Skip to content

Class: FyzMenuTrigger

@flyze/lib-core-angular 1.0.0-alpha.34· latest

Defined in: projects/lib-core-angular/src/lib/directives/fyz-mat-menu-trigger/fyz-mat-menu-trigger.directive.ts:30

A directive that extends the MatMenuTrigger to provide additional functionality.

  • MatMenuTrigger
  • OnInit

new FyzMenuTrigger(overlay, element, viewContainerRef, scrollStrategy, parentMenu, menuItemInstance, dir, focusMonitor, ngZone): FyzMenuTrigger

Defined in: node_modules/@angular/material/menu/index.d.ts:476

Overlay

ElementRef<HTMLElement>

ViewContainerRef

any

MatMenuPanel

MatMenuItem

Directionality

FocusMonitor

NgZone

FyzMenuTrigger

MatMenuTrigger.constructor

new FyzMenuTrigger(overlay, element, viewContainerRef, scrollStrategy, parentMenu, menuItemInstance, dir, focusMonitor?): FyzMenuTrigger

Defined in: node_modules/@angular/material/menu/index.d.ts:481

Overlay

ElementRef<HTMLElement>

ViewContainerRef

any

MatMenuPanel

MatMenuItem

Directionality

FocusMonitor

FyzMenuTrigger

focusMonitor will become a required parameter.

8.0.0

MatMenuTrigger.constructor

new FyzMenuTrigger(overlay, element, viewContainerRef, scrollStrategy, parentMenu, menuItemInstance, dir, focusMonitor): FyzMenuTrigger

Defined in: node_modules/@angular/material/menu/index.d.ts:486

Overlay

ElementRef<HTMLElement>

ViewContainerRef

any

MatMenuPanel

MatMenuItem

Directionality

FocusMonitor

FyzMenuTrigger

ngZone will become a required parameter.

15.0.0

MatMenuTrigger.constructor

get anchor(): HTMLElement

Defined in: projects/lib-core-angular/src/lib/directives/fyz-mat-menu-trigger/fyz-mat-menu-trigger.directive.ts:115

The element the menu is anchored to on every open, instead of the directive’s host element. Use it when the trigger sits inside a wrapper the menu should line up with - a chips container around a search input, for example, where anchoring to the input alone would let the menu drift sideways as chips push the input along.

openMenuAtElement() still wins for the single open it applies to.

HTMLElement

set anchor(value): void

Defined in: projects/lib-core-angular/src/lib/directives/fyz-mat-menu-trigger/fyz-mat-menu-trigger.directive.ts:118

HTMLElement | ElementRef<HTMLElement>

void


get closeOnScrollOutOfView(): unknown

Defined in: projects/lib-core-angular/src/lib/directives/fyz-mat-menu-trigger/fyz-mat-menu-trigger.directive.ts:98

Whether the menu should close once its trigger has been scrolled out of sight. Without it the menu keeps following the trigger and is clamped to the viewport.

unknown

set closeOnScrollOutOfView(value): void

Defined in: projects/lib-core-angular/src/lib/directives/fyz-mat-menu-trigger/fyz-mat-menu-trigger.directive.ts:101

unknown

void


get gap(): number

Defined in: projects/lib-core-angular/src/lib/directives/fyz-mat-menu-trigger/fyz-mat-menu-trigger.directive.ts:85

The gap between the menu and the trigger element.

number

set gap(value): void

Defined in: projects/lib-core-angular/src/lib/directives/fyz-mat-menu-trigger/fyz-mat-menu-trigger.directive.ts:88

number

void


get menu(): MatMenuPanel<any>

Defined in: projects/lib-core-angular/src/lib/directives/fyz-mat-menu-trigger/fyz-mat-menu-trigger.directive.ts:165

References the menu instance that the trigger is associated with.

MatMenuPanel<any>

set menu(menu): void

Defined in: projects/lib-core-angular/src/lib/directives/fyz-mat-menu-trigger/fyz-mat-menu-trigger.directive.ts:168

References the menu instance that the trigger is associated with.

MatMenuPanel

void

MatMenuTrigger.menu


get openOnClick(): unknown

Defined in: projects/lib-core-angular/src/lib/directives/fyz-mat-menu-trigger/fyz-mat-menu-trigger.directive.ts:132

Whether a click on the trigger opens the menu. true is Material’s own behavior.

Set it to false to link a menu to this trigger without the directive opening it: the ARIA wiring and the positioning stay in place, and the consumer decides when to call openMenu(). That is what a combobox needs - Material toggles on click, so an open panel would close again when the user clicks the input to move the caret.

unknown

set openOnClick(value): void

Defined in: projects/lib-core-angular/src/lib/directives/fyz-mat-menu-trigger/fyz-mat-menu-trigger.directive.ts:135

unknown

void


get panelWidth(): "anchor"

Defined in: projects/lib-core-angular/src/lib/directives/fyz-mat-menu-trigger/fyz-mat-menu-trigger.directive.ts:154

The width of the menu panel.

  • 'anchor' - exactly as wide as the element the menu attaches to, from the first open, and it keeps following that element while the menu is open. Also drops the default viewportMargin to 0, so the menu stays on its origin even flush against the window edge.
  • null (default) - the directive does nothing. Material’s own 112px-280px panel sizing stands, exactly as it does on a plain matMenuTrigger.

Which element 'anchor' measures is whatever the origin resolves to: openMenuAtElement(), then the anchor input, then the host. A menu opened with openMenuAt(x, y) has no origin element and is unaffected.

"anchor"

set panelWidth(value): void

Defined in: projects/lib-core-angular/src/lib/directives/fyz-mat-menu-trigger/fyz-mat-menu-trigger.directive.ts:157

"anchor"

void


get viewportMargin(): number

Defined in: projects/lib-core-angular/src/lib/directives/fyz-mat-menu-trigger/fyz-mat-menu-trigger.directive.ts:73

The margin around the viewport where the menu should be positioned.

Defaults to 8, or to 0 when panelWidth is 'anchor' - a menu exactly as wide as its origin is on screen whenever that origin is, and the margin is what would otherwise shift it off an origin flush against the window edge. Setting the input explicitly always wins.

The CDK spends the margin unevenly - it is the trailing/bottom distance, doubled, and the leading edges get none. See docs/features/mat-menu-trigger.md.

number

set viewportMargin(value): void

Defined in: projects/lib-core-angular/src/lib/directives/fyz-mat-menu-trigger/fyz-mat-menu-trigger.directive.ts:76

number

void

_handleClick(event): void

Defined in: projects/lib-core-angular/src/lib/directives/fyz-mat-menu-trigger/fyz-mat-menu-trigger.directive.ts:240

Swallows the click when openOnClick is off.

Unlike _setPosition, this one is public in Material’s type, so it is a real override - a signature change on upgrade fails the build instead of silently doing nothing. It is reached because Angular copies Material’s host listeners onto this directive and dispatches them on the instance.

MouseEvent

void

MatMenuTrigger._handleClick


ngOnDestroy(): void

Defined in: projects/lib-core-angular/src/lib/directives/fyz-mat-menu-trigger/fyz-mat-menu-trigger.directive.ts:177

void

MatMenuTrigger.ngOnDestroy


ngOnInit(): void

Defined in: projects/lib-core-angular/src/lib/directives/fyz-mat-menu-trigger/fyz-mat-menu-trigger.directive.ts:172

A callback method that is invoked immediately after the default change detector has checked the directive’s data-bound properties for the first time, and before any of the view or content children have been checked. It is invoked only once when the directive is instantiated.

void

OnInit.ngOnInit


openMenu(): void

Defined in: projects/lib-core-angular/src/lib/directives/fyz-mat-menu-trigger/fyz-mat-menu-trigger.directive.ts:200

Material’s own open, plus the two things panelWidth needs and cannot do any earlier.

Both of them have to happen after super.openMenu():

  • the pane is sized here rather than from inside _setPosition, because updateSize() replaces OverlayRef._config (overlay.mjs:939) while openMenu() captured that object before calling _setPosition and writes hasBackdrop to it afterwards (menu.mjs:840). Replacing it in between orphans that write, attach() reads undefined, no backdrop is created - and backdropClick() is the only thing that closes a menu on an outside click.
  • the panel inside the pane only exists once attach() has run. Sizing the pane is not enough on its own: .cdk-overlay-pane is a row flexbox, so the panel does not stretch to it, and .mat-mdc-menu-panel carries min-width: 112px; max-width: 280px.

Doing this after the open costs nothing: OverlayRef.attach() defers positioning to NgZone.onStable (overlay.mjs:793), so the width is still in the DOM before the CDK measures.

void

MatMenuTrigger.openMenu


openMenuAt(x, y): void

Defined in: projects/lib-core-angular/src/lib/directives/fyz-mat-menu-trigger/fyz-mat-menu-trigger.directive.ts:336

Open the menu at the specified coordinates.

number

number

void


openMenuAtElement(element): void

Defined in: projects/lib-core-angular/src/lib/directives/fyz-mat-menu-trigger/fyz-mat-menu-trigger.directive.ts:347

Opens the menu at the specified element.

HTMLElement

void