Skip to content

Menu

import { Menu } from 'yarcl';
Last action: nothing yet
<Menu>
<Menu.Trigger>
<Button variant="outline">Actions</Button>
</Menu.Trigger>
<Menu.Content>
<Menu.Item onSelect={rename}>Rename</Menu.Item>
<Menu.Item disabled>Move</Menu.Item>
<Menu.Separator />
<Menu.Item color="danger" onSelect={remove}>Delete</Menu.Item>
</Menu.Content>
</Menu>

For choosing a value, use Select instead: a menu is for actions (role="menu"), a select for values (role="listbox").

Key Action
Enter Space on the trigger opens the menu and focuses the first item
moves between items, skipping disabled ones
typing jumps to a matching item
Enter Space runs the item and closes the menu
Esc closes; focus returns to the trigger
PropTypeDefaultDescription
childrenReactNodeMenu.Trigger and Menu.Content.
defaultOpenbooleanfalseInitial open state when uncontrolled.
onOpenChange(open: boolean) => voidCalled when the menu opens or closes.
openbooleanControlled open state.
placementPlacement'bottom-start'Preferred side. Flips when there isn't room.
sizeSizeconfigconfig.defaults.sizeItem size, from the sizes config.
PropTypeDefaultDescription
colorColorconfigSemantic color for the item, e.g. a destructive action. From the colors config.
onSelect() => voidCalled when the item is chosen by click, Enter or Space. The menu closes afterwards.
textValuestringText used for type-to-select. Defaults to children when it is a string.