Menu

A native action menu with a visible menu button, optional external native trigger, context-surface support, named groups and separators. Its top-layer positioning and nested-overlay lifecycle reuse the same controller as popovers and tooltips.

Usage

<script type="module" src="/assets/components/menu/qds-menu.js"></script>
<qds-menu id="actions" label="Document actions"></qds-menu>
<script>
  customElements.whenDefined('qds-menu').then(() => {
    document.querySelector('#actions').items = [
      { type: 'group', label: 'Review', items: [
        { id: 'archive', label: 'Archive document' },
        { id: 'publish', label: 'Publish (unavailable)', disabled: true }
      ] },
      { type: 'separator' },
      { id: 'open', label: 'Open document review' }
    ];
  });
</script>

API

Property / attribute Default Meaning
items property [] Item, group or separator data. Item: id, label, optional disabled. Group: type group, label, items. Separator: type separator.
label Actions Visible built-in trigger label and default menu name.
menu-label label Optional distinct accessible menu name.
anchor property / for attribute built-in button External native menu button or its ID. Changing it restores the previous trigger’s ARIA.
contextTarget property / context-for attribute absent Optional context surface. Its ordinary menu button remains available for touch and discoverability.
open false Requested visibility; opening moves focus into the menu.
controlled false Visibility requests are emitted; the application sets open.
disabled false Prevent opening and close the current menu. The internal trigger is disabled; external triggers receive aria-disabled.
placement bottom-start bottom-start/end or top-start/end; viewport collision and RTL are handled.

Use real native interactive elements for external triggers. Set type=button; trigger activation also prevents accidental form submission. A context surface should be named and keyboard focusable (for example, an article with tabindex=0). Set target properties after mounting when dynamically creating external nodes.

Invalid/blank item records are omitted; first unique nonblank ID wins across groups. Input/output records are copied, including group children. Labels are literal text. No nested submenu, URL navigation or downloaded icon runtime is implied; perform application actions through qds-select.

Events and state

Methods: show(), hide(), showAt(x, y), requestOpen(open, reason), reposition(), focus(). showAt uses viewport coordinates and retains a real context/trigger anchor for removal tracking. Empty menus do not open; menus with disabled actions still explain those actions. Data updates retain the focused item identity or focus the first remaining item. Disconnect closes and resets open, removes listeners and restores external-trigger ARIA; reconnect starts closed.

Calling show() or showAt() while open can switch between the ordinary anchor and context coordinates without losing popup visibility. A repeated showAt() updates the point; Escape returns focus to the current invocation surface.

Keyboard and focus

Follow the APG menu button and menu patterns. Parts: trigger, menu, item, group, separator. Both themes, focus outlines, 44px action targets, long text, viewport clamping and forced colors use existing QDS tokens.

Quangular business use

Northwind Documents > Document library presents the committee review document at /#/documents. The generated QdsMenuComponent provides a normal action button and context actions on the review card. Archive changes that document’s status in the card and table; Restore for review reverses the local change. Open document review navigates to its existing detail route. Data is fictional and changes reset when leaving the screen; no real document is archived or transmitted.