Skip to content

Commit

Permalink
UHF-8590: Fix scroll behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremysteerio committed Aug 16, 2023
1 parent 3030e33 commit 93ae289
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dist/js/district-and-project-search.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/job-search.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/news-archive.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/school-search.min.js

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions src/js/react/apps/school-search/containers/SearchContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { LoadingSpinner, Tab, TabList, Tabs } from 'hds-react';
import { Suspense, useState } from 'react';
import { useSetAtom } from 'jotai';
import ProximityFormContainer from './ProximityFormContainer';
import ProximityResultsContainer from './ProximityResultsContainer';
import FeatureFormContainer from './FeatureFormContainer';
import FeatureResultsContainer from './FeatureResultsContainer';
import { paramsAtom } from '../store';

const MODE_OPTIONS = {
// Search by school features
Expand All @@ -14,22 +16,32 @@ const MODE_OPTIONS = {

const SearchContainer = () => {
const [searchMode, setSearchMode] = useState<string>(MODE_OPTIONS.proximity);

const setParams = useSetAtom(paramsAtom);

const changeSearchMode = (mode: string) => {
if (mode === searchMode) {
return;
}

setParams({});
setSearchMode(mode);
};

return (
<>
<Tabs>
<TabList className='react-search__tabs'>
<Tab
className='react-search__tab'
index={0}
onClick={() => setSearchMode(MODE_OPTIONS.proximity)}
onClick={() => changeSearchMode(MODE_OPTIONS.proximity)}
>
{Drupal.t('Search for your local school', {}, {context: 'School search: local search title'})}
</Tab>
<Tab
className='react-search__tab'
index={1}
onClick={() => setSearchMode(MODE_OPTIONS.feature)}
onClick={() => changeSearchMode(MODE_OPTIONS.feature)}
>
{Drupal.t('Search with school information', {}, {context: 'School search: Feature form title'})}
</Tab>
Expand Down
2 changes: 1 addition & 1 deletion src/js/react/common/hooks/useScrollToResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const useScrollToResults = (ref: RefObject<HTMLElement>, shouldScrollOnRender: b
if (current && shouldScrollOnRender) {
current.setAttribute('tabindex', '0');
current.focus();
current.scrollIntoView({behavior: 'smooth'});
current.scrollIntoView({behavior: 'smooth', block: 'center'});
}
}, [ref, shouldScrollOnRender]);
};
Expand Down

0 comments on commit 93ae289

Please sign in to comment.