Skip to content

DropdownMenu API

import { DropdownMenu } from "@stratakit/structures";
// OR
import * as DropdownMenu from "@stratakit/structures/DropdownMenu";

A dropdown menu displays a list of actions or commands when the menu button is clicked.

DropdownMenu is a compound component with subcomponents exposed for different parts.

Example:

<DropdownMenu.Provider>
<DropdownMenu.Button>Actions</DropdownMenu.Button>
<DropdownMenu.Content>
<DropdownMenu.Item label="Add" />
<DropdownMenu.Item label="Edit" />
<DropdownMenu.Item label="Delete" />
</DropdownMenu.Content>
</DropdownMenu.Provider>

Note: DropdownMenu should not be used for navigation; it is only intended for actions.

Type: ReactNode (optional)
Type: boolean | undefined (optional)
Default: false

Whether the content should be visible by default.

Type: boolean | undefined (optional)
Default: false

Whether the content is visible.

Type: Placement | undefined (optional)
Default: "bottom-start"
Type: ((open: boolean) => void) | undefined (optional)

A callback that gets called when the open state changes.

Base element: <button>

The button that triggers the dropdown menu to open. Should be used as a child of DropdownMenu.Provider.

Example:

<DropdownMenu.Button>Actions</DropdownMenu.Button>

By default it will render a solid Button with a disclosure arrow. This can be customized by passing a render prop.

<DropdownMenu.Button
render={<IconButton variant="ghost" label="More" icon={<Icon href={…} />} />}
/>
Base element: <div>

The actual “menu” portion containing the items shown within the dropdown.

Should be used as a child of DropdownMenu.Provider.

Should include one or more of DropdownMenu.Item, DropdownMenu.CheckboxItem and DropdownMenu.Group as direct descendants.

Base element: <button>

A single menu item within the dropdown menu. Should be used as a child of DropdownMenu.Content and DropdownMenu.Submenu.

Example:

<DropdownMenu.Item label="Add" />
<DropdownMenu.Item label="Edit" />

Use the submenu prop to display a submenu.

Example:

<DropdownMenu.Item
label="More"
submenu={
<DropdownMenu.Submenu>
<DropdownMenu.Item label="Add" />
<DropdownMenu.Item label="Edit" />
</DropdownMenu.Submenu>
}
/>
Type: ReactNode (required)

The primary text label for the menu-item.

Type: string | Element | undefined (optional)

An optional icon displayed before the menu-item label.

Can be a URL of an SVG from the @stratakit/icons package, or a custom JSX icon.

Type: AnyString | `Control+${AnyString}` | `Shift+${AnyString}` | `Backspace+${AnyString}` | `Command+${AnyString}` | `Down+${AnyString}` | `Eject+${AnyString}` | ... 8 more ... | undefined (optional)

A string defining the keyboard shortcut(s) associated with the menu item.

shortcuts="S" // A single key shortcut

Multiple keys should be separated by the + character. If one of the keys is recognized as a symbol name or a modifier key, it will be displayed as a symbol.

shortcuts="Control+Enter" // A multi-key shortcut, displayed as "Ctrl ⏎"
Type: ReactNode (optional)

The submenu to display when the item is activated. Must be a DropdownMenu.Submenu component.

Type: string | undefined (optional)

Dot shown on the right end of the menu-item. Value will be used as accessible description.

Base element: <button>

A single checkbox menu item within the dropdown menu. Should be used as a child of DropdownMenu.Content and DropdownMenu.Submenu.

Example:

<DropdownMenu.CheckboxItem name="add" label="Add" />
<DropdownMenu.CheckboxItem name="edit" label="Edit" />
Type: ReactNode (required)

The primary text label for the menu-item.

Type: string (required)

The name of the field in the values state.

Type: boolean | undefined (optional)

The controlled checked state of the element. It will set the menu values state if provided.

Type: boolean | undefined (optional)

The default checked state of the element. It will set the default value in the menu values state if provided.

Type: string | Element | undefined (optional)

An optional icon displayed before the menu-item label.

Can be a URL of an SVG from the @stratakit/icons package, or a custom JSX icon.

Type: ChangeEventHandler<HTMLInputElement, HTMLInputElement> | undefined (optional)

A function that is called when the checkbox’s checked state changes.

Type: string | number | readonly string[] | undefined (optional)

The value of the checkbox. This is useful when the same checkbox store is used for multiple Checkbox elements, in which case the value will be an array of checked values.

Base element: <div>

The submenu portion containing the nested submenu items.

Should be passed into the submenu prop of DropdownMenu.Item.

Should include one or more of DropdownMenu.Item, DropdownMenu.CheckboxItem and DropdownMenu.Group as direct descendants.

Base element: <div>

A group of menu items within the dropdown menu. Should be used as a child of DropdownMenu.Content and DropdownMenu.Submenu.

Example:

<DropdownMenu.Group
label="Manage"
items={[
<DropdownMenu.Item key="add" label="Add" />,
<DropdownMenu.Item key="edit" label="Edit" />
]}
/>
Type: Element[] (required)

The menu items within the group.

Should be an array of DropdownMenu.Item and/or DropdownMenu.CheckboxItem elements.

Type: string (required)

The text label for the menu-group.