@@ -59,6 +59,7 @@ export function useComboBox<T>(props: AriaComboBoxProps<T>, state: ComboBoxState
59
59
60
60
let onChange = ( val ) => {
61
61
state . setInputValue ( val ) ;
62
+ state . selectionManager . setFocusedKey ( null ) ;
62
63
63
64
if ( menuTrigger !== 'manual' ) {
64
65
state . open ( ) ;
@@ -192,23 +193,11 @@ export function useComboBox<T>(props: AriaComboBoxProps<T>, state: ComboBoxState
192
193
193
194
let lastValue = useRef ( state . inputValue ) ;
194
195
useEffect ( ( ) => {
196
+ // Close combobox menu if user clears input text unless trigger is focus (as per design)
195
197
if ( lastValue . current !== state . inputValue ) {
196
- // Clear focused key if user clears textfield to prevent accidental selection on blur and menuTrigger='focus' (as per design feedback)
197
- // Also clear focused key if allowsCustomValue is true, there isn't a selected key, and the input value changed
198
- // Specifically for case where menu is closed and user copy pastes a matching value into input field then deletes a character
199
- if ( ( state . inputValue === '' && menuTrigger === 'focus' ) || ( allowsCustomValue && ! state . selectedKey ) ) {
200
- state . selectionManager . setFocusedKey ( null ) ;
201
- }
202
-
203
198
if ( state . inputValue === '' && menuTrigger !== 'focus' ) {
204
199
state . close ( ) ;
205
200
}
206
-
207
- // Focus first item if filtered collection no longer contains original focused item (aka user typing to filter collection)
208
- // Only set a focused key if one existed previously, don't want to focus something by default if allowsCustomValue = true
209
- if ( ( ! allowsCustomValue || state . selectionManager . focusedKey ) && state . inputValue !== '' && ! state . collection . getItem ( state . selectionManager . focusedKey ) ) {
210
- state . selectionManager . setFocusedKey ( layout . getFirstKey ( ) ) ;
211
- }
212
201
}
213
202
214
203
lastValue . current = state . inputValue ;
0 commit comments