MCPcopy Create free account
hub / github.com/angular/components / CdkMenuTrigger

Class CdkMenuTrigger

src/cdk/menu/menu-trigger.ts:80–385  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78 ],
79})
80export class CdkMenuTrigger extends CdkMenuTriggerBase implements OnChanges, OnDestroy {
81 private readonly _elementRef: ElementRef<HTMLElement> = inject(ElementRef);
82 private readonly _ngZone = inject(NgZone);
83 private readonly _changeDetectorRef = inject(ChangeDetectorRef);
84 private readonly _inputModalityDetector = inject(InputModalityDetector);
85 private readonly _directionality = inject(Directionality, {optional: true});
86 private readonly _renderer = inject(Renderer2);
87 private readonly _injector = inject(Injector);
88 private _cleanupMouseenter!: () => void;
89
90 /** The app's menu tracking registry */
91 private readonly _menuTracker = inject(MenuTracker);
92
93 /** The parent menu this trigger belongs to. */
94 private readonly _parentMenu = inject(CDK_MENU, {optional: true});
95
96 /** The menu aim service used by this menu. */
97 private readonly _menuAim = inject(MENU_AIM, {optional: true});
98
99 constructor() {
100 super();
101 this._setRole();
102 this._registerCloseHandler();
103 this._subscribeToMenuStackClosed();
104 this._subscribeToMouseEnter();
105 this._subscribeToMenuStackHasFocus();
106 this._setType();
107 }
108
109 /** Toggle the attached menu. */
110 toggle() {
111 this.isOpen() ? this.close() : this.open();
112 }
113
114 /** Open the attached menu. */
115 open() {
116 if (!this._parentMenu) {
117 this._menuTracker.update(this);
118 }
119 if (!this.isOpen() && this.menuTemplateRef != null) {
120 this.opened.next();
121
122 this.overlayRef =
123 this.overlayRef || createOverlayRef(this._injector, this._getOverlayConfig());
124 this.overlayRef.attach(this.getMenuContentPortal());
125 this._changeDetectorRef.markForCheck();
126 this._subscribeToOutsideClicks();
127 }
128 }
129
130 /** Close the opened menu. */
131 close() {
132 if (this.isOpen()) {
133 this.closed.next();
134
135 this.overlayRef!.detach();
136 this._changeDetectorRef.markForCheck();
137 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected