Dropdown Menu
A menu of actions or options, triggered by a button.
Installation
Shadwire follows shadcn/ui's open code model: the component's source is copied into your application and becomes yours. Install it with the CLI:
The dropdown-menu registry item installs these files:
-
app/components/ui_component.rb -
app/components/ui/dropdown_menu_component.rb -
app/components/ui/dropdown_menu/trigger_component.rb -
app/components/ui/dropdown_menu/content_component.rb -
app/components/ui/dropdown_menu/item_component.rb -
app/components/ui/dropdown_menu/label_component.rb -
app/components/ui/dropdown_menu/separator_component.rb -
app/components/ui/dropdown_menu/group_component.rb -
app/components/ui/dropdown_menu/shortcut_component.rb -
app/components/ui/button_component.rb -
app/helpers/ui/dropdown_menu_helper.rb -
app/helpers/ui/button_helper.rb -
app/javascript/controllers/ui_dropdown_menu_controller.js -
vendor/shadwire/shadwire.css
This component uses Stimulus, so the application needs importmap-rails and stimulus-rails with automatic controller loading.
Haven't installed the CLI yet? gem install shadwire, then shadwire init.
Usage
The ui-dropdown-menu controller
implements the WAI-ARIA menu pattern: roving focus across the items,
↑/↓ with wrapping,
Home/End,
typeahead matching, and closing with
Esc, Tab, or a click outside.
Or render the components directly:
Composition
Examples
API reference
Every part accepts class /
class_name and
**attrs.
| Component | Argument | Default | Description |
|---|---|---|---|
DropdownMenu::Trigger |
variant, size |
:outline, :default |
Passed to the Ui::ButtonComponent it renders. |
DropdownMenu::Content |
side, align |
:bottom, :start |
Menu positioning, through utilities. |
DropdownMenu::Item |
variant |
:default |
:destructive marks dangerous actions. |
DropdownMenu::Item |
inset, disabled |
false |
Indents to line up with icons; a disabled item is skipped during navigation. |
DropdownMenu::Item |
tag |
:button |
Use :a with href for link items. |