Dropdown
A contextual menu with checkbox items, links, placement options, and htmx integration.
<rhx-dropdown>
Examples
Basic Dropdown
<rhx-dropdown>
<rhx-dropdown-trigger>
<rhx-button rhx-variant="neutral" rhx-appearance="outlined">
Actions ▾
</rhx-button>
</rhx-dropdown-trigger>
<rhx-dropdown-item>Edit</rhx-dropdown-item>
<rhx-dropdown-item>Duplicate</rhx-dropdown-item>
<rhx-dropdown-divider />
<rhx-dropdown-item>Archive</rhx-dropdown-item>
<rhx-dropdown-item rhx-disabled="true">Delete</rhx-dropdown-item>
</rhx-dropdown>
Placements
<rhx-dropdown rhx-placement="bottom-start">
<rhx-dropdown-trigger>
<rhx-button rhx-variant="brand">Bottom Start ▾</rhx-button>
</rhx-dropdown-trigger>
<rhx-dropdown-item>Item A</rhx-dropdown-item>
<rhx-dropdown-item>Item B</rhx-dropdown-item>
</rhx-dropdown>
<rhx-dropdown rhx-placement="bottom-end">
<rhx-dropdown-trigger>
<rhx-button rhx-variant="brand">Bottom End ▾</rhx-button>
</rhx-dropdown-trigger>
<rhx-dropdown-item>Item A</rhx-dropdown-item>
<rhx-dropdown-item>Item B</rhx-dropdown-item>
</rhx-dropdown>
<rhx-dropdown rhx-placement="top-start">
<rhx-dropdown-trigger>
<rhx-button rhx-variant="brand">Top Start ▴</rhx-button>
</rhx-dropdown-trigger>
<rhx-dropdown-item>Item A</rhx-dropdown-item>
<rhx-dropdown-item>Item B</rhx-dropdown-item>
</rhx-dropdown>
Checkbox Items
<rhx-dropdown rhx-stay-open="true">
<rhx-dropdown-trigger>
<rhx-button rhx-variant="neutral" rhx-appearance="outlined">
Columns ▾
</rhx-button>
</rhx-dropdown-trigger>
<rhx-dropdown-item rhx-type="checkbox" rhx-checked="true" rhx-value="name">
Name
</rhx-dropdown-item>
<rhx-dropdown-item rhx-type="checkbox" rhx-checked="true" rhx-value="email">
Email
</rhx-dropdown-item>
<rhx-dropdown-item rhx-type="checkbox" rhx-value="phone">
Phone
</rhx-dropdown-item>
<rhx-dropdown-item rhx-type="checkbox" rhx-value="role">
Role
</rhx-dropdown-item>
</rhx-dropdown>
Link Items
<rhx-dropdown>
<rhx-dropdown-trigger>
<rhx-button rhx-variant="neutral" rhx-appearance="outlined">
Navigate ▾
</rhx-button>
</rhx-dropdown-trigger>
<rhx-dropdown-item rhx-href="/">Home</rhx-dropdown-item>
<rhx-dropdown-item rhx-href="/Docs/Components/Dropdowns">Dropdowns</rhx-dropdown-item>
<rhx-dropdown-divider />
<rhx-dropdown-item rhx-href="/Error">Error Page</rhx-dropdown-item>
</rhx-dropdown>
htmx Integration
<rhx-dropdown>
<rhx-dropdown-trigger>
<rhx-button rhx-variant="brand" rhx-appearance="outlined">
Actions ▾
</rhx-button>
</rhx-dropdown-trigger>
<rhx-dropdown-item hx-post="/Docs/Components/Dropdowns?handler=Edit"
hx-target="#dropdown-result" hx-swap="innerHTML">
Edit Item
</rhx-dropdown-item>
<rhx-dropdown-item hx-post="/Docs/Components/Dropdowns?handler=Duplicate"
hx-target="#dropdown-result" hx-swap="innerHTML">
Duplicate Item
</rhx-dropdown-item>
<rhx-dropdown-divider />
<rhx-dropdown-item hx-delete="/Docs/Components/Dropdowns?handler=Remove"
hx-target="#dropdown-result" hx-swap="innerHTML"
hx-confirm="Are you sure?">
Delete Item
</rhx-dropdown-item>
</rhx-dropdown>
<span id="dropdown-result">Select an action...</span>
States
<rhx-dropdown rhx-disabled="true">
<rhx-dropdown-trigger>
<rhx-button rhx-variant="neutral" rhx-appearance="outlined"
rhx-disabled="true">
Disabled ▾
</rhx-button>
</rhx-dropdown-trigger>
<rhx-dropdown-item>Unreachable</rhx-dropdown-item>
</rhx-dropdown>
<rhx-dropdown rhx-open="true">
<rhx-dropdown-trigger>
<rhx-button rhx-variant="success" rhx-appearance="outlined">
Open ▾
</rhx-button>
</rhx-dropdown-trigger>
<rhx-dropdown-item>Already visible</rhx-dropdown-item>
<rhx-dropdown-item>Second item</rhx-dropdown-item>
</rhx-dropdown>
Properties
| Property | Type | Default | Description |
|---|---|---|---|
rhx-open |
bool |
false |
Whether the dropdown is initially open |
rhx-placement |
string |
bottom-start |
Menu position: bottom-start, bottom-end, top-start, top-end |
rhx-disabled |
bool |
false |
Disables the dropdown trigger |
rhx-stay-open |
bool |
false |
Keep menu open after item selection (useful for checkboxes) |
aria-label |
string |
- |
Accessible label for the dropdown menu |
Item Properties
Properties for <rhx-dropdown-item> elements.
Properties
| Property | Type | Default | Description |
|---|---|---|---|
rhx-type |
string |
normal |
Item type: normal, checkbox |
rhx-checked |
bool |
false |
Checked state for checkbox items |
rhx-value |
string |
- |
Value associated with the item |
rhx-disabled |
bool |
false |
Disables the item |
rhx-href |
string |
- |
Renders the item as a navigation link |
aria-label |
string |
- |
Accessible label for the item |
Accessibility
- The trigger button receives
aria-haspopup="true"andaria-expandedreflecting menu state. - The menu uses
role="menu"with items usingrole="menuitem"orrole="menuitemcheckbox". - Arrow keys navigate between items; Enter or Space activates the focused item.
- Escape closes the menu and returns focus to the trigger.
- Disabled items receive
aria-disabled="true"and are skipped during keyboard navigation. - Link items render as
<a>elements withrole="menuitem".