From b618ac497161ada420a45b8073d26ed1f551c99b Mon Sep 17 00:00:00 2001 From: juliesaia Date: Sun, 31 Dec 2023 03:23:37 -0500 Subject: [PATCH 1/2] feat(autocomplete): automatically focus first non-disabled item --- .../components/autocomplete/src/use-autocomplete.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/components/autocomplete/src/use-autocomplete.ts b/packages/components/autocomplete/src/use-autocomplete.ts index 1928c37d63..a9a353b966 100644 --- a/packages/components/autocomplete/src/use-autocomplete.ts +++ b/packages/components/autocomplete/src/use-autocomplete.ts @@ -280,6 +280,16 @@ export function useAutocomplete(originalProps: UseAutocomplete } }, [isOpen, allowsCustomValue]); + // 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]); + const {buttonProps, inputProps, listBoxProps} = useComboBox( { ...originalProps, From 1bb0a62cd8a622c5c31b6b8f49706915f8d27727 Mon Sep 17 00:00:00 2001 From: WK Wong Date: Tue, 1 Oct 2024 16:58:03 +0800 Subject: [PATCH 2/2] chore(changeset): add changeset --- .changeset/popular-pigs-begin.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/popular-pigs-begin.md diff --git a/.changeset/popular-pigs-begin.md b/.changeset/popular-pigs-begin.md new file mode 100644 index 0000000000..f5d0a05413 --- /dev/null +++ b/.changeset/popular-pigs-begin.md @@ -0,0 +1,5 @@ +--- +"@nextui-org/autocomplete": patch +--- + +automatically focus first non-disabled item