@@ -22,7 +22,7 @@ import type { Option } from './useCombobox';
22
22
import { useCombobox } from './useCombobox' ;
23
23
import { useComboboxKeyboard } from './useComboboxKeyboard' ;
24
24
import { useFloatingCombobox } from './useFloatingCombobox' ;
25
- import { prefix , removePrefix } from './utilities' ;
25
+ import { prefix , removePrefix , setReactInputValue } from './utilities' ;
26
26
27
27
export type ComboboxProps = {
28
28
/**
@@ -161,6 +161,12 @@ export const ComboboxComponent = forwardRef<HTMLInputElement, ComboboxProps>(
161
161
162
162
const [ inputValue , setInputValue ] = useState < string > ( rest . inputValue || '' ) ;
163
163
164
+ useEffect ( ( ) => {
165
+ if ( typeof rest . inputValue === 'string' ) {
166
+ setInputValue ( rest . inputValue ) ;
167
+ }
168
+ } , [ rest . inputValue ] ) ;
169
+
164
170
const {
165
171
selectedOptions,
166
172
options,
@@ -208,7 +214,8 @@ export const ComboboxComponent = forwardRef<HTMLInputElement, ComboboxProps>(
208
214
useEffect ( ( ) => {
209
215
if ( value && value . length > 0 && ! multiple ) {
210
216
const option = options [ prefix ( value [ 0 ] ) ] ;
211
- setInputValue ( option ?. label || '' ) ;
217
+ inputRef . current &&
218
+ setReactInputValue ( inputRef . current , option ?. label || '' ) ;
212
219
}
213
220
} , [ multiple , value , options ] ) ;
214
221
@@ -239,7 +246,7 @@ export const ComboboxComponent = forwardRef<HTMLInputElement, ComboboxProps>(
239
246
const { option, clear, remove } = args ;
240
247
if ( clear ) {
241
248
setSelectedOptions ( { } ) ;
242
- setInputValue ( '' ) ;
249
+ inputRef . current && setReactInputValue ( inputRef . current , '' ) ;
243
250
onValueChange ?.( [ ] ) ;
244
251
return ;
245
252
}
@@ -264,15 +271,16 @@ export const ComboboxComponent = forwardRef<HTMLInputElement, ComboboxProps>(
264
271
} else {
265
272
newSelectedOptions [ prefix ( option . value ) ] = option ;
266
273
}
267
- setInputValue ( '' ) ;
274
+ inputRef . current && setReactInputValue ( inputRef . current , '' ) ;
268
275
inputRef . current ?. focus ( ) ;
269
276
} else {
270
277
/* clear newSelectedOptions */
271
278
for ( const key of Object . keys ( newSelectedOptions ) ) {
272
279
delete newSelectedOptions [ key ] ;
273
280
}
274
281
newSelectedOptions [ prefix ( option . value ) ] = option ;
275
- setInputValue ( option ?. label || '' ) ;
282
+ inputRef . current &&
283
+ setReactInputValue ( inputRef . current , option ?. label || '' ) ;
276
284
// move cursor to the end of the input
277
285
setTimeout ( ( ) => {
278
286
inputRef . current ?. setSelectionRange (
0 commit comments