mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-04 00:18:01 +01:00
feat: select first item after query (#7592)
Now after search is done, the first item will be selected
This commit is contained in:
parent
7ed717379c
commit
0a4ef3b49f
@ -171,6 +171,12 @@ export const CommandBar = () => {
|
||||
debouncedSetSearchState(value);
|
||||
}, [searchedFlagCount]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!searchLoading) {
|
||||
selectFirstItem();
|
||||
}
|
||||
}, [searchLoading, searchString]);
|
||||
|
||||
const onSearchChange = (value: string) => {
|
||||
debouncedSetSearchState(value);
|
||||
setValue(value);
|
||||
@ -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') {
|
||||
|
Loading…
Reference in New Issue
Block a user