Skip to content

Router that virtually distributes inference across connected devices in the home.

Go
169 KB
Raw Blame

Dropdown

Use Dropdowns to allow users to select one or multiple options, navigate through links, or take actions. Dropdowns are often used for navigation, filters, or contextual actions.

Examples

Basic Dropdown With Links

<Dropdown
    items={[
        { children: 'Item 1', href: '/item-1' },
        { children: 'Item 2', href: '/item-2' },
        { children: 'Item 3', href: '/item-3' }
    ]}
    // replace default anchor with a custom link component using the renderLink prop
    // renderLink={(item) => <Link href={item.href}>{item.children}</Link>}
>
    Actions
</Dropdown>

Basic Dropdown With Handlers

Use when you need a simple list of actions triggered from a button.

<Dropdown
    items={[
        { children: 'Edit', onSelect: handleSelect },
        { children: 'Duplicate', onSelect: handleSelect },
        { children: 'Delete', danger: true, onSelect: handleSelect }
    ]}
>
    Actions
</Dropdown>

With Item Select Callback Dropdown

Use the aggregate onItemSelect callback when every item shares the same selection logic — easier to wire into a router, analytics, or a reducer than per-item onSelect handlers. Reach for per-item onSelect when each item needs distinct behavior.

<Dropdown
    items={[
        { children: 'Edit', value: 'edit' },
        { children: 'Duplicate', value: 'duplicate' },
        { children: 'Delete', value: 'delete', danger: true }
    ]}
    onItemSelect={handleItemSelect}
>
    Actions
</Dropdown>

With Icons Dropdown

Use slotStart and slotEnd to add leading or trailing icons that reinforce each item's meaning.

<Dropdown
    items={[
        {
            children: 'Edit',
            slotStart: <Document />,
            onSelect: handleSelect
        },
        {
            children: 'Duplicate',
            slotStart: <CopyDoc />,
            slotEnd: <InfoCircle />,
            onSelect: handleSelect
        },
        {
            children: 'Delete',
            danger: true,
            slotStart: <Trash />,
            onSelect: handleSelect
        }
    ]}
>
    Actions
</Dropdown>

With Sections Dropdown

Use when dropdown items are logically grouped into categories that benefit from visual separation.

<Dropdown
    items={[
        {
            slotHeading: 'Navigation',
            items: [
                { children: 'Dashboard', onSelect: handleSelect },
                { children: 'Settings', onSelect: handleSelect }
            ]
        },
        {
            slotHeading: 'Account',
            items: [
                { children: 'Profile', onSelect: handleSelect },
                { children: 'Sign Out', danger: true, onSelect: handleSelect }
            ]
        }
    ]}
>
    Menu
</Dropdown>

With Sub Menu Dropdown

Use when certain actions have nested options that should be discoverable without cluttering the main list.

<Dropdown
    items={[
        { children: 'Cut', onSelect: handleSelect },
        { children: 'Copy', onSelect: handleSelect },
        {
            kind: 'sub',
            children: 'Share',
            items: [
                { children: 'Email', onSelect: handleSelect },
                { children: 'Slack', onSelect: handleSelect }
            ]
        }
    ]}
>
    Edit
</Dropdown>

With Dividers Dropdown

Insert a divider entry to visually separate destructive or unrelated actions inside a flat list.

<Dropdown
    items={[
        { children: 'Open', onSelect: handleSelect },
        { children: 'Open in New Tab', onSelect: handleSelect },
        { kind: 'divider' },
        { children: 'Rename', onSelect: handleSelect },
        { children: 'Move', onSelect: handleSelect },
        { kind: 'divider' },
        { children: 'Delete', danger: true, onSelect: handleSelect }
    ]}
>
    File
</Dropdown>

Checkbox Dropdown

Use when the user needs to toggle multiple independent options from a single dropdown.

<Dropdown
    items={[
        {
            children: 'Show Labels',
            kind: 'checkbox',
            defaultChecked: true
        },
        {
            children: 'Show Tooltips',
            kind: 'checkbox'
        },
        {
            children: 'Compact Mode',
            kind: 'checkbox'
        }
    ]}
>
    View Options
</Dropdown>

Radio Dropdown

Use when the user must pick exactly one option from a group of mutually exclusive choices.

<Dropdown
    items={[
        {
            kind: 'radio',
            name: 'theme',
            slotHeading: 'Theme',
            defaultValue: 'auto',
            items: [
                { children: 'Auto', value: 'auto' },
                { children: 'Light', value: 'light' },
                { children: 'Dark', value: 'dark' }
            ]
        }
    ]}
>
    Theme
</Dropdown>

Check Radio Dropdown

Set radioKind to 'check' when you want a single checkmark on the selected option instead of radio dots — common for compact filter or theme pickers.

<Dropdown
    items={[
        {
            kind: 'radio',
            radioKind: 'check',
            name: 'status',
            slotHeading: 'Status',
            defaultValue: 'ready',
            items: [
                { children: 'Ready', value: 'ready' },
                { children: 'Pending', value: 'pending' },
                { children: 'Completed', value: 'completed' }
            ]
        }
    ]}
>
    Status
</Dropdown>

Mixed Dropdown

Combine action items, checkbox toggles, and radio groups in a single dropdown by nesting them in sections.

<Dropdown
    items={[
        {
            slotHeading: 'Actions',
            items: [
                { children: 'Edit', onSelect: handleSelect },
                { children: 'Duplicate', onSelect: handleSelect },
                { children: 'Delete', danger: true, onSelect: handleSelect }
            ]
        },
        {
            slotHeading: 'Settings',
            items: [
                {
                    kind: 'checkbox',
                    children: 'Show notifications',
                    defaultChecked: true
                },
                {
                    kind: 'checkbox',
                    children: 'Auto-save',
                    defaultChecked: false
                }
            ]
        },
        {
            kind: 'radio',
            slotHeading: 'Theme',
            name: 'mixed-theme',
            defaultValue: 'system',
            items: [
                { children: 'System', value: 'system' },
                { children: 'Light', value: 'light' },
                { children: 'Dark', value: 'dark' }
            ]
        }
    ]}
>
    More
</Dropdown>

Filterable Dropdown

Use when the dropdown contains many items and the user benefits from searching to find their selection quickly.

<Dropdown
    filterable
    items={[
        { children: 'United States', onSelect: handleSelect },
        { children: 'Canada', onSelect: handleSelect },
        { children: 'United Kingdom', onSelect: handleSelect },
        { children: 'Germany', onSelect: handleSelect },
        { children: 'Japan', onSelect: handleSelect }
    ]}
>
    Select Country
</Dropdown>

Icon Only Trigger Dropdown

Use an icon child with showChevron={false} for kebab/overflow menus where space is constrained. Always supply an aria-label.

<Dropdown
    showChevron={false}
    aria-label="More actions"
    items={[
        { children: 'Edit', onSelect: handleSelect },
        { children: 'Duplicate', onSelect: handleSelect },
        { children: 'Delete', danger: true, onSelect: handleSelect }
    ]}
>
    <MenuIcon />
</Dropdown>

Size Dropdown

Match the trigger size to the surrounding controls. Pass density to override the menu's default density independently from the trigger size.

<Flex gap="2" align="center" wrap="wrap">
    <Dropdown size="small" items={['Item 1', 'Item 2', 'Item 3']}>
        Small
    </Dropdown>
    <Dropdown size="medium" items={['Item 1', 'Item 2', 'Item 3']}>
        Medium
    </Dropdown>
    <Dropdown size="large" items={['Item 1', 'Item 2', 'Item 3']}>
        Large
    </Dropdown>
</Flex>

Positioning Dropdown

Combine side (top | bottom | left | right) and align (start | center | end) to override the default bottom/start placement when the menu would clip against a scroll container or viewport edge.

<Dropdown side="right" align="end" items={['Item 1', 'Item 2', 'Item 3']}>
    Open
</Dropdown>

Server Actions Dropdown

Wrap composed primitives in a

and pass formAction/formMethod on each DropdownItem so the menu submits to different endpoints without JavaScript.

<form>
    <DropdownRoot>
        <DropdownTrigger>Task Actions</DropdownTrigger>
        <DropdownContent>
            <DropdownItem formAction="/api/tasks/complete" formMethod="post">
                Mark as Complete
            </DropdownItem>
            <DropdownItem formAction="/api/tasks/reassign" formMethod="post">
                Reassign
            </DropdownItem>
            <DropdownItem danger formAction="/api/tasks/delete" formMethod="post">
                Delete Task
            </DropdownItem>
        </DropdownContent>
    </DropdownRoot>
</form>

Composed

Use composed primitives when you need full control over the dropdown trigger, content, and item rendering.

<DropdownRoot>
    <DropdownTrigger asChild>
        <Button>Open</Button>
    </DropdownTrigger>
    <DropdownContent>
        <DropdownItem
        // onSelect={handleSelect}
        >
            Item 1
        </DropdownItem>
        <DropdownItem
        // onSelect={handleSelect}
        >
            Item 2
        </DropdownItem>
        <DropdownItem
            danger
            // onSelect={handleSelect}
        >
            Delete
        </DropdownItem>
    </DropdownContent>
</DropdownRoot>

Props

Prop Type Default Description
items * string | ({ href: string; children: ReactNode; onSelect: (event: Event) => void; disabled: boolean; value: string; kind: "default"; formAction: string; formMethod: "get" | "post"; danger: boolean; slotEnd: ReactNode; slotStart: ReactNode; filterValue: string }) | ({ defaultChecked: boolean; children: ReactNode; onSelect: (event: Event) => void; disabled: boolean; kind: "checkbox"; danger: boolean; checked: false | true | "indeterminate"; error: boolean; onCheckedChange: (checked: false | true | "indeterminate") => void; slotEnd: ReactNode; slotStart: ReactNode; filterValue: string; slotControl: ReactNode }) | ({ items: string | ({ children: ReactNode; onSelect: (event: Event) => void; disabled: boolean; value: string; kind: never; danger: boolean; required: boolean; slotEnd: ReactNode; slotStart: ReactNode; filterValue: string })[]; defaultValue: string; disabled: boolean; name: string; value: string; kind: "radio"; required: boolean; error: boolean; onValueChange: (value: string) => void; slotHeading: ReactNode; radioKind: "radio" | "check" }) | ({ kind: "sub"; children: ReactNode; items: ({ href: string; children: ReactNode; onSelect: (event: Event) => void; disabled: boolean; value: string; kind: "default"; formAction: string; formMethod: "get" | "post"; danger: boolean; slotEnd: ReactNode; slotStart: ReactNode; filterValue: string }) | ({ defaultChecked: boolean; children: ReactNode; onSelect: (event: Event) => void; disabled: boolean; kind: "checkbox"; danger: boolean; checked: false | true | "indeterminate"; error: boolean; onCheckedChange: (checked: false | true | "indeterminate") => void; slotEnd: ReactNode; slotStart: ReactNode; filterValue: string; slotControl: ReactNode }) | ({ items: string | ({ children: ReactNode; onSelect: (event: Event) => void; disabled: boolean; value: string; kind: never; danger: boolean; required: boolean; slotEnd: ReactNode; slotStart: ReactNode; filterValue: string })[]; defaultValue: string; disabled: boolean; name: string; value: string; kind: "radio"; required: boolean; error: boolean; onValueChange: (value: string) => void; slotHeading: ReactNode; radioKind: "radio" | "check" }) | { kind: "divider"; width: "small" | "medium" | "large"; filterValue: never } | Omit<DropdownSectionEntry, "items"> & { items: (DropdownDefaultItemEntry | DropdownCheckboxItemEntry | DropdownDividerItemEntry)[]; }[]; filterValue: string; onSelect: (event: Event) => void; disabled: boolean; danger: boolean; slotEnd: ReactNode; slotStart: ReactNode; open: boolean; defaultOpen: boolean; onOpenChange: (open: boolean) => void; density: "compact" | "standard" | "spacious"; sideOffset: number; alignOffset: number }) | ({ items: ({ href: string; children: ReactNode; onSelect: (event: Event) => void; disabled: boolean; value: string; kind: "default"; formAction: string; formMethod: "get" | "post"; danger: boolean; slotEnd: ReactNode; slotStart: ReactNode; filterValue: string }) | ({ defaultChecked: boolean; children: ReactNode; onSelect: (event: Event) => void; disabled: boolean; kind: "checkbox"; danger: boolean; checked: false | true | "indeterminate"; error: boolean; onCheckedChange: (checked: false | true | "indeterminate") => void; slotEnd: ReactNode; slotStart: ReactNode; filterValue: string; slotControl: ReactNode }) | ({ kind: "sub"; children: ReactNode; items: ({ href: string; children: ReactNode; onSelect: (event: Event) => void; disabled: boolean; value: string; kind: "default"; formAction: string; formMethod: "get" | "post"; danger: boolean; slotEnd: ReactNode; slotStart: ReactNode; filterValue: string }) | ({ defaultChecked: boolean; children: ReactNode; onSelect: (event: Event) => void; disabled: boolean; kind: "checkbox"; danger: boolean; checked: false | true | "indeterminate"; error: boolean; onCheckedChange: (checked: false | true | "indeterminate") => void; slotEnd: ReactNode; slotStart: ReactNode; filterValue: string; slotControl: ReactNode }) | ({ items: string | ({ children: ReactNode; onSelect: (event: Event) => void; disabled: boolean; value: string; kind: never; danger: boolean; required: boolean; slotEnd: ReactNode; slotStart: ReactNode; filterValue: string })[]; defaultValue: string; disabled: boolean; name: string; value: string; kind: "radio"; required: boolean; error: boolean; onValueChange: (value: string) => void; slotHeading: ReactNode; radioKind: "radio" | "check" }) | { kind: "divider"; width: "small" | "medium" | "large"; filterValue: never } | Omit<DropdownSectionEntry, "items"> & { items: (DropdownDefaultItemEntry | DropdownCheckboxItemEntry | DropdownDividerItemEntry)[]; }[]; filterValue: string; onSelect: (event: Event) => void; disabled: boolean; danger: boolean; slotEnd: ReactNode; slotStart: ReactNode; open: boolean; defaultOpen: boolean; onOpenChange: (open: boolean) => void; density: "compact" | "standard" | "spacious"; sideOffset: number; alignOffset: number }) | { kind: "divider"; width: "small" | "medium" | "large"; filterValue: never }[]; children: never; kind: "section"; filterValue: never; slotHeading: ReactNode }) | { kind: "divider"; width: "small" | "medium" | "large"; filterValue: never }[] - The items to render in the dropdown.
align "center" | "start" | "end" "start" The alignment of the dropdown content relative to the trigger.
asChild boolean - When true, renders the immediate child instead of the default element, merging this component's props with the child's props.
defaultFilterValue string - This sets the default value of the dropdown search input.
defaultOpen boolean false The open state of the dropdown when it is initially rendered. Use when you do not need to control its open state.
density "compact" | "standard" | "spacious" "standard" The "density" of the component. This affects the padding/spacing of the component and its children. By default, the component will inherit density from its parent, which is usually standard. - Setting to null or undefined will allow the component to inherit density from its parent. - Setting to compact will reduce the padding/spacing of the component and its children. - Setting to standard will use the standard padding/spacing of the component and its children. - Setting to spacious will increase the padding/spacing of the component and its children.
disabled boolean - When true, prevents the user from interacting with the dropdown.
filterable boolean false Whether the dropdown is filterable.
filterMatchFn "disable" | ((matchTerm: string, value: string) => boolean) - The function to use to match items against the search value.
filterValue string - The controlled value of the dropdown search input. Must be used in conjunction with onFilterChange.
id string - A stable identifier used to derive the dropdown content id and CSS anchor name. Provide this when rendering in SSR-sensitive trees to ensure the generated ids remain consistent between server and client.
modal boolean false The modality of the dropdown. When set to true, interaction with outside elements will be disabled and only menu content will be visible to screen readers. Modality is disabled by default to minimize performance impact.
onCloseAutoFocus (event: Event) => void - Event handler called when focus moves to the trigger after closing. It can be prevented by calling event.preventDefault.
onEscapeKeyDown (event: KeyboardEvent) => void - Event handler called when the escape key is down. It can be prevented by calling event.preventDefault.
onFilterChange (value: string) => void - Callback fired when the search value changes.
onInteractOutside (event: Event) => void - Event handler called when an interaction event occurs outside the bounds of the component. It can be prevented by calling event.preventDefault.
onItemCheckedChange (item: { defaultChecked: boolean; children: ReactNode; onSelect: (event: Event) => void; disabled: boolean; kind: "checkbox"; danger: boolean; checked: false | true | "indeterminate"; error: boolean; onCheckedChange: (checked: false | true | "indeterminate") => void; slotEnd: ReactNode; slotStart: ReactNode; filterValue: string; slotControl: ReactNode }, checked: false | true | "indeterminate") => void - Callback fired when a dropdown item's checked state changes.
onItemSelect (event: Event, item: ({ href: string; children: ReactNode; onSelect: (event: Event) => void; disabled: boolean; value: string; kind: "default"; formAction: string; formMethod: "get" | "post"; danger: boolean; slotEnd: ReactNode; slotStart: ReactNode; filterValue: string }) | ({ defaultChecked: boolean; children: ReactNode; onSelect: (event: Event) => void; disabled: boolean; kind: "checkbox"; danger: boolean; checked: false | true | "indeterminate"; error: boolean; onCheckedChange: (checked: false | true | "indeterminate") => void; slotEnd: ReactNode; slotStart: ReactNode; filterValue: string; slotControl: ReactNode }) | ({ children: ReactNode; onSelect: (event: Event) => void; disabled: boolean; value: string; kind: never; danger: boolean; required: boolean; slotEnd: ReactNode; slotStart: ReactNode; filterValue: string })) => void - Callback fired when a dropdown item is selected.
onOpenChange (open: boolean) => void - Event handler called when the open state of the dropdown changes.
onPointerDownOutside (event: Event) => void - Event handler called when a pointer event occurs outside the bounds of the component. It can be prevented by calling event.preventDefault.
open boolean - The controlled open state of the dropdown. Must be used in conjunction with onOpenChange.
ref ((instance: HTMLButtonElement) => void | (() => void | { [UNDEFINED_VOID_ONLY]: never; })) | React.RefObject<HTMLButtonElement> - Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
renderLink (item: { href: string; children: ReactNode; onSelect: (event: Event) => void; disabled: boolean; value: string; kind: "default"; formAction: string; formMethod: "get" | "post"; danger: boolean; slotEnd: ReactNode; slotStart: ReactNode; filterValue: string }) => ReactNode - Render a custom link component - useful if your framework has a custom link component i.e. Next.js Link.
showChevron boolean true When true, shows the chevron icon showing the current state of the dropdown.
side "right" | "bottom" | "left" | "top" "bottom" The preferred side of the trigger to render against when open. Will be reversed when collisions occur.
size "small" | "tiny" | "medium" | "large" "medium" The size of the dropdown and its trigger.

* = required prop