Async Select component built with React & shadcn/ui
Installation
The Async Select Component is built through the composition of <Popover />
and the <Command />
components from shadcn/ui.
See installation instructions for the Popover and the Command components.
Basic Usage
Props
Required Props
Prop | Type | Description |
---|---|---|
fetcher | (query?: string) => Promise<T[]> | Async function to fetch options |
renderOption | (option: T) => React.ReactNode | Function to render each option in the dropdown |
getOptionValue | (option: T) => string | Function to get unique value from option |
getDisplayValue | (option: T) => React.ReactNode | Function to render selected value |
value | string | Currently selected value |
onChange | (value: string) => void | Callback when selection changes |
label | string | Label for the select field |
Optional Props
Prop | Type | Default | Description |
---|---|---|---|
preload | boolean | false | Enable preloading all options |
filterFn | (option: T, query: string) => boolean | - | Custom filter function for preload mode |
notFound | React.ReactNode | - | Custom not found message/component |
loadingSkeleton | React.ReactNode | - | Custom loading state component |
placeholder | string | "Select..." | Placeholder text |
disabled | boolean | false | Disable the select |
width | string | number | "200px" | Custom width |
className | string | - | Custom class for popover |
triggerClassName | string | - | Custom class for trigger button |
noResultsMessage | string | - | Custom no results message |
clearable | boolean | true | Allow clearing selection |