Drawer Menu
newWe need to go deeper. A menu in a drawer for touch screens, with checkbox and radio items and submenus that drill down in the same sheet.
Open Props in the corner of the example to try size. It takes Menu's names, xs to xl, on the same control scale, plus room for a thumb: rows come out at 36, 40, 48 (the default), 56 and 64px, with a little more padding and, from md up, a larger icon. From sm up every row is large enough to tap; xs packs a long list tighter.
Installation
Usage
<script setup lang="ts">
import { Button } from '@/components/ui/button'
import { Drawer, DrawerContent, DrawerHeader, DrawerTitle, DrawerTrigger } from '@/components/ui/drawer'
import { DrawerMenu, DrawerMenuItem, DrawerMenuSeparator } from '@/components/ui/drawer-menu'
</script>
<template>
<Drawer>
<DrawerTrigger as-child>
<Button>Actions</Button>
</DrawerTrigger>
<DrawerContent>
<DrawerHeader>
<DrawerTitle>report.pdf</DrawerTitle>
</DrawerHeader>
<DrawerMenu>
<DrawerMenuItem>Rename</DrawerMenuItem>
<DrawerMenuSeparator />
<DrawerMenuItem color="destructive">Delete</DrawerMenuItem>
</DrawerMenu>
</DrawerContent>
</Drawer>
</template>
Put DrawerMenu in DrawerContent, after the header. The drawer's title names the menu.
Picking an item closes the drawer. To keep it open, prevent the item's select event.
The parts take the same props and events as Menu's, so one menu can render as either. See Responsive menu.
Examples
Selection
Checkbox items and radio items close the drawer like any other item; @select.prevent keeps it open while the user changes several of them.
Submenus
A DrawerMenuSub drills down: its content replaces the list, slides in from the end and starts with a back row named after its trigger. textValue on the trigger names the back row instead of the trigger's text.
Responsive menu
Desktop gets a dropdown or a right-click menu, phones get a drawer. Write the items once against a set of parts, and pass in the set that fits:
// menu-parts.ts
export interface MenuPartSet {
Item: Component
Separator: Component
Label: Component
Group: Component
Sub: Component
SubTrigger: Component
SubContent: Component
RadioGroup: Component
RadioItem: Component
CheckboxItem: Component
}
export const menuParts: MenuPartSet = { Item: MenuItem, Sub: MenuSub /* … */ }
export const sheetParts: MenuPartSet = { Item: DrawerMenuItem, Sub: DrawerMenuSub /* … */ }
In the demo, the same items render as a Menu next to the ⋯ button and on right-click, and as a DrawerMenu below 768px.
Keep checkbox and radio state outside the menu, so it survives the switch.
roadmap.key
Tap ⋯ for actions
Custom motion
Every panel carries data-motion while it slides, from-end or from-start when it arrives and to-start or to-end when it leaves, and data-state (active or inactive). A leaving panel stays on screen until its own animation or transition ends, so any CSS on those attributes replaces the slide: keyframes on data-motion, or a transition on data-state with @starting-style for the arriving panel.
API Reference
DrawerMenu
| Prop | Default | Type and description |
|---|---|---|
| loop | — | booleanWhether the arrow keys wrap from the last item to the first and back. |
| dir | — | DrawerMenuDirectionReading direction, |
| asChild | — | booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it. The child's own content becomes the root panel, and the submenu panels go inside the child after it, such as |
| as | — | AsTag | ComponentThe element or component to render. |
| size | "md" | DrawerMenuSizeRow height, padding and icon size, from the control scale plus room for a thumb: |
| Slot | Scope and description |
|---|---|
| default | {}Items, groups, labels, separators and submenus. |
DrawerMenuItem
| Prop | Default | Type and description |
|---|---|---|
| disabled | — | booleanDisables the item: it is skipped by the keyboard and cannot be chosen. |
| textValue | — | stringKept for parity with the dropdown and context menu items; the drawer menu has no typeahead. |
| asChild | — | booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it. |
| as | — | AsTag | ComponentThe element or component to render. |
| inset | — | booleanIndents the text to line up with items that have an indicator. |
| color | — | DrawerMenuItemColor | (string & {})Colour role the item, its icon and its hover layer are drawn in, such as |
| Event | Payload and description |
|---|---|
| select | [event: Event]Fires when the item is chosen by tap, click or keyboard. Call |
| Slot | Scope and description |
|---|---|
| default | {}The label, with an optional leading icon. |
DrawerMenuCheckboxItem
| Prop | Default | Type and description |
|---|---|---|
| modelValue | — | DrawerMenuCheckedStateWhether it is checked, |
| disabled | — | booleanDisables the item: it is skipped by the keyboard and cannot be chosen. |
| textValue | — | stringKept for parity with the dropdown and context menu items; the drawer menu has no typeahead. |
| asChild | — | booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it. |
| as | — | AsTag | ComponentThe element or component to render. |
| Event | Payload and description |
|---|---|
| select | [event: Event]Fires when the item is chosen. Call |
| update:modelValue | [value: DrawerMenuCheckedState]Fires when the item is toggled. |
| Slot | Scope and description |
|---|---|
| indicator-icon | {}The icon shown while checked, a check by default. |
| default | {}The label. |
DrawerMenuRadioGroup
| Prop | Default | Type and description |
|---|---|---|
| modelValue | — | AcceptableValueThe value of the checked item, bound with |
| asChild | — | booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it. |
| as | — | AsTag | ComponentThe element or component to render. |
| Event | Payload and description |
|---|---|
| update:modelValue | [value: AcceptableValue]Fires when another item is chosen. |
| Slot | Scope and description |
|---|---|
| default | {}
|
DrawerMenuRadioItem
| Prop | Default | Type and description |
|---|---|---|
| value* | — | AcceptableValueThe value the group takes when this item is chosen. |
| disabled | — | booleanDisables the item: it is skipped by the keyboard and cannot be chosen. |
| textValue | — | stringKept for parity with the dropdown and context menu items; the drawer menu has no typeahead. |
| asChild | — | booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it. |
| as | — | AsTag | ComponentThe element or component to render. |
| Event | Payload and description |
|---|---|
| select | [event: Event]Fires when the item is chosen. Call |
| Slot | Scope and description |
|---|---|
| indicator-icon | {}The mark shown while checked, a dot by default. |
| default | {}The label. |
DrawerMenuSub
| Prop | Default | Type and description |
|---|---|---|
| open | — | booleanWhether it is open, bound with |
| defaultOpen | — | booleanWhether it starts open when |
| Event | Payload and description |
|---|---|
| update:open | [value: boolean]Fires when it opens or closes. |
| Slot | Scope and description |
|---|---|
| default | { open: boolean; }A |
DrawerMenuSubTrigger
| Prop | Default | Type and description |
|---|---|---|
| disabled | — | booleanDisables the item: it is skipped by the keyboard and cannot open its submenu. |
| textValue | — | stringThe label of the back row in its submenu, instead of the trigger's text. |
| asChild | — | booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it. |
| as | — | AsTag | ComponentThe element or component to render. |
| inset | — | booleanIndents the text to line up with items that have an indicator. |
| Slot | Scope and description |
|---|---|
| default | {}The label, with an optional leading icon; a chevron follows it. |
DrawerMenuGroup
| Prop | Default | Type and description |
|---|---|---|
| asChild | — | booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it. |
| as | — | AsTag | ComponentThe element or component to render. |
| Slot | Scope and description |
|---|---|
| default | {}Related items. |
DrawerMenuLabel
| Prop | Default | Type and description |
|---|---|---|
| asChild | — | booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it. |
| as | — | AsTag | ComponentThe element or component to render. |
| inset | — | booleanIndents the text to line up with items that have an indicator. |
| Slot | Scope and description |
|---|---|
| default | {}The label text. |
DrawerMenuSeparator
| Prop | Default | Type and description |
|---|---|---|
| asChild | — | booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it. |
| as | — | AsTag | ComponentThe element or component to render. |
DrawerMenuSubContent
| Slot | Scope and description |
|---|---|
| default | {}The submenu's items. A back row naming the trigger comes first. |
Props
- loop
booleanWhether the arrow keys wrap from the last item to the first and back.- dir
DrawerMenuDirectionReading direction,ltrorrtl; it swaps the keys that open and close a submenu. Defaults to theConfigProviderdirection.- asChild
booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it. The child's own content becomes the root panel, and the submenu panels go inside the child after it, such as<nav>around the items.- as
AsTag | ComponentThe element or component to render.- size
"md" DrawerMenuSizeRow height, padding and icon size, from the control scale plus room for a thumb:xs36px,sm40px,md48px (default),lg56px,xl64px.
Slots
- default
{}Items, groups, labels, separators and submenus.
Props
- disabled
booleanDisables the item: it is skipped by the keyboard and cannot be chosen.- textValue
stringKept for parity with the dropdown and context menu items; the drawer menu has no typeahead.- asChild
booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it.- as
AsTag | ComponentThe element or component to render.- inset
booleanIndents the text to line up with items that have an indicator.- color
DrawerMenuItemColor | (string & {})Colour role the item, its icon and its hover layer are drawn in, such asdestructivefor actions that delete or cannot be undone. Any other name picks up a colour you declare on[data-slot][data-color="<name>"].
Emits
- select
[event: Event]Fires when the item is chosen by tap, click or keyboard. Callevent.preventDefault()to keep the drawer open.
Slots
- default
{}The label, with an optional leading icon.
Props
- modelValue
DrawerMenuCheckedStateWhether it is checked,true,falseorindeterminate, bound withv-model.- disabled
booleanDisables the item: it is skipped by the keyboard and cannot be chosen.- textValue
stringKept for parity with the dropdown and context menu items; the drawer menu has no typeahead.- asChild
booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it.- as
AsTag | ComponentThe element or component to render.
Emits
- select
[event: Event]Fires when the item is chosen. Callevent.preventDefault()to keep the drawer open.- update:modelValue
[value: DrawerMenuCheckedState]Fires when the item is toggled.
Slots
- indicator-icon
{}The icon shown while checked, a check by default.- default
{}The label.
Props
- modelValue
AcceptableValueThe value of the checked item, bound withv-model.- asChild
booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it.- as
AsTag | ComponentThe element or component to render.
Emits
- update:modelValue
[value: AcceptableValue]Fires when another item is chosen.
Slots
- default
{}DrawerMenuRadioItems.
Props
- value*
AcceptableValueThe value the group takes when this item is chosen.- disabled
booleanDisables the item: it is skipped by the keyboard and cannot be chosen.- textValue
stringKept for parity with the dropdown and context menu items; the drawer menu has no typeahead.- asChild
booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it.- as
AsTag | ComponentThe element or component to render.
Emits
- select
[event: Event]Fires when the item is chosen. Callevent.preventDefault()to keep the drawer open.
Slots
- indicator-icon
{}The mark shown while checked, a dot by default.- default
{}The label.
Props
- open
booleanWhether it is open, bound withv-model:open.- defaultOpen
booleanWhether it starts open whenv-model:openis not used.
Emits
- update:open
[value: boolean]Fires when it opens or closes.
Slots
- default
{ open: boolean; }ADrawerMenuSubTriggerand aDrawerMenuSubContent.
Props
- disabled
booleanDisables the item: it is skipped by the keyboard and cannot open its submenu.- textValue
stringThe label of the back row in its submenu, instead of the trigger's text.- asChild
booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it.- as
AsTag | ComponentThe element or component to render.- inset
booleanIndents the text to line up with items that have an indicator.
Slots
- default
{}The label, with an optional leading icon; a chevron follows it.
Props
- asChild
booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it.- as
AsTag | ComponentThe element or component to render.
Slots
- default
{}Related items.
Props
- asChild
booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it.- as
AsTag | ComponentThe element or component to render.- inset
booleanIndents the text to line up with items that have an indicator.
Slots
- default
{}The label text.
Props
- asChild
booleanRender the single child instead of a wrapper, merging this part's attributes and classes onto it.- as
AsTag | ComponentThe element or component to render.
Slots
- default
{}The submenu's items. A back row naming the trigger comes first.
Data attributes
| data-slot | Attributes | Description |
|---|---|---|
| drawer-menu | data-size | The menu inside the drawer. data-size is xs to xl. |
| drawer-menu-item | data-highlighted, data-disabled, data-inset, data-color | An item. data-color carries its color; data-highlighted marks keyboard focus or a resting mouse. |
| drawer-menu-checkbox-item | data-state, data-highlighted, data-disabled | A checkbox item. data-state is checked, unchecked or indeterminate. |
| drawer-menu-radio-item | data-state, data-highlighted, data-disabled | A radio item. |
| drawer-menu-item-indicator | data-state | The check or dot of a checked item. |
| drawer-menu-radio-group | — | A group of radio items. |
| drawer-menu-group | — | A group of related items. |
| drawer-menu-label | data-inset | A label for the items after it. |
| drawer-menu-separator | — | A line between groups. |
| drawer-menu-sub-trigger | data-state, data-highlighted, data-inset | The item that opens a submenu. data-state is open while its submenu is. |
| drawer-menu-sub-content | data-state, data-motion | A submenu's panel. data-state is active while it is the visible one; data-motion is from-start, from-end, to-start or to-end. |
| drawer-menu-back | data-highlighted | The row at the top of a submenu that goes back. |
Accessibility
Each panel is a menu: the root one labelled by the drawer's title, a submenu labelled by its trigger, which carries aria-haspopup, aria-expanded and aria-controls. Checkbox and radio items are menuitemcheckbox and menuitemradio with aria-checked. Only the visible panel can be focused; the others are hidden and inert.
| Key | Action |
|---|---|
| ArrowDown | Moves focus to the next item. |
| ArrowUp | Moves focus to the previous item. |
| Home | Moves focus to the first item. |
| End | Moves focus to the last item. |
| Enter | Chooses the focused item, or opens its submenu. |
| Space | Chooses the focused item, or opens its submenu. |
| ArrowRight | Opens the focused submenu (ArrowLeft in right-to-left text). |
| ArrowLeft | Goes back from a submenu (ArrowRight in right-to-left text), unless focus is in a text field. |
| Backspace | Goes back from a submenu, unless focus is in a text field. |
| Escape | Goes back from a submenu; at the top level closes the drawer. |