@@ -165,10 +165,10 @@ export function useComboBoxState<T extends object>(props: ComboBoxStateOptions<T
165
165
}
166
166
} , [ triggerState , filteredCollection ] ) ;
167
167
168
- let lastValue = useRef ( inputValue ) ;
168
+ let [ lastValue , setLastValue ] = useState ( inputValue ) ;
169
169
let resetInputValue = ( ) => {
170
170
let itemText = collection . getItem ( selectedKey ) ?. textValue ?? '' ;
171
- lastValue . current = itemText ;
171
+ setLastValue ( itemText ) ;
172
172
setInputValue ( itemText ) ;
173
173
} ;
174
174
@@ -183,7 +183,7 @@ export function useComboBoxState<T extends object>(props: ComboBoxStateOptions<T
183
183
isFocused &&
184
184
( filteredCollection . size > 0 || allowsEmptyCollection ) &&
185
185
! triggerState . isOpen &&
186
- inputValue !== lastValue . current &&
186
+ inputValue !== lastValue &&
187
187
menuTrigger !== 'manual'
188
188
) {
189
189
open ( null , 'input' ) ;
@@ -209,7 +209,7 @@ export function useComboBoxState<T extends object>(props: ComboBoxStateOptions<T
209
209
}
210
210
211
211
// Clear focused key when input value changes and display filtered collection again.
212
- if ( inputValue !== lastValue . current ) {
212
+ if ( inputValue !== lastValue ) {
213
213
selectionManager . setFocusedKey ( null ) ;
214
214
setShowAllItems ( false ) ;
215
215
@@ -228,8 +228,8 @@ export function useComboBoxState<T extends object>(props: ComboBoxStateOptions<T
228
228
( props . inputValue === undefined || props . selectedKey === undefined )
229
229
) {
230
230
resetInputValue ( ) ;
231
- } else {
232
- lastValue . current = inputValue ;
231
+ } else if ( lastValue !== inputValue ) {
232
+ setLastValue ( inputValue ) ;
233
233
}
234
234
235
235
// Update the inputValue if the selected item's text changes from its last tracked value.
@@ -239,7 +239,7 @@ export function useComboBoxState<T extends object>(props: ComboBoxStateOptions<T
239
239
let selectedItemText = collection . getItem ( selectedKey ) ?. textValue ?? '' ;
240
240
if ( ! isFocused && selectedKey != null && props . inputValue === undefined && selectedKey === lastSelectedKey . current ) {
241
241
if ( lastSelectedKeyText . current !== selectedItemText ) {
242
- lastValue . current = selectedItemText ;
242
+ setLastValue ( selectedItemText ) ;
243
243
setInputValue ( selectedItemText ) ;
244
244
}
245
245
}
@@ -275,7 +275,7 @@ export function useComboBoxState<T extends object>(props: ComboBoxStateOptions<T
275
275
276
276
// Stop menu from reopening from useEffect
277
277
let itemText = collection . getItem ( selectedKey ) ?. textValue ?? '' ;
278
- lastValue . current = itemText ;
278
+ setLastValue ( itemText ) ;
279
279
closeMenu ( ) ;
280
280
} else {
281
281
// If only a single aspect of combobox is controlled, reset input value and close menu for the user
0 commit comments