Search documentation

Find a component or a docs page

Dropdown Menu

Displays a menu to the user — such as a set of actions or functions — triggered by a button.

Usage

Basic

Click the button, or focus it and press Enter, Space, ArrowDown or ArrowUp: the menu opens and takes focus. Arrow keys, Home/End and typing a letter move through the items; Enter or Space picks one; Esc closes it and focus goes back to the button; Tab closes it and moves on to the next control, Shift+Tab stops on the button. While it is open the page behind is inert and doesn't scroll.

With shortcuts

DropdownMenuShortcut shows the key combination. It only displays the keys: binding them is up to you.

Checkboxes

DropdownMenuCheckboxItem toggles aria-checked and keeps the menu open. Listen to ruby-ui--dropdown-menu:change; event.detail.checked has the new state.

Radio group

DropdownMenuRadioItems in a DropdownMenuRadioGroup: checking one unchecks the rest. In ruby-ui--dropdown-menu:change, event.detail.value carries the item's value: argument.

Destructive

variant: :destructive marks an item that deletes or can't be undone.

Inset

inset: indents an item or label (pl-8), e.g. to line it up with items that show an indicator.

Opening a dialog

An item can host its own interactive element, such as a DialogTrigger. Picking it opens the dialog and closes the menu.

Side and align

side: (top, right, bottom, left) and align: (start, center, end) place the menu next to the button; side_offset: and align_offset: set the gap. The defaults are bottom, start, 4 and 0. The menu flips and shifts to stay on screen, and is as wide as the button (at least 8rem).

Non-modal

modal: false leaves the page scrollable and usable while the menu is open; a click outside still closes it.

Installation

Components

ComponentBuilt usingSource
DropdownMenuPhlex
DropdownMenuCheckboxItemPhlex
DropdownMenuContentPhlex
DropdownMenuDocsPhlex
DropdownMenuGroupPhlex
DropdownMenuItemPhlex
DropdownMenuItemIndicatorPhlex
DropdownMenuLabelPhlex
DropdownMenuRadioGroupPhlex
DropdownMenuRadioItemPhlex
DropdownMenuSeparatorPhlex
DropdownMenuShortcutPhlex
DropdownMenuSubPhlex
DropdownMenuSubContentPhlex
DropdownMenuSubTriggerPhlex
DropdownMenuTriggerPhlex
DropdownMenuControllerStimulus JS