Dropdown Menu

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

Anatomy

DropdownMenu do |d|
d.trigger
d.content do
d.label
d.separator
d.group do
d.item
d.item
d.sub do |sub|
sub.trigger
sub.content do
d.item
d.item
end
end
end
end
end

API Reference

DropdownMenu

NameTypeDefault
open:booleanfalse
Controls the initial open state of the dropdown menu. When true, the menu will be visible on render.
attributeskeyword arguments

DropdownMenu#trigger

NameTypeDefault
as_child:booleanfalse
When true, merges the trigger functionality with the child element instead of creating a wrapper div.
attributeskeyword arguments

DropdownMenu#content

The container for the dropdown menu items. Positioned relative to the trigger with configurable placement and alignment.

NameTypeDefault
side:symbol:bottom
Controls which side of the trigger the content appears on. :top | :left | :bottom | :right
align:symbol:center
Controls the alignment of the content relative to the trigger. :start | :center | :end
attributeskeyword arguments

DropdownMenu#label

NameType
attributeskeyword arguments

DropdownMenu#item

NameTypeDefault
variant:symbol:default
Visual style variant for the item. :default | :destructive
as_child:booleanfalse
When true, merges the item functionality with the child element instead of creating a wrapper div.
disabled:booleanfalse
When true, the item is visually disabled and cannot be selected or focused.
attributeskeyword arguments

DropdownMenu#item_to

A Rails-integrated menu item that wraps button_to for form submissions. Inherits all button_to functionality while maintaining dropdown styling.

NameTypeDefault
namestringnil
The text content of the button (first argument to button_to).
optionshashnil
URL or path options passed to button_to (second argument).
html_optionshashnil
HTML attributes and options passed to button_to. Also supports variant: and disabled: options.

DropdownMenu#separator

A visual separator line between menu items. Includes proper ARIA attributes for accessibility.

NameType
attributeskeyword arguments

DropdownMenu#group

A semantic grouping container for related menu items. Provides proper ARIA role for screen readers.

NameType
attributeskeyword arguments

DropdownMenu#sub

Creates a nested submenu within the dropdown. Generates unique ARIA IDs for proper accessibility relationships.

NameTypeDefault
sub_triggermethod
Use sub_trigger method to create the trigger for opening the submenu.
sub_contentmethod
Use sub_content method to create the submenu content container.
attributeskeyword arguments

DropdownMenuSub#trigger

The trigger element for opening a submenu. Only available within a sub block. Handles submenu-specific keyboard interactions.

NameTypeDefault
as_child:booleanfalse
When true, merges the trigger functionality with the child element instead of creating a wrapper div.
attributeskeyword arguments

DropdownMenuSub#content

The container for submenu items. Only available within a sub block. Positioned relative to the sub trigger with automatic collision detection.

NameTypeDefault
side:symbol:right
Controls which side of the sub trigger the content appears on. :top | :left | :bottom | :right
align:symbol:start
Controls the alignment of the submenu content relative to the trigger. :start | :center | :end
attributeskeyword arguments

Keyboard Interactions

KeyDescription
SpaceWhen focus is on trigger, opens the dropdown menu and focuses the first item. When focus is on an item, activates the focused item.
EnterWhen focus is on trigger, opens the dropdown menu and focuses the first item. When focus is on an item, activates the focused item.
ArrowDownWhen focus is on trigger, opens the dropdown menu. When focus is on an item, moves focus to the next item.
ArrowUpWhen focus is on an item, moves focus to the previous item.
EscCloses the dropdown menu and moves focus to trigger.

Examples