Skip to content

Commit

Permalink
Auto call onAddNew when the user searchs and there is no match
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnCh committed Sep 18, 2024
1 parent 646362b commit 83c0c8a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/inputs/internal/ComboBoxBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ export function ComboBoxBase<O, V extends Value>(props: ComboBoxBaseProps<O, V>)

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) {
Expand Down

0 comments on commit 83c0c8a

Please sign in to comment.