Components ds-dropdown
Dropdown
Menu button: a trigger that opens a menu of actions below it. The arrow keys move between the items, and choosing one, Escape, Tab or a press outside closes the menu.
Live playground
events: none yet
Interactive props
Usage example
<ds-dropdown @ds-close=${onClose}>
<button slot="trigger">Account</button>
<button role="menuitem" @click=${openProfile}>Profile</button>
<button role="menuitem" aria-disabled="true">Billing</button>
<a role="menuitem" href="/sign-out">Sign out</a>
</ds-dropdown>
<!-- An icon trigger needs a label; the menu is named after it. -->
<ds-dropdown align="end">
<button slot="trigger" aria-label="More actions">⋯</button>
…
</ds-dropdown>
Keyboard
| Key | Result |
|---|---|
| Enter / Space / Arrow Down | On the trigger: opens the menu on its first item. |
| Arrow Up | On the trigger: opens the menu on its last item. |
| Arrow Down / Up | In the menu: moves between items, wrapping at the ends. |
| Home / End | In the menu: moves to the first or last item. |
| Escape | Closes the menu and returns focus to the trigger. |
| Tab | Closes the menu and moves on. |
API Reference
| Member | Kind | Description |
|---|---|---|
| open | property | Whether the menu is open. Reflects to an attribute. |
| align | property | Which edge of the trigger the menu lines up with: start (the default) or end. |
| show() | method | Opens the menu and focuses its first item. |
| close() | method | Closes the menu and leaves focus where it is. |
| ds-open / ds-close | event | The menu opened or closed. |
| trigger | slot | The button that opens the menu. |
| (default) | slot | Items with role="menuitem", usually buttons or links. |
| menu | part | The menu surface, for style overrides. |