mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
feat(autocomplete): automatically focus first non-disabled item (#2186)
Co-authored-by: WK Wong <wingkwong.code@gmail.com>
This commit is contained in:
parent
a4ab02006a
commit
557f10f5ec
5
.changeset/popular-pigs-begin.md
Normal file
5
.changeset/popular-pigs-begin.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@nextui-org/autocomplete": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
automatically focus first non-disabled item
|
||||||
@ -317,6 +317,16 @@ export function useAutocomplete<T extends object>(originalProps: UseAutocomplete
|
|||||||
}
|
}
|
||||||
}, [inputRef.current]);
|
}, [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(() => {
|
useEffect(() => {
|
||||||
if (isOpen) {
|
if (isOpen) {
|
||||||
// apply the same with to the popover as the select
|
// apply the same with to the popover as the select
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user