Skip to main content
cngx-src documentation

CngxMenuTrigger

DirectivePrimaryv0.1.0WCAG AA

projects/common/interactive/menu/menu-trigger.directive.ts

Import#

import { CngxMenuTrigger } from '@cngx/common/interactive'

Description#

Trigger atom for dropdown menus.

Pairs a focusable element with a CngxMenu and a CngxPopover through explicit template references - identical keyboard model to CngxListboxTrigger except closeOnSelect is hardcoded true (menu semantics: activating an item dismisses the menu).

Carries a focus-stack model for nested submenus: when a submenu opens, its inner CngxMenu is pushed onto the stack so subsequent ArrowDown / Up / Home / End / Enter target the submenu's items via its own CngxActiveDescendant. ArrowLeft / Escape pop the stack and close the top submenu.

Focus model

The dropdown trigger deliberately keeps DOM focus on the trigger button while the menu is open - WAI-ARIA APG Menu Button Pattern - and drives the menu's CngxActiveDescendant from there via host keydown. It does NOT call CngxMenuHost.focus after open; that path is reserved for CngxContextMenuTrigger, where the trigger zone is non-focusable consumer content and the menu container itself must take focus to receive keyboard input.

Dismissal

Four dismissal sources close the menu by default: Escape, pointerdown outside both the popover and the trigger host, window blur, and document pointercancel. Window scroll is opt-in via withDismissOnScroll. The source that fired most recently is readable through lastDismissSource.

Override individual sources at app root with withDismissOnOutsideClick, withDismissOnScroll, withDismissOnBlur, or swap the whole handler via CNGX_MENU_DISMISS_HANDLER_FACTORY for telemetry-wrapped or test-doubled dismissal.

https://cngxjs.github.io/cngx/examples/#/common/interactive/menu/submenu/two-level-submenu https://cngxjs.github.io/cngx/examples/#/common/interactive/menu/trigger/dropdown-menu

Metadata#

Host#

Relationships

Index#

Inputs#

input()Required

Popover that wraps the menu panel.

Instance Properties#

lastDismissSource#unknown
Readonly

The dismissal source that closed the menu most recently. null before the first close. Surface for demos, telemetry, and audit sinks - reads which path fired without re-installing listeners.

this.dismissBinding.lastSource

Methods#

handleKeydown#void
Protected
handleKeydown(event: KeyboardEvent)
@parameventKeyboardEvent

HostBindings#

BindingExpression
[attr.aria-haspopup]"menu"
[attr.aria-expanded]isOpen()

HostListeners#

EventHandler
(keydown)keydown()