File tree Expand file tree Collapse file tree
packages/components/src/ui Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -49,6 +49,8 @@ export interface SelectProps<T extends React.Key = string>
4949 // Search behavior
5050 searchable ?: boolean ;
5151 searchInputProps ?: React . ComponentPropsWithoutRef < typeof CommandInput > ;
52+ // Clear the search input when the dropdown closes
53+ clearSearchOnClose ?: boolean ;
5254 // Creatable behavior
5355 creatable ?: boolean ;
5456 onCreateOption ?: ( input : string ) => SelectOption < T > | Promise < SelectOption < T > > ;
@@ -74,6 +76,7 @@ export function Select<T extends React.Key = string>({
7476 components,
7577 searchable = true ,
7678 searchInputProps,
79+ clearSearchOnClose = false ,
7780 creatable = false ,
7881 onCreateOption,
7982 createOptionLabel,
@@ -96,6 +99,13 @@ export function Select<T extends React.Key = string>({
9699 } ) ;
97100 } , [ popoverState . isOpen ] ) ;
98101
102+ // When closing, optionally clear the search query to reset the input value
103+ useEffect ( ( ) => {
104+ if ( ! popoverState . isOpen && clearSearchOnClose ) {
105+ setSearchQuery ( '' ) ;
106+ }
107+ } , [ popoverState . isOpen , clearSearchOnClose ] ) ;
108+
99109 const selectedOption = options . find ( ( o ) => o . value === value ) ;
100110
101111 const Trigger =
You can’t perform that action at this time.
0 commit comments