Skip to content

Select ​

A Base UI select styled as a menu. Arrows, Home and End, typeahead, Enter and Escape work.

tsx
import { Select } from '@adecore/ui';
tsx
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.

tsx
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' }
                    ]
                }
            ]}
        />
    );
}

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.

tsx
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.

PropTypeDefault
valueT | nullRequired.
onValueChange(value: T) => voidRequired.
itemsSelectItem<T>[] | SelectGroup<T>[]Required.
labelstringRequired. The trigger's accessible name.
placeholderstring"Select"
size'sm' | 'md''md'
variant'outlined' | 'ghost''outlined'
disabledboolean
align'start' | 'end''start'Where the popup lines up with the trigger.
truncateValuebooleantrueTruncates a long value.
searchableboolean | number
searchPlaceholderstring"Search"
classNamestring
refRef<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.

Licenses and third-party notices are listed in each package.