Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/js/job-search.min.js

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions src/js/react/apps/job-search/containers/ResultsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ const ResultsContainer = () => {
const scrollTarget = createRef<HTMLDivElement>();
const { query, promoted, handleResults } = useResultsQuery(urlParams);

// Scroll to results when they change.
const choices = Boolean(Object.keys(urlParams).length);
useScrollToResults(scrollTarget, choices);

const { data, error, isLoading, isValidating } = useIndexQuery({
keepPreviousData: true,
query,
multi: promoted
});

// Scroll to results when they change.
const choices = Boolean(Object.keys(urlParams).length);
const shouldScrollOnRender = Boolean(choices && !isLoading && !isValidating);
useScrollToResults(scrollTarget, shouldScrollOnRender);

const updatePage = (e: SyntheticEvent<HTMLButtonElement>, index: number) => {
e.preventDefault();
setPage(index.toString());
Expand Down
4 changes: 2 additions & 2 deletions src/js/react/common/hooks/useScrollToResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const useScrollToResults = (ref: RefObject<HTMLElement>, shouldScrollOnRender: b

if (current && shouldScrollOnRender) {
current.setAttribute('tabindex', '-1');
current.focus({preventScroll: true});
current.scrollIntoView({behavior: 'smooth', block: 'center'});
current.focus({ preventScroll: true });
current.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
}, [ref, shouldScrollOnRender]);
};
Expand Down
Loading