Skip to content

Commit

Permalink
Desensitize hiding the autocomplete results on scroll. (datacommonsor…
Browse files Browse the repository at this point in the history
…g#4731)

Only hides the autocomplete results after 15% of window width has been
scrolled through.

https://screencast.googleplex.com/cast/NjMyMDgzNjY5MTYyMzkzNnxmNjAxODU2Yy0xZQ
  • Loading branch information
gmechali committed Dec 5, 2024
1 parent b9ea8d1 commit 56fa57c
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions static/js/components/nl_search_bar/auto_complete_input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ export function AutoCompleteInput(
const [lastAutoCompleteSelection, setLastAutoCompleteSelection] =
useState("");
// Used to reduce sensitivity to scrolling for autocomplete result dismissal.
// Tracks the last scrollY value at time of autocomplete request.
const [lastScrollYOnTrigger, setLastScrollYOnTrigger] = useState(0);
// Tracks the last scrollY value for current height offsett.
const [lastScrollY, setLastScrollY] = useState(0);

const isHeaderBar = props.barType == "header";
Expand All @@ -99,7 +101,7 @@ export function AutoCompleteInput(
}, []);

// Whenever any of the scrollY states change, recompute to see if we need to hide the results.
// We only hide the results when the user has scrolled past 15% of the window height.
// We only hide the results when the user has scrolled past 15% of the window height since the autocomplete request.
// It allows the user to navigate through the page without being annoyed by the results,
// and to scroll through the results without them disappearing.
useEffect(() => {
Expand All @@ -109,12 +111,7 @@ export function AutoCompleteInput(
) {
setResults({ placeResults: [], svResults: [] });
}
}, [
lastScrollY,
setLastScrollY,
lastScrollYOnTrigger,
setLastScrollYOnTrigger,
]);
}, [lastScrollY, lastScrollYOnTrigger]);

useEffect(() => {
// For the first load when q= param is set, we want to ensure the
Expand Down

0 comments on commit 56fa57c

Please sign in to comment.