From 83c0c8ac678a8073412bc2acae2cac5af8b56500 Mon Sep 17 00:00:00 2001 From: JonnCh Date: Wed, 18 Sep 2024 13:18:30 -0600 Subject: [PATCH] Auto call onAddNew when the user searchs and there is no match --- src/inputs/internal/ComboBoxBase.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/inputs/internal/ComboBoxBase.tsx b/src/inputs/internal/ComboBoxBase.tsx index 396cd79f3..9948730c1 100644 --- a/src/inputs/internal/ComboBoxBase.tsx +++ b/src/inputs/internal/ComboBoxBase.tsx @@ -312,6 +312,11 @@ export function ComboBoxBase(props: ComboBoxBaseProps) const [debouncedSearch] = useDebounce(searchValue, 300); + useEffect(() => { + if (!debouncedSearch || !onAddNew) return; + if (filteredOptions.length === 1 && filteredOptions[0] === addNewOption) onAddNew(debouncedSearch); + }, [debouncedSearch, filteredOptions, onAddNew]); + // Reset inputValue when closed or selected changes useEffect(() => { if (state.isOpen && multiselect) {