Menu

import {Menu} from "@qualcomm-ui/react/menu"

Examples

Item Customization

Compose the menu to include icons and commands.

Context Menu

Demonstrates how to trigger a menu on right-click or other context events.

Nested Menus

Compose nested menus by nesting <Menu.Root> components inside each other.

<q-menu>
  <button emphasis="primary" q-menu-button variant="fill">Show Menu</button>
  <q-portal>
    <div q-menu-positioner>
      <div q-menu-content>
        <button q-menu-item value="new-text-file">New Text File</button>
        <button q-menu-item value="new-file">New File...</button>
        <q-menu>
          <button q-menu-trigger-item value="open-recent">
            Open Recents
          </button>

          <q-portal>
            <div q-menu-positioner>
              <div q-menu-content>
                <button q-menu-item value="file-1">File 1</button>
                <button q-menu-item value="file-2">File 2</button>
                <button q-menu-item value="file-3">File 3</button>
              </div>
            </div>
          </q-portal>
        </q-menu>
      </div>
    </div>
  </q-portal>
</q-menu>

Menu items can be links.

<div q-menu-content>
  <a
    href="https://angular.dev"
    q-menu-item
    target="_blank"
    value="angular-dev"
  >
    <div icon="ExternalLink" q-menu-item-start-icon></div>
    angular.dev
  </a>
  <a
    fragment="links"
    q-menu-item
    routerLink="/components/menu"
    value="menu-links-demo"
  >
    Menu Links Demo
  </a>
</div>

Groups

Use the q-menu-item-group component to group menu items.

Item Types

There are three item types, each corresponding to one of the three types of aria menu item roles:

  • q-menu-itemmenuitem
  • q-menu-radio-itemmenuitemradio
  • q-menu-checkbox-itemmenuitemcheckbox

Checkbox Items

Use checkbox items when you need options that are individually selectable.

Checkbox Group State

Checkbox item state is controlled individually on each item. Use the useCheckboxGroup hook to manage the state of a group of checkbox items.

<div q-menu-item-group>
  <label q-menu-item-group-label>Choose an option</label>
  @for (item of items; track item.value) {
    <button
      q-menu-checkbox-item
      [checked]="checkboxGroup.isChecked(item.value)"
      [value]="item.value"
      (checkedChanged)="checkboxGroup.toggleValue(item.value)"
    >
      {{ item.label }}
      <div q-menu-item-indicator></div>
    </button>
  }
</div>

Radio Group

Radio items are grouped such that only one can be selected at a time.

<div q-menu-radio-item-group>
  <label q-menu-item-group-label>Choose an option</label>
  <div q-menu-radio-item-group>
    <button q-menu-radio-item value="option-1">
      Option 1
      <div q-menu-item-indicator></div>
    </button>
    <button q-menu-radio-item value="option-2">
      Option 2
      <div q-menu-item-indicator></div>
    </button>
    <button q-menu-radio-item value="option-3">
      Option 3
      <div q-menu-item-indicator></div>
    </button>
  </div>
</div>

Radio Group State

Radio item state can be controlled via the value property on the parent menu-radio-item-group element.

<div q-menu-radio-item-group>
  <label q-menu-item-group-label>Choose an option</label>
  <div q-menu-radio-item-group [(value)]="value">
    <button q-menu-radio-item value="option-1">
      Option 1
      <div q-menu-item-indicator></div>
    </button>
    <button q-menu-radio-item value="option-2">
      Option 2
      <div q-menu-item-indicator></div>
    </button>
    <button q-menu-radio-item value="option-3">
      Option 3
      <div q-menu-item-indicator></div>
    </button>
  </div>
</div>

Controlled State

The menu's visibility can be controlled via the open, openChange, and defaultOpen properties.

  • Use open to explicitly set whether the menu is open (controlled mode).
  • Use openChanged to be notified when the menu requests to open or close.
  • Use defaultOpen to set the initial open state when you don't need to control it yourself (uncontrolled mode).

In controlled mode, the open prop should be updated in response to openChanged events to reflect the desired visibility.

Placement

Configure the menu's placement using the positioning.placement prop.

Anchor Point

Use the positioning.anchorPoint prop to control the anchor point of the menu.

Anchor

Avatar

Here's an example that composes the Menu with the Avatar component to display a user account menu.

TODO: add

Within Dialog

When using the Menu inside a Dialog, don't render the q-menu-positioner within a <q-portal> element.

Hide When Detached

Use the positioning.hideWhenDetached prop to hide the menu when it's detached from the trigger.

Item 0
Item 1
Item 2
Item 3
Item 4
Item 5

API

<q-menu>

PropTypeDefault
The positioning point for the menu. Can be set by the context menu trigger or the button trigger.
{
x: number
y: number
}
Whether to close the menu when an option is selected
boolean
true
Whether the menu is composed with other composite widgets like a combobox or tabs
boolean
true
The initial highlighted value of the menu item when rendered. Use when you don't need to control the highlighted value of the menu item.
string
The initial open state of the menu when rendered. Use when you don't need to control the open state of the menu.
boolean
The document's text/writing direction.
'ltr' | 'rtl'
"ltr"
A root node to correctly resolve the Document in custom environments. i.e., Iframes, Electron.
() =>
| Node
| ShadowRoot
| Document
The controlled highlighted value of the menu item.
string
id attribute. If omitted, a unique identifier will be generated for accessibility.)
string
Whether to synchronize the present change immediately or defer it to the next frame.
boolean
false
When true, the component will not be rendered in the DOM until it becomes visible or active.
boolean
false
Whether to loop the keyboard navigation.
boolean
false
The controlled open state of the menu
boolean
The options used to dynamically position the menu
The controlled presence of the node.
boolean
'sm' | 'md'
Whether to allow the initial presence animation.
boolean
false
Whether the pressing printable characters should trigger typeahead navigation
boolean
true
When true, the component will be completely removed from the DOM when it becomes inactive or hidden, rather than just being hidden with CSS.
boolean
false
Function called when the escape key is pressed
KeyboardEvent
Function called when the animation ends in the closed state
void
Function called when the focus is moved outside the component
CustomEvent<{
event?: E
}>
Function called when the highlighted menu item changes.
string
Function called when an interaction happens outside the component
| CustomEvent<{event?: E}>
| CustomEvent<{event?: E}>
Function to navigate to the selected item if it's an anchor element
{
href: string
node: HTMLAnchorElement
value: string
}
Function called when the open state changes
boolean
Function called when the pointer is pressed down outside the component
CustomEvent<{
event?: E
}>
Function called when this layer is closed due to a parent layer being closed
CustomEvent<{
originalIndex: number
originalLayer: HTMLElement
targetIndex: number
targetLayer: HTMLElement
}>
Function called when a menu item is selected.
string
Type
{
x: number
y: number
}
Description
The positioning point for the menu. Can be set by the context menu trigger or the button trigger.
Type
boolean
Description
Whether to close the menu when an option is selected
Type
boolean
Description
Whether the menu is composed with other composite widgets like a combobox or tabs
Type
string
Description
The initial highlighted value of the menu item when rendered. Use when you don't need to control the highlighted value of the menu item.
Type
boolean
Description
The initial open state of the menu when rendered. Use when you don't need to control the open state of the menu.
Type
'ltr' | 'rtl'
Description
The document's text/writing direction.
Type
() =>
| Node
| ShadowRoot
| Document
Description
A root node to correctly resolve the Document in custom environments. i.e., Iframes, Electron.
Type
string
Description
The controlled highlighted value of the menu item.
Type
string
Description
id attribute. If omitted, a unique identifier will be generated for accessibility.)
Type
boolean
Description
Whether to synchronize the present change immediately or defer it to the next frame.
Type
boolean
Description
When true, the component will not be rendered in the DOM until it becomes visible or active.
Type
boolean
Description
Whether to loop the keyboard navigation.
Type
boolean
Description
The controlled open state of the menu
Description
The options used to dynamically position the menu
Type
boolean
Description
The controlled presence of the node.
Type
'sm' | 'md'
Type
boolean
Description
Whether to allow the initial presence animation.
Type
boolean
Description
Whether the pressing printable characters should trigger typeahead navigation
Type
boolean
Description
When true, the component will be completely removed from the DOM when it becomes inactive or hidden, rather than just being hidden with CSS.
Type
KeyboardEvent
Description
Function called when the escape key is pressed
Type
void
Description
Function called when the animation ends in the closed state
Type
CustomEvent<{
event?: E
}>
Description
Function called when the focus is moved outside the component
Type
string
Description
Function called when the highlighted menu item changes.
Type
| CustomEvent<{event?: E}>
| CustomEvent<{event?: E}>
Description
Function called when an interaction happens outside the component
Type
{
href: string
node: HTMLAnchorElement
value: string
}
Description
Function to navigate to the selected item if it's an anchor element
Type
boolean
Description
Function called when the open state changes
Type
CustomEvent<{
event?: E
}>
Description
Function called when the pointer is pressed down outside the component
Type
CustomEvent<{
originalIndex: number
originalLayer: HTMLElement
targetIndex: number
targetLayer: HTMLElement
}>
Description
Function called when this layer is closed due to a parent layer being closed
Type
string
Description
Function called when a menu item is selected.

q-menu-item

Each menu item type shares the same base properties.
PropType
The unique value of the menu item option.
string
Whether the menu should be closed when the option is selected.
boolean
Whether the menu item is disabled
boolean
The textual value of the option. Used in typeahead navigation of the menu. If not provided, the text content of the menu item will be used.
string
Emitted when the item is selected
void
Type
string
Description
The unique value of the menu item option.
Type
boolean
Description
Whether the menu should be closed when the option is selected.
Type
boolean
Description
Whether the menu item is disabled
Type
string
Description
The textual value of the option. Used in typeahead navigation of the menu. If not provided, the text content of the menu item will be used.
Type
void
Description
Emitted when the item is selected

q-menu-checkbox-item

Each menu item type shares the same base properties.
PropType
The unique value of the menu item option.
string
Whether the option is checked
boolean
Whether the menu should be closed when the option is selected.
boolean
boolean
Whether the menu item is disabled
boolean
The textual value of the option. Used in typeahead navigation of the menu. If not provided, the text content of the menu item will be used.
string
boolean
Emitted when the item is selected
void
Type
string
Description
The unique value of the menu item option.
Type
boolean
Description
Whether the option is checked
Type
boolean
Description
Whether the menu should be closed when the option is selected.
Type
boolean
Type
boolean
Description
Whether the menu item is disabled
Type
string
Description
The textual value of the option. Used in typeahead navigation of the menu. If not provided, the text content of the menu item will be used.
Type
boolean
Type
void
Description
Emitted when the item is selected

PositioningOptions

The positioning prop accepts an object with the following shape:

PropTypeDefault
The minimum padding between the arrow and the floating element's corner.
number
4
The overflow boundary of the reference element
    () =>
    | 'clippingAncestors'
    | Element
    | Array<Element>
    | {
    height: number
    width: number
    x: number
    y: number
    }
    Whether the popover should fit the viewport.
    boolean
    Whether to flip the placement when the floating element overflows the boundary.
    | boolean
    | Array<
    | 'bottom'
    | 'bottom-end'
    | 'bottom-start'
    | 'left'
    | 'left-end'
    | 'left-start'
    | 'right'
    | 'right-end'
    | 'right-start'
    | 'top'
    | 'top-end'
    | 'top-start'
    >
    true
    
    Function that returns the anchor rect
      (
      element:
      | HTMLElement
      | VirtualElement,
      ) => {
      height?: number
      width?: number
      x?: number
      y?: number
      }
      The main axis offset or gap between the reference and floating element
      number
      8
      
      Whether the popover should be hidden when the reference element is detached
      boolean
      Options to activate auto-update listeners
      | boolean
      | {
      ancestorResize?: boolean
      ancestorScroll?: boolean
      animationFrame?: boolean
      elementResize?: boolean
      layoutShift?: boolean
      }
      true
      
      The offset of the floating element
      {
      crossAxis?: number
      mainAxis?: number
      }
      Function called when the placement is computed
        (
        data: ComputePositionReturn,
        ) => void
        Function called when the floating element is positioned or not
          (data: {
          placed: boolean
          }) => void
          The virtual padding around the viewport edges to check for overflow
          number
          Whether the floating element can overlap the reference element
          boolean
          false
          
          The initial placement of the floating element
          | 'bottom'
          | 'bottom-end'
          | 'bottom-start'
          | 'left'
          | 'left-end'
          | 'left-start'
          | 'right'
          | 'right-end'
          | 'right-start'
          | 'top'
          | 'top-end'
          | 'top-start'
          'bottom'
          
          Whether to make the floating element same width as the reference element
          boolean
          The secondary axis offset or gap between the reference and floating elements
          number
          Whether the popover should slide when it overflows.
          boolean
          The strategy to use for positioning
          | 'absolute'
          | 'fixed'
          'absolute'
          
          A callback that will be called when the popover needs to calculate its position.
            (data: {
            updatePosition: () => Promise<void>
            }) => void | Promise<void>
            Type
            number
            Description
            The minimum padding between the arrow and the floating element's corner.
            Type
            () =>
            | 'clippingAncestors'
            | Element
            | Array<Element>
            | {
            height: number
            width: number
            x: number
            y: number
            }
            Description
            The overflow boundary of the reference element
              Type
              boolean
              Description
              Whether the popover should fit the viewport.
              Type
              | boolean
              | Array<
              | 'bottom'
              | 'bottom-end'
              | 'bottom-start'
              | 'left'
              | 'left-end'
              | 'left-start'
              | 'right'
              | 'right-end'
              | 'right-start'
              | 'top'
              | 'top-end'
              | 'top-start'
              >
              Description
              Whether to flip the placement when the floating element overflows the boundary.
              Type
              (
              element:
              | HTMLElement
              | VirtualElement,
              ) => {
              height?: number
              width?: number
              x?: number
              y?: number
              }
              Description
              Function that returns the anchor rect
                Type
                number
                Description
                The main axis offset or gap between the reference and floating element
                Type
                boolean
                Description
                Whether the popover should be hidden when the reference element is detached
                Type
                | boolean
                | {
                ancestorResize?: boolean
                ancestorScroll?: boolean
                animationFrame?: boolean
                elementResize?: boolean
                layoutShift?: boolean
                }
                Description
                Options to activate auto-update listeners
                Type
                {
                crossAxis?: number
                mainAxis?: number
                }
                Description
                The offset of the floating element
                Type
                (
                data: ComputePositionReturn,
                ) => void
                Description
                Function called when the placement is computed
                  Type
                  (data: {
                  placed: boolean
                  }) => void
                  Description
                  Function called when the floating element is positioned or not
                    Type
                    number
                    Description
                    The virtual padding around the viewport edges to check for overflow
                    Type
                    boolean
                    Description
                    Whether the floating element can overlap the reference element
                    Type
                    | 'bottom'
                    | 'bottom-end'
                    | 'bottom-start'
                    | 'left'
                    | 'left-end'
                    | 'left-start'
                    | 'right'
                    | 'right-end'
                    | 'right-start'
                    | 'top'
                    | 'top-end'
                    | 'top-start'
                    Description
                    The initial placement of the floating element
                    Type
                    boolean
                    Description
                    Whether to make the floating element same width as the reference element
                    Type
                    number
                    Description
                    The secondary axis offset or gap between the reference and floating elements
                    Type
                    boolean
                    Description
                    Whether the popover should slide when it overflows.
                    Type
                    | 'absolute'
                    | 'fixed'
                    Description
                    The strategy to use for positioning
                    Type
                    (data: {
                    updatePosition: () => Promise<void>
                    }) => void | Promise<void>
                    Description
                    A callback that will be called when the popover needs to calculate its position.