Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight the second item in in the omnibar search results #4611

Merged
merged 6 commits into from
Jun 17, 2021
Merged
Next Next commit
Update Initial active item index
  • Loading branch information
akash-codemonk committed May 21, 2021
commit c142dcb204b4de7728883fbdea262393e9226773
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ const getSectionTitle = (title: string, icon: any) => ({
icon,
});

const INITIAL_ACTIVE_ITEM_INDEX = 2;

function GlobalSearch() {
const modalOpen = useSelector(isModalOpenSelector);
const defaultDocs = useDefaultDocumentationResults(modalOpen);
Expand All @@ -118,7 +120,9 @@ function GlobalSearch() {
setDocumentationSearchResultsInState(res);
}, []);

const [activeItemIndex, setActiveItemIndexInState] = useState(1);
const [activeItemIndex, setActiveItemIndexInState] = useState(
INITIAL_ACTIVE_ITEM_INDEX,
);
const setActiveItemIndex = useCallback((index) => {
scrollPositionRef.current = 0;
setActiveItemIndexInState(index);
Expand Down Expand Up @@ -166,12 +170,12 @@ function GlobalSearch() {
setQuery(resetSearchQuery);
} else {
dispatch(setGlobalSearchQuery(""));
if (!query) setActiveItemIndex(1);
if (!query) setActiveItemIndex(INITIAL_ACTIVE_ITEM_INDEX);
}
}, [modalOpen]);

useEffect(() => {
setActiveItemIndex(1);
setActiveItemIndex(INITIAL_ACTIVE_ITEM_INDEX);
}, [query]);

const filteredWidgets = useMemo(() => {
Expand Down