Skip to content

Dropdown Menu

The bq-dropdown-menu component is a trigger-activated overlay for actions or navigation links. It follows the WAI-ARIA Menu pattern with full keyboard navigation.

Basic Usage

html
<bq-dropdown-menu label="Actions">
  <button slot="trigger">Options ▾</button>
  <button data-value="edit">Edit</button>
  <button data-value="duplicate">Duplicate</button>
  <hr />
  <button data-value="delete">Delete</button>
</bq-dropdown-menu>

Placement

Control where the menu appears relative to the trigger.

html
<bq-dropdown-menu placement="bottom-start">
  <button slot="trigger">Bottom Start ▾</button>
  <button>Item 1</button>
</bq-dropdown-menu>

<bq-dropdown-menu placement="bottom-end">
  <button slot="trigger">Bottom End ▾</button>
  <button>Item 1</button>
</bq-dropdown-menu>

<bq-dropdown-menu placement="top-start">
  <button slot="trigger">Top Start ▴</button>
  <button>Item 1</button>
</bq-dropdown-menu>

<bq-dropdown-menu placement="top-end">
  <button slot="trigger">Top End ▴</button>
  <button>Item 1</button>
</bq-dropdown-menu>
html
<bq-dropdown-menu label="Navigation">
  <button slot="trigger">Go to ▾</button>
  <a href="/dashboard">Dashboard</a>
  <a href="/settings">Settings</a>
  <a href="/profile">Profile</a>
</bq-dropdown-menu>

Disabled

html
<bq-dropdown-menu disabled>
  <button slot="trigger" disabled>Unavailable ▾</button>
  <button>Item 1</button>
</bq-dropdown-menu>

With Separators

Use <hr> elements to visually separate groups of items.

html
<bq-dropdown-menu label="File actions">
  <button slot="trigger">File ▾</button>
  <button data-value="new">New</button>
  <button data-value="open">Open</button>
  <button data-value="save">Save</button>
  <hr />
  <button data-value="export">Export</button>
  <button data-value="print">Print</button>
</bq-dropdown-menu>

Properties

PropertyTypeDefaultDescription
labelstringAccessible label for the menu
placementstringbottom-startbottom-start | bottom-end | top-start | top-end
openbooleanfalseWhether the menu is open
disabledbooleanfalseDisables the dropdown

Events

EventDetailDescription
bq-openFired when the menu opens
bq-closeFired when the menu closes
bq-select{ value: string }Fired when a menu item is activated

The value in bq-select comes from the item's data-value attribute, or falls back to the item's text content.

Slots

SlotDescription
triggerElement that opens the menu
(default)Menu items (<button>, <a>, <hr>)

CSS Parts

PartDescription
triggerThe trigger wrapper
menuThe dropdown menu

Keyboard Navigation

KeyAction
Enter / Space / ArrowDown on triggerOpens the menu and focuses the first item
ArrowDownMoves focus to the next item
ArrowUpMoves focus to the previous item
HomeMoves focus to the first item
EndMoves focus to the last item
EscapeCloses the menu and returns focus to the trigger
TabCloses the menu and moves focus according to the browser's tab order (does not return focus to the trigger)
Printable charactersTypeahead focuses the next matching enabled item by label

Accessibility

  • Menu container has role="menu" with optional aria-label
  • Trigger slot has aria-haspopup="menu" and aria-expanded
  • Trigger has aria-controls pointing to the menu's unique id
  • Focus is managed: opening moves focus to first item; closing via Escape, outside click, or item selection returns focus to the trigger, while Tab closes the menu without restoring focus
  • Click-outside closes the menu
  • Disabled items are skipped during keyboard navigation
  • Typeahead matching uses the item label or data-value text, which helps large menus stay efficient without custom scripting

Localization

The following i18n keys are available for use with the dropdown menu:

KeyDefaultUsage
dropdownMenu.open"Open menu"Can be used as trigger label
dropdownMenu.close"Close menu"Can be used programmatically

Released under the MIT License.