@@ -238,29 +238,30 @@ export const MultiSelectCombobox = forwardRef<
238
238
[ onChange , selected ] ,
239
239
) ;
240
240
241
- const handleKeyDown = useCallback (
242
- ( e : KeyboardEvent < HTMLDivElement > ) => {
243
- const input = inputRef . current ;
244
- if ( input ) {
245
- if ( e . key === "Delete" || e . key === "Backspace" ) {
246
- if ( input . value === "" && selected . length > 0 ) {
247
- const lastSelectOption = selected [ selected . length - 1 ] ;
248
- // If last item is fixed, we should not remove it.
249
- if ( ! lastSelectOption . fixed ) {
250
- handleUnselect ( selected [ selected . length - 1 ] ) ;
251
- }
241
+ const handleKeyDown = ( e : KeyboardEvent < HTMLDivElement > ) => {
242
+ const input = inputRef . current ;
243
+ if ( input ) {
244
+ if ( e . key === "Delete" || e . key === "Backspace" ) {
245
+ if ( input . value === "" && selected . length > 0 ) {
246
+ const lastSelectOption = selected [ selected . length - 1 ] ;
247
+ // If last item is fixed, we should not remove it.
248
+ if ( ! lastSelectOption . fixed ) {
249
+ handleUnselect ( selected [ selected . length - 1 ] ) ;
252
250
}
253
251
}
254
- // This is not a default behavior of the <input /> field
255
- if ( e . key === "Escape" ) {
256
- input . blur ( ) ;
257
- }
258
252
}
259
- } ,
260
- [ handleUnselect , selected ] ,
261
- ) ;
253
+ // This is not a default behavior of the <input /> field
254
+ if ( e . key === "Escape" ) {
255
+ input . blur ( ) ;
256
+ }
257
+ }
258
+ } ;
262
259
263
260
useEffect ( ( ) => {
261
+ if ( ! open ) {
262
+ return ;
263
+ }
264
+
264
265
const handleClickOutside = ( event : MouseEvent | TouchEvent ) => {
265
266
if (
266
267
dropdownRef . current &&
@@ -273,10 +274,6 @@ export const MultiSelectCombobox = forwardRef<
273
274
}
274
275
} ;
275
276
276
- if ( ! open ) {
277
- return ;
278
- }
279
-
280
277
if ( open ) {
281
278
document . addEventListener ( "mousedown" , handleClickOutside ) ;
282
279
document . addEventListener ( "touchend" , handleClickOutside ) ;
@@ -381,7 +378,7 @@ export const MultiSelectCombobox = forwardRef<
381
378
onChange ?.( newOptions ) ;
382
379
} }
383
380
>
384
- { ` Create "$ {inputValue } "` }
381
+ Create "{ inputValue } "
385
382
</ CommandItem >
386
383
) ;
387
384
@@ -554,6 +551,12 @@ export const MultiSelectCombobox = forwardRef<
554
551
setSelected ( fixedOptions ) ;
555
552
onChange ?.( fixedOptions ) ;
556
553
} }
554
+ onKeyDown = { ( e ) => {
555
+ if ( e . key === "Enter" ) {
556
+ setSelected ( fixedOptions ) ;
557
+ onChange ?.( fixedOptions ) ;
558
+ }
559
+ } }
557
560
className = { cn (
558
561
"bg-transparent mt-1 border-none rounded-sm cursor-pointer text-content-secondary hover:text-content-primary outline-none focus:ring-2 focus:ring-content-link" ,
559
562
( hideClearAllButton ||
0 commit comments