Skip to content

Commit

Permalink
feat: select first item after query (#7592)
Browse files Browse the repository at this point in the history
Now after search is done, the first item will be selected
  • Loading branch information
sjaanus authored Jul 16, 2024
1 parent 7ed7173 commit 0a4ef3b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions frontend/src/component/commandBar/CommandBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ export const CommandBar = () => {
debouncedSetSearchState(value);
}, [searchedFlagCount]);

useEffect(() => {
if (!searchLoading) {
selectFirstItem();
}
}, [searchLoading, searchString]);

const onSearchChange = (value: string) => {
debouncedSetSearchState(value);
setValue(value);
Expand Down Expand Up @@ -265,6 +271,13 @@ export const CommandBar = () => {
},
);

const selectFirstItem = () => {
const itemsAndIndex = findCommandBarLinksAndSelectedIndex();
if (!itemsAndIndex) return;
const { allCommandBarLinks } = itemsAndIndex;
(allCommandBarLinks[0] as HTMLElement).focus();
};

useOnClickOutside([searchContainerRef], hideSuggestions);
const onKeyDown = (event: React.KeyboardEvent) => {
if (event.key === 'Escape') {
Expand Down

0 comments on commit 0a4ef3b

Please sign in to comment.