Skip to content

Commit 5a7baff

Browse files
committed
fix(ComboBox): reset value on blur
1 parent 77a033a commit 5a7baff

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/components/fields/ComboBox/ComboBox.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,25 @@ export const ComboBox = forwardRef(function ComboBox<T extends object>(
366366
}
367367
});
368368

369+
let onBlur = useEvent((e: FocusEvent) => {
370+
if (
371+
!props.allowsCustomValue &&
372+
inputRef.current?.value &&
373+
![...state.collection]
374+
.map((i) => i.textValue)
375+
.includes(inputRef.current?.value)
376+
) {
377+
props.onSelectionChange?.(null);
378+
}
379+
});
380+
369381
useEffect(() => {
370382
inputRef.current?.addEventListener('keydown', onKeyPress, true);
383+
inputRef.current?.addEventListener('blur', onBlur, true);
371384

372385
return () => {
373386
inputRef.current?.removeEventListener('keydown', onKeyPress, true);
387+
inputRef.current?.removeEventListener('blur', onBlur, true);
374388
};
375389
}, []);
376390

0 commit comments

Comments
 (0)