Select Search
SelectSearch is a controlled single-select combobox for lists too long to scroll. Search by city, or by a keyword such as PST. Pass an icon component to show it before the label. Pick the selected option again to clear it.
@dentil/select-searchOn this page
Result:
—components/demos/select-search-overview.tsx
'use client';
import { useState } from 'react';
import { SelectSearch } from '@/components/dentil/select-search/select-search';
const timezones = [
{ label: 'London (GMT+0)', value: 'Europe/London', keywords: ['UK', 'Britain'] },
{ label: 'Paris (GMT+1)', value: 'Europe/Paris', keywords: ['France', 'CET'] },
{ label: 'New York (GMT-5)', value: 'America/New_York', keywords: ['EST', 'Eastern'] },
{ label: 'Los Angeles (GMT-8)', value: 'America/Los_Angeles', keywords: ['PST', 'Pacific'] },
{ label: 'Tokyo (GMT+9)', value: 'Asia/Tokyo', keywords: ['Japan', 'JST'] },
{ label: 'Sydney (GMT+11)', value: 'Australia/Sydney', keywords: ['AEDT'] },
];
export function SelectSearchOverviewDemo() {
const [timezone, setTimezone] = useState('');
return (
<div className="flex w-full max-w-xs flex-col gap-4">
<SelectSearch
options={timezones}
value={timezone}
onChange={setTimezone}
placeholder="Select a timezone"
searchPlaceholder="Search timezones..."
emptyText="No timezone found."
/>
<span className="text-muted-foreground text-sm">
Result: <code className="text-foreground">{timezone || '—'}</code>
</span>
</div>
);
}Installation
pnpm dlx shadcn@latest add @dentil/select-searchnpx shadcn@latest add @dentil/select-searchyarn dlx shadcn@latest add @dentil/select-searchbunx --bun shadcn@latest add @dentil/select-searchFiles land in components/dentil/select-search/. Uses the stock shadcn button, command and popover, so it follows your theme.
API reference
SelectSearch
| Prop | Type | Default | Description |
|---|---|---|---|
| options | { label: string; value: string; keywords?: string[]; icon?: ReactNode | ComponentType; description?: string; labelClassName?: string }[] | — | Options to list. Search matches the value, the label, the description and any keywords. icon is a component, such as a Lucide icon, or any node, shown before the label. description is muted text after the label, in the list only. labelClassName sizes that label, such as a fixed-width code. |
| value | string | null | undefined | — | The selected option’s value. |
| onChange | (value: string) => void | — | Called with the picked value, or '' when the selected option is picked again. |
| placeholder | string | 'Select...' | Trigger label with no value. |
| searchPlaceholder | string | 'Search...' | Search field placeholder. |
| emptyText | ReactNode | 'No results.' | Shown when nothing matches. |
| filter | (value, search, keywords?) => number | — | cmdk filter. Return 0 to hide an option, and higher numbers to rank it first. |
| groups | SelectSearchOption[][] | — | Renders these groups instead of one list, with a separator between them. The separator hides while searching, and a group hides when none of its options match. options is still used for the selected label. |
| renderValue | (selected: SelectSearchOption | undefined) => ReactNode | — | Trigger content in place of the selected option’s icon and label. The chevron stays. |
| align | 'start' | 'center' | 'end' | 'start' | Popover alignment against the trigger. |
| contentClassName | string | — | Applied to the popover. It is at least as wide as the trigger; use a min-w-* class to widen it. |
| …props | ComponentProps<'button'> | — | Other props (id, aria-invalid, aria-describedby, onBlur…) are passed to the trigger button. |