Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/components/src/ui/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export interface SelectProps<T extends React.Key = string>
// Search behavior
searchable?: boolean;
searchInputProps?: React.ComponentPropsWithoutRef<typeof CommandInput>;
// Clear the search input when the dropdown closes
clearSearchOnClose?: boolean;
// Creatable behavior
creatable?: boolean;
onCreateOption?: (input: string) => SelectOption<T> | Promise<SelectOption<T>>;
Expand All @@ -74,6 +76,7 @@ export function Select<T extends React.Key = string>({
components,
searchable = true,
searchInputProps,
clearSearchOnClose = false,
creatable = false,
onCreateOption,
createOptionLabel,
Expand All @@ -96,6 +99,13 @@ export function Select<T extends React.Key = string>({
});
}, [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 =
Expand Down