feat(autocomplete): automatically focus first non-disabled item (#2186)

Co-authored-by: WK Wong <wingkwong.code@gmail.com>
This commit is contained in:
Julie Saia 2024-10-01 04:58:59 -04:00 committed by GitHub
parent a4ab02006a
commit 557f10f5ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 0 deletions

View File

@ -0,0 +1,5 @@
---
"@nextui-org/autocomplete": patch
---
automatically focus first non-disabled item

View File

@ -317,6 +317,16 @@ export function useAutocomplete<T extends object>(originalProps: UseAutocomplete
}
}, [inputRef.current]);
// focus first non-disabled item
useEffect(() => {
let key = state.collection.getFirstKey();
while (key && state.disabledKeys.has(key)) {
key = state.collection.getKeyAfter(key);
}
state.selectionManager.setFocusedKey(key);
}, [state.collection, state.disabledKeys]);
useEffect(() => {
if (isOpen) {
// apply the same with to the popover as the select