Skip to content

Commit c463c88

Browse files
authored
Fix combobox visible focus styling when opening the menu via keyboard (#4299)
* Make sure selection manager isFocused returns true when menu is opened a selectable item is only considered isFocused if "manager.isFocused" returns true and the item key matches the tracked key. Usually we update "manager.isFocused" when the collection or something in it is focused but virtual focused collections wont do this * adding to one other area for correctness * simplify logic also moved clearing of setFocusedKey to onOpenChange so it is colocated with its relevant logic * forgot to remove old code
1 parent 6cccc9c commit c463c88

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

packages/@react-stately/combobox/src/useComboBoxState.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ export function useComboBoxState<T extends object>(props: ComboBoxStateOptions<T
102102
if (props.onOpenChange) {
103103
props.onOpenChange(open, open ? menuOpenTrigger.current : undefined);
104104
}
105+
106+
selectionManager.setFocused(open);
107+
if (!open) {
108+
selectionManager.setFocusedKey(null);
109+
}
105110
};
106111

107112
let triggerState = useMenuTriggerState({...props, onOpenChange, isOpen: undefined, defaultOpen: undefined});
@@ -248,13 +253,6 @@ export function useComboBoxState<T extends object>(props: ComboBoxStateOptions<T
248253
lastSelectedKeyText.current = selectedItemText;
249254
});
250255

251-
useEffect(() => {
252-
// Reset focused key when the menu closes
253-
if (!triggerState.isOpen) {
254-
selectionManager.setFocusedKey(null);
255-
}
256-
}, [triggerState.isOpen, selectionManager]);
257-
258256
// Revert input value and close menu
259257
let revert = () => {
260258
if (allowsCustomValue && selectedKey == null) {

0 commit comments

Comments
 (0)