@@ -15,7 +15,7 @@ import {
15
15
} from '@headlessui/react'
16
16
import cn from 'classnames'
17
17
import { matchSorter } from 'match-sorter'
18
- import { useId , useState , type ReactNode , type Ref } from 'react'
18
+ import { useEffect , useId , useState , type ReactNode , type Ref } from 'react'
19
19
20
20
import { SelectArrows6Icon } from '@oxide/design-system/icons/react'
21
21
@@ -97,6 +97,26 @@ export const Combobox = ({
97
97
keys : [ 'selectedLabel' , 'label' ] ,
98
98
sorter : ( items ) => items , // preserve original order, don't sort by match
99
99
} )
100
+
101
+ // In the arbitraryValues case, clear the query whenever the value is cleared.
102
+ // this is necessary, e.g., for the firewall rules form when you submit the
103
+ // targets subform and clear the field. Two possible changes we might want to make
104
+ // here if we run into issues:
105
+ //
106
+ // 1. do it all the time, not just in the arbitraryValues case
107
+ // 2. do it on all value changes, not just on clear
108
+ //
109
+ // Currently, I don't think there are any arbitraryValues=false cases where we
110
+ // set the value from outside. There is an arbitraryvalues=true case where we
111
+ // setValue to something other than empty string, but we don't need the
112
+ // sync because that setValue is done in onInputChange and we already are
113
+ // doing setQuery in here along with it.
114
+ useEffect ( ( ) => {
115
+ if ( allowArbitraryValues && ! selectedItemValue ) {
116
+ setQuery ( '' )
117
+ }
118
+ } , [ allowArbitraryValues , selectedItemValue ] )
119
+
100
120
// If the user has typed in a value that isn't in the list,
101
121
// add it as an option if `allowArbitraryValues` is true
102
122
if (
0 commit comments