Drawer Menu

new

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

Demo

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.

Selection

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.

Submenus

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.

Responsive

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.

Custom motion

API Reference

Data attributes

data-slotAttributesDescription
drawer-menudata-sizeThe menu inside the drawer. data-size is xs to xl.
drawer-menu-itemdata-highlighted, data-disabled, data-inset, data-colorAn item. data-color carries its color; data-highlighted marks keyboard focus or a resting mouse.
drawer-menu-checkbox-itemdata-state, data-highlighted, data-disabledA checkbox item. data-state is checked, unchecked or indeterminate.
drawer-menu-radio-itemdata-state, data-highlighted, data-disabledA radio item.
drawer-menu-item-indicatordata-stateThe 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-labeldata-insetA label for the items after it.
drawer-menu-separator—A line between groups.
drawer-menu-sub-triggerdata-state, data-highlighted, data-insetThe item that opens a submenu. data-state is open while its submenu is.
drawer-menu-sub-contentdata-state, data-motionA 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-backdata-highlightedThe 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.

KeyAction
ArrowDownMoves focus to the next item.
ArrowUpMoves focus to the previous item.
HomeMoves focus to the first item.
EndMoves focus to the last item.
EnterChooses the focused item, or opens its submenu.
SpaceChooses the focused item, or opens its submenu.
ArrowRightOpens the focused submenu (ArrowLeft in right-to-left text).
ArrowLeftGoes back from a submenu (ArrowRight in right-to-left text), unless focus is in a text field.
BackspaceGoes back from a submenu, unless focus is in a text field.
EscapeGoes back from a submenu; at the top level closes the drawer.

Changelog

  1. registry 0.22.0

    36aba2b — DrawerMenu as-child makes the child the menu root: the child gets the root's attributes (data-slot, classes, dir, the height variable and the back keys), its own content becomes the root panel, and the submenu panels render inside it. Before, the attributes landed on the root panel and the submenus sat outside the child.

  2. core 0.16.0

    36aba2b — DrawerMenu as-child makes the child the menu root: the child gets the root's attributes (data-slot, classes, dir, the height variable and the back keys), its own content becomes the root panel, and the submenu panels render inside it. Before, the attributes landed on the root panel and the submenus sat outside the child.

  3. registry 0.21.0

    02e469f — MenuItem, MenubarItem and DrawerMenuItem take color instead of variant: variant="destructive" becomes color="destructive", and every other tone (primary, neutral, success, warning, info or one you declare on [data-slot][data-color="<name>"]) now works too. The item, its icon and its hover layer read --tone-text; data-variant is gone from the item and data-color carries the colour.

  4. registry 0.19.0

    adf96cd — Parts no longer style themselves from their root's size through group-data-[size=…] variants, which beat any plain class of yours. size is the density of the root, and a class on a part wins:

    - Card, Empty, Alert and Stepper: CardTitle, CardDescription, EmptyTitle, EmptyDescription, AlertTitle, AlertDescription, StepperTitle and StepperDescription keep one text size at every root size (title-md/body-md, title-sm/body-md for Alert, title-sm/body-sm for Stepper). Empty's icon and gaps and Stepper's indicator number still follow the size, through --empty-icon, --empty-header-gap, --empty-content-gap and --stepper-text on the root. - Menu and DrawerMenu labels, Menubar triggers and the Calendar heading, weekday cells and week numbers keep scaling with the size, through --menu-label, --menubar-text, --calendar-heading and --calendar-label (each with a -leading twin) set by the root. - AlertDialog size="sm" centres its text through the content, so text-start on AlertDialogHeader wins; the footer keeps its two-column grid.

  5. core 0.12.0

    d675257 — A DrawerMenu panel that leaves now waits for any animation or transition running on it, not only for a keyframe animation, so the slide between panels can be replaced with plain CSS: keyframes on data-motion, or a transition on data-state with @starting-style for the arriving panel. A transition used to be cut short: the panel hid at once when animation-name was none.

  6. registry 0.15.0

    d09f26a — Pressable parts ripple on their own: Button, Toggle, ToggleGroupItem, Item as a link or a button, the calendar days, tabs, accordion, menubar and navigation menu triggers, the items of Menu, Menubar, Select, Combobox, Command, DrawerMenu, Listbox and Tree, and the clear buttons of TagsInput and Combobox. Each imports the directive from @/lib/ripple, so add brings the ripple item along and nothing needs registering. On menu, listbox and tree rows the wave replaces the pressed layer, as state-layer already did. Bind v-ripple="false" on a Button to turn one off, or set --kappa-ripple: none on :root to turn them all off.

  7. registry 0.13.0

    93e57a0 — Every size on the control scale is named xs to xl; default and the bare icon are gone. To move over:

    - Button: size="default" becomes size="md", or leave size out; size="icon" becomes size="icon-md". The full set is xs to xl and icon-xs to icon-xl. Toggle, ToggleGroup, ToggleGroupItem, the Toolbar parts, AlertDialogAction, AlertDialogCancel and ToastAction take the same names; Button, Toggle and ToggleGroup default to md, the Toolbar parts keep sm and ToastAction keeps xs. InputGroupButton keeps its own xs, sm, icon-xs and icon-sm, 24 and 32px to fit inside the group, xs by default. Pagination hands its md to Button as it is. Button, Toggle and ToggleGroupItem set data-variant, data-color and data-size even when you leave them at their defaults. - AlertDialogContent: size="default" becomes size="md", still the default; sm is unchanged. The size option of useConfirm's confirm, alert and prompt takes the same names. - Table and DataTable: density becomes size, data-density becomes data-size, and the TableDensity type is now TableSize. sm, md and lg keep their 36, 44 and 52px rows; xs (28px) and xl (60px) are new, and DataTable's virtual row estimates cover them. The cells' padding above and below the text is now --table-cell-py on the table: 8px as before, 3px at xs. At xs, DataTable's sort buttons and expand and group toggles shrink to fit the row. The table-density example is now table-sizes. - DrawerMenu: size takes xs to xl like Menu and reads the control scale, plus room for a thumb. sm, md and lg keep their 40, 48 and 56px rows, padding and icons; xs is 36px and xl 64px. Overriding a --control-* token on :root now resizes DrawerMenu rows as well. - Select and Combobox: the list opens at the trigger's or anchor's size instead of always at md, so <SelectTrigger size="xl"> opens an xl list. size on SelectContent or ComboboxList picks another. Behind an as-child button, set size on ComboboxAnchor to match the button. The Select list now sets its menu variables on SelectContent instead of its viewport, so a class such as [--menu-item-height:2.5rem] on SelectContent reaches the items. - Input, Textarea, InputFloating, SelectTrigger, ComboboxAnchor and Separator set data-size with the default filled in, and the anchor sets data-variant too. With as-child, the anchor leaves the button's own data-variant and data-size alone.

  8. registry 0.10.0

    0a9aa94 — DropdownMenu and ContextMenu are removed: Menu covers both, opening on click from the element it sits in or from a MenuTrigger, and with context-menu on right-click and long-press. It has the same parts (MenuItem, MenuCheckboxItem, MenuRadioGroup, MenuRadioItem, MenuLabel, MenuSeparator, MenuShortcut, MenuGroup, MenuSub, MenuSubTrigger, MenuSubContent), sizes and styles, so moving over means renaming the parts and replacing DropdownMenuTrigger/ContextMenuTrigger and the content part with a Menu inside the element that opens it; align="end" becomes anchor="bottom end" self="top end". Copies already in a project keep working. The Breadcrumb, ButtonGroup, DrawerMenu and overlay examples use Menu.

  9. registry 0.9.0

    74f9dd1 — New DrawerMenu: a menu inside a drawer for touch screens, with DrawerMenuItem, DrawerMenuCheckboxItem, DrawerMenuRadioGroup, DrawerMenuRadioItem, DrawerMenuGroup, DrawerMenuLabel, DrawerMenuSeparator and submenus (DrawerMenuSub, DrawerMenuSubTrigger, DrawerMenuSubContent) that drill down in the same sheet with a back row, in sm, md and lg. Its parts take the props and events of the dropdown and context menu parts, so one menu definition renders through any of the three.

  10. core 0.8.0

    f4a4e02 — @kappa-ui/core/drawer-menu: a menu that lives inside a drawer. DrawerMenu holds panels with role="menu" and roving focus; DrawerMenuItem, DrawerMenuCheckboxItem, DrawerMenuRadioGroup, DrawerMenuRadioItem, DrawerMenuItemIndicator, DrawerMenuGroup, DrawerMenuLabel and DrawerMenuSeparator take the props and events of Reka UI's menu parts, so a select closes the drawer unless prevented. DrawerMenuSub, DrawerMenuSubTrigger and DrawerMenuSubContent drill down in the same sheet, with DrawerMenuBack at the top of a sub panel; ArrowLeft, Backspace and Escape go back. tailwind.css adds the drawer-menu utility, which slides between panels and follows the visible panel's height.

    8f50769 — DrawerMenuBack follows its DrawerMenuSubTrigger's text when that text changes while the submenu is open, such as a live count in the label. Before, it kept the text from when the submenu opened.