@@ -49,6 +49,9 @@ export type ComboboxPopupControls<T extends ListItem<V>, V> = {
49
49
/** Selects the current item in the popup. */
50
50
select : ( item ?: T ) => void ;
51
51
52
+ /** Clears the selection state of the popup. */
53
+ clearSelection : ( ) => void ;
54
+
52
55
/** Filters the items in the popup. */
53
56
filter : ( text : string ) => void ;
54
57
@@ -95,7 +98,20 @@ export class ComboboxPattern<T extends ListItem<V>, V> {
95
98
. on ( 'ArrowUp' , ( ) => this . prev ( ) )
96
99
. on ( 'Home' , ( ) => this . first ( ) )
97
100
. on ( 'End' , ( ) => this . last ( ) )
98
- . on ( 'Escape' , ( ) => this . close ( ) )
101
+ . on ( 'Escape' , ( ) => {
102
+ if ( this . inputs . filterMode ( ) === 'highlight' && this . inputs . popupControls ( ) ?. activeId ( ) ) {
103
+ this . inputs . popupControls ( ) ?. unfocus ( ) ;
104
+ this . inputs . popupControls ( ) ?. clearSelection ( ) ;
105
+
106
+ const inputEl = this . inputs . inputEl ( ) ;
107
+
108
+ if ( inputEl ) {
109
+ inputEl . value = this . searchString ( ) ;
110
+ }
111
+ } else {
112
+ this . close ( ) ;
113
+ }
114
+ } ) // TODO: When filter mode is 'highlight', escape should revert to the last committed value.
99
115
. on ( 'Enter' , ( ) => this . select ( { commit : true , close : true } ) ) ;
100
116
} ) ;
101
117
@@ -141,7 +157,11 @@ export class ComboboxPattern<T extends ListItem<V>, V> {
141
157
this . open ( ) ;
142
158
this . inputs . popupControls ( ) ?. first ( ) ;
143
159
144
- if ( event instanceof InputEvent && event . inputType === 'deleteContentBackward' ) {
160
+ if (
161
+ event instanceof InputEvent &&
162
+ this . inputs . filterMode ( ) !== 'manual' &&
163
+ event . inputType . match ( / d e l e t e .* / )
164
+ ) {
145
165
this . inputs . popupControls ( ) ?. select ( ) ;
146
166
return ;
147
167
}
@@ -161,18 +181,19 @@ export class ComboboxPattern<T extends ListItem<V>, V> {
161
181
! ( event . relatedTarget instanceof HTMLElement ) ||
162
182
! this . inputs . containerEl ( ) ?. contains ( event . relatedTarget )
163
183
) {
164
- this . close ( ) ;
165
-
166
184
if ( this . inputs . filterMode ( ) !== 'manual' ) {
167
185
this . commit ( ) ;
168
186
}
187
+
188
+ this . close ( ) ;
169
189
}
170
190
}
171
191
172
192
/** Closes the combobox. */
173
193
close ( ) {
174
194
this . expanded . set ( false ) ;
175
195
this . inputs . popupControls ( ) ?. unfocus ( ) ;
196
+ this . inputs . popupControls ( ) ?. clearSelection ( ) ;
176
197
}
177
198
178
199
/** Opens the combobox. */
@@ -242,6 +263,10 @@ export class ComboboxPattern<T extends ListItem<V>, V> {
242
263
if ( opts . highlight ) {
243
264
this . highlight ( ) ;
244
265
}
266
+ if ( this . inputs . filterMode ( ) === 'manual' ) {
267
+ this . inputs . popupControls ( ) ?. clearSelection ( ) ;
268
+ this . inputs . value . set ( undefined ) ;
269
+ }
245
270
}
246
271
247
272
/** Updates the value of the input based on the currently selected item. */
0 commit comments