diff --git a/packages/components/src/ui/select.tsx b/packages/components/src/ui/select.tsx index 4b3dc92..c2ba665 100644 --- a/packages/components/src/ui/select.tsx +++ b/packages/components/src/ui/select.tsx @@ -49,6 +49,8 @@ export interface SelectProps // Search behavior searchable?: boolean; searchInputProps?: React.ComponentPropsWithoutRef; + // Clear the search input when the dropdown closes + clearSearchOnClose?: boolean; // Creatable behavior creatable?: boolean; onCreateOption?: (input: string) => SelectOption | Promise>; @@ -74,6 +76,7 @@ export function Select({ components, searchable = true, searchInputProps, + clearSearchOnClose = false, creatable = false, onCreateOption, createOptionLabel, @@ -96,6 +99,13 @@ export function Select({ }); }, [popoverState.isOpen]); + // When closing, optionally clear the search query to reset the input value + useEffect(() => { + if (!popoverState.isOpen && clearSearchOnClose) { + setSearchQuery(''); + } + }, [popoverState.isOpen, clearSearchOnClose]); + const selectedOption = options.find((o) => o.value === value); const Trigger =