Select
A Base UI select styled as a menu. Arrows, Home and End, typeahead, Enter and Escape work.
import { Select } from '@adecore/ui';import { Select } from '@adecore/ui';
import { useState } from 'react';
type Theme = 'system' | 'light' | 'dark';
export default function SelectDemo() {
const [theme, setTheme] = useState<Theme>('system');
const [sort, setSort] = useState<string | null>(null);
return (
<div className="flex flex-wrap items-center gap-3">
<Select<Theme>
label="Theme"
value={theme}
onValueChange={setTheme}
items={[
{ value: 'system', label: 'Match the system' },
{ value: 'light', label: 'Light' },
{ value: 'dark', label: 'Dark' }
]}
/>
<Select
label="Sort by"
placeholder="Sort by"
variant="ghost"
size="sm"
value={sort}
onValueChange={setSort}
items={[
{ value: 'name', label: 'Name' },
{ value: 'modified', label: 'Last modified', description: 'The newest change first' },
{ value: 'size', label: 'Size', disabled: true }
]}
/>
</div>
);
}outlined, the default, is a bordered field at most 224 pixels wide. ghost is a borderless trigger in muted text, for a toolbar. An item can carry an icon, a second-line description and disabled. Without a value the trigger shows placeholder, or "Select" (action.select).
Groups
Pass items a list of groups to get a label above each group's rows.
import { Select } from '@adecore/ui';
import { useState } from 'react';
export default function SelectGroups() {
const [font, setFont] = useState<string | null>('jetbrains');
return (
<Select
label="Font"
value={font}
onValueChange={setFont}
items={[
{
label: 'Monospace',
items: [
{ value: 'jetbrains', label: 'JetBrains Mono' },
{ value: 'sf-mono', label: 'SF Mono' }
]
},
{
label: 'Proportional',
items: [
{ value: 'inter', label: 'Inter' },
{ value: 'system', label: 'System font' }
]
}
]}
/>
);
}Search
searchable adds a search field above the options: always for true, or from that many options on for a number. Typing keeps options whose label contains the text, ignoring case. With one left, Enter picks it. Groups without matches are hidden.
import { Select } from '@adecore/ui';
import { useState } from 'react';
const LABELS = [
'Bug',
'Docs',
'Deps: JavaScript',
'Deps: PHP',
'Deps: Rust',
'Design',
'Enhancement',
'Good first issue',
'Help wanted',
'Performance',
'Question',
'Security',
'Tests',
'Wontfix'
];
export default function SelectSearchDemo() {
const [label, setLabel] = useState<string | null>(null);
return (
<Select
label="Label"
placeholder="All labels"
value={label}
onValueChange={setLabel}
searchable={10}
searchPlaceholder="Find a label"
items={LABELS.map((entry) => ({ value: entry, label: entry }))}
/>
);
}searchPlaceholder sets the field's placeholder and accessible name, "Search" (select.search) by default. An empty result shows select.noMatch.
Props
Select is generic over the value, a string type.
| Prop | Type | Default | |
|---|---|---|---|
value | T | null | Required. | |
onValueChange | (value: T) => void | Required. | |
items | SelectItem<T>[] | SelectGroup<T>[] | Required. | |
label | string | Required. The trigger's accessible name. | |
placeholder | string | "Select" | |
size | 'sm' | 'md' | 'md' | |
variant | 'outlined' | 'ghost' | 'outlined' | |
disabled | boolean | ||
align | 'start' | 'end' | 'start' | Where the popup lines up with the trigger. |
truncateValue | boolean | true | Truncates a long value. |
searchable | boolean | number | ||
searchPlaceholder | string | "Search" | |
className | string | ||
ref | Ref<HTMLButtonElement> | The trigger. |
A SelectItem<T> is { value, label, description?, icon?, disabled? }. A SelectGroup<T> is { label, items }. SelectProps, SelectItem and SelectGroup are exported types.