UNPKG

39 kBJavaScriptView Raw
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import { Directive, ElementRef, inject, NgZone } from '@angular/core';
9import { Directionality } from '@angular/cdk/bidi';
10import { Overlay, OverlayConfig, STANDARD_DROPDOWN_ADJACENT_POSITIONS, STANDARD_DROPDOWN_BELOW_POSITIONS, } from '@angular/cdk/overlay';
11import { DOWN_ARROW, ENTER, hasModifierKey, LEFT_ARROW, RIGHT_ARROW, SPACE, UP_ARROW, } from '@angular/cdk/keycodes';
12import { _getEventTarget } from '@angular/cdk/platform';
13import { InputModalityDetector } from '@angular/cdk/a11y';
14import { fromEvent } from 'rxjs';
15import { filter, takeUntil } from 'rxjs/operators';
16import { CDK_MENU } from './menu-interface';
17import { PARENT_OR_NEW_MENU_STACK_PROVIDER } from './menu-stack';
18import { MENU_AIM } from './menu-aim';
19import { CdkMenuTriggerBase, MENU_TRIGGER } from './menu-trigger-base';
20import * as i0 from "@angular/core";
21/**
22 * A directive that turns its host element into a trigger for a popup menu.
23 * It can be combined with cdkMenuItem to create sub-menus. If the element is in a top level
24 * MenuBar it will open the menu on click, or if a sibling is already opened it will open on hover.
25 * If it is inside of a Menu it will open the attached Submenu on hover regardless of its sibling
26 * state.
27 */
28class CdkMenuTrigger extends CdkMenuTriggerBase {
29 constructor() {
30 super();
31 this._elementRef = inject(ElementRef);
32 this._overlay = inject(Overlay);
33 this._ngZone = inject(NgZone);
34 this._directionality = inject(Directionality, { optional: true });
35 this._inputModalityDetector = inject(InputModalityDetector);
36 /** The parent menu this trigger belongs to. */
37 this._parentMenu = inject(CDK_MENU, { optional: true });
38 /** The menu aim service used by this menu. */
39 this._menuAim = inject(MENU_AIM, { optional: true });
40 this._setRole();
41 this._registerCloseHandler();
42 this._subscribeToMenuStackClosed();
43 this._subscribeToMouseEnter();
44 this._subscribeToMenuStackHasFocus();
45 this._setType();
46 }
47 /** Toggle the attached menu. */
48 toggle() {
49 this.isOpen() ? this.close() : this.open();
50 }
51 /** Open the attached menu. */
52 open() {
53 if (!this.isOpen() && this.menuTemplateRef != null) {
54 this.opened.next();
55 this.overlayRef = this.overlayRef || this._overlay.create(this._getOverlayConfig());
56 this.overlayRef.attach(this.getMenuContentPortal());
57 this._subscribeToOutsideClicks();
58 }
59 }
60 /** Close the opened menu. */
61 close() {
62 if (this.isOpen()) {
63 this.closed.next();
64 this.overlayRef.detach();
65 }
66 this._closeSiblingTriggers();
67 }
68 /**
69 * Get a reference to the rendered Menu if the Menu is open and rendered in the DOM.
70 */
71 getMenu() {
72 return this.childMenu;
73 }
74 /**
75 * Handles keyboard events for the menu item.
76 * @param event The keyboard event to handle
77 */
78 _toggleOnKeydown(event) {
79 const isParentVertical = this._parentMenu?.orientation === 'vertical';
80 switch (event.keyCode) {
81 case SPACE:
82 case ENTER:
83 if (!hasModifierKey(event)) {
84 this.toggle();
85 this.childMenu?.focusFirstItem('keyboard');
86 }
87 break;
88 case RIGHT_ARROW:
89 if (!hasModifierKey(event)) {
90 if (this._parentMenu && isParentVertical && this._directionality?.value !== 'rtl') {
91 event.preventDefault();
92 this.open();
93 this.childMenu?.focusFirstItem('keyboard');
94 }
95 }
96 break;
97 case LEFT_ARROW:
98 if (!hasModifierKey(event)) {
99 if (this._parentMenu && isParentVertical && this._directionality?.value === 'rtl') {
100 event.preventDefault();
101 this.open();
102 this.childMenu?.focusFirstItem('keyboard');
103 }
104 }
105 break;
106 case DOWN_ARROW:
107 case UP_ARROW:
108 if (!hasModifierKey(event)) {
109 if (!isParentVertical) {
110 event.preventDefault();
111 this.open();
112 event.keyCode === DOWN_ARROW
113 ? this.childMenu?.focusFirstItem('keyboard')
114 : this.childMenu?.focusLastItem('keyboard');
115 }
116 }
117 break;
118 }
119 }
120 /** Handles clicks on the menu trigger. */
121 _handleClick() {
122 // Don't handle clicks originating from the keyboard since we
123 // already do the same on `keydown` events for enter and space.
124 if (this._inputModalityDetector.mostRecentModality !== 'keyboard') {
125 this.toggle();
126 this.childMenu?.focusFirstItem('mouse');
127 }
128 }
129 /**
130 * Sets whether the trigger's menu stack has focus.
131 * @param hasFocus Whether the menu stack has focus.
132 */
133 _setHasFocus(hasFocus) {
134 if (!this._parentMenu) {
135 this.menuStack.setHasFocus(hasFocus);
136 }
137 }
138 /**
139 * Subscribe to the mouseenter events and close any sibling menu items if this element is moused
140 * into.
141 */
142 _subscribeToMouseEnter() {
143 this._ngZone.runOutsideAngular(() => {
144 fromEvent(this._elementRef.nativeElement, 'mouseenter')
145 .pipe(filter(() => !this.menuStack.isEmpty() && !this.isOpen()), takeUntil(this.destroyed))
146 .subscribe(() => {
147 // Closes any sibling menu items and opens the menu associated with this trigger.
148 const toggleMenus = () => this._ngZone.run(() => {
149 this._closeSiblingTriggers();
150 this.open();
151 });
152 if (this._menuAim) {
153 this._menuAim.toggle(toggleMenus);
154 }
155 else {
156 toggleMenus();
157 }
158 });
159 });
160 }
161 /** Close out any sibling menu trigger menus. */
162 _closeSiblingTriggers() {
163 if (this._parentMenu) {
164 // If nothing was removed from the stack and the last element is not the parent item
165 // that means that the parent menu is a menu bar since we don't put the menu bar on the
166 // stack
167 const isParentMenuBar = !this.menuStack.closeSubMenuOf(this._parentMenu) &&
168 this.menuStack.peek() !== this._parentMenu;
169 if (isParentMenuBar) {
170 this.menuStack.closeAll();
171 }
172 }
173 else {
174 this.menuStack.closeAll();
175 }
176 }
177 /** Get the configuration object used to create the overlay. */
178 _getOverlayConfig() {
179 return new OverlayConfig({
180 positionStrategy: this._getOverlayPositionStrategy(),
181 scrollStrategy: this._overlay.scrollStrategies.reposition(),
182 direction: this._directionality || undefined,
183 });
184 }
185 /** Build the position strategy for the overlay which specifies where to place the menu. */
186 _getOverlayPositionStrategy() {
187 return this._overlay
188 .position()
189 .flexibleConnectedTo(this._elementRef)
190 .withLockedPosition()
191 .withGrowAfterOpen()
192 .withPositions(this._getOverlayPositions());
193 }
194 /** Get the preferred positions for the opened menu relative to the menu item. */
195 _getOverlayPositions() {
196 return (this.menuPosition ??
197 (!this._parentMenu || this._parentMenu.orientation === 'horizontal'
198 ? STANDARD_DROPDOWN_BELOW_POSITIONS
199 : STANDARD_DROPDOWN_ADJACENT_POSITIONS));
200 }
201 /**
202 * Subscribe to the MenuStack close events if this is a standalone trigger and close out the menu
203 * this triggers when requested.
204 */
205 _registerCloseHandler() {
206 if (!this._parentMenu) {
207 this.menuStack.closed.pipe(takeUntil(this.destroyed)).subscribe(({ item }) => {
208 if (item === this.childMenu) {
209 this.close();
210 }
211 });
212 }
213 }
214 /**
215 * Subscribe to the overlays outside pointer events stream and handle closing out the stack if a
216 * click occurs outside the menus.
217 */
218 _subscribeToOutsideClicks() {
219 if (this.overlayRef) {
220 this.overlayRef
221 .outsidePointerEvents()
222 .pipe(takeUntil(this.stopOutsideClicksListener))
223 .subscribe(event => {
224 const target = _getEventTarget(event);
225 const element = this._elementRef.nativeElement;
226 if (target !== element && !element.contains(target)) {
227 if (!this.isElementInsideMenuStack(target)) {
228 this.menuStack.closeAll();
229 }
230 else {
231 this._closeSiblingTriggers();
232 }
233 }
234 });
235 }
236 }
237 /** Subscribe to the MenuStack hasFocus events. */
238 _subscribeToMenuStackHasFocus() {
239 if (!this._parentMenu) {
240 this.menuStack.hasFocus.pipe(takeUntil(this.destroyed)).subscribe(hasFocus => {
241 if (!hasFocus) {
242 this.menuStack.closeAll();
243 }
244 });
245 }
246 }
247 /** Subscribe to the MenuStack closed events. */
248 _subscribeToMenuStackClosed() {
249 if (!this._parentMenu) {
250 this.menuStack.closed.subscribe(({ focusParentTrigger }) => {
251 if (focusParentTrigger && !this.menuStack.length()) {
252 this._elementRef.nativeElement.focus();
253 }
254 });
255 }
256 }
257 /** Sets the role attribute for this trigger if needed. */
258 _setRole() {
259 // If this trigger is part of another menu, the cdkMenuItem directive will handle setting the
260 // role, otherwise this is a standalone trigger, and we should ensure it has role="button".
261 if (!this._parentMenu) {
262 this._elementRef.nativeElement.setAttribute('role', 'button');
263 }
264 }
265 /** Sets thte `type` attribute of the trigger. */
266 _setType() {
267 const element = this._elementRef.nativeElement;
268 if (element.nodeName === 'BUTTON' && !element.getAttribute('type')) {
269 // Prevents form submissions.
270 element.setAttribute('type', 'button');
271 }
272 }
273 static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: CdkMenuTrigger, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
274 static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.0.0", type: CdkMenuTrigger, isStandalone: true, selector: "[cdkMenuTriggerFor]", inputs: { menuTemplateRef: ["cdkMenuTriggerFor", "menuTemplateRef"], menuPosition: ["cdkMenuPosition", "menuPosition"], menuData: ["cdkMenuTriggerData", "menuData"] }, outputs: { opened: "cdkMenuOpened", closed: "cdkMenuClosed" }, host: { listeners: { "focusin": "_setHasFocus(true)", "focusout": "_setHasFocus(false)", "keydown": "_toggleOnKeydown($event)", "click": "_handleClick()" }, properties: { "attr.aria-haspopup": "menuTemplateRef ? \"menu\" : null", "attr.aria-expanded": "menuTemplateRef == null ? null : isOpen()" }, classAttribute: "cdk-menu-trigger" }, providers: [
275 { provide: MENU_TRIGGER, useExisting: CdkMenuTrigger },
276 PARENT_OR_NEW_MENU_STACK_PROVIDER,
277 ], exportAs: ["cdkMenuTriggerFor"], usesInheritance: true, ngImport: i0 }); }
278}
279export { CdkMenuTrigger };
280i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: CdkMenuTrigger, decorators: [{
281 type: Directive,
282 args: [{
283 selector: '[cdkMenuTriggerFor]',
284 exportAs: 'cdkMenuTriggerFor',
285 standalone: true,
286 host: {
287 'class': 'cdk-menu-trigger',
288 '[attr.aria-haspopup]': 'menuTemplateRef ? "menu" : null',
289 '[attr.aria-expanded]': 'menuTemplateRef == null ? null : isOpen()',
290 '(focusin)': '_setHasFocus(true)',
291 '(focusout)': '_setHasFocus(false)',
292 '(keydown)': '_toggleOnKeydown($event)',
293 '(click)': '_handleClick()',
294 },
295 inputs: [
296 'menuTemplateRef: cdkMenuTriggerFor',
297 'menuPosition: cdkMenuPosition',
298 'menuData: cdkMenuTriggerData',
299 ],
300 outputs: ['opened: cdkMenuOpened', 'closed: cdkMenuClosed'],
301 providers: [
302 { provide: MENU_TRIGGER, useExisting: CdkMenuTrigger },
303 PARENT_OR_NEW_MENU_STACK_PROVIDER,
304 ],
305 }]
306 }], ctorParameters: function () { return []; } });
307//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVudS10cmlnZ2VyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vc3JjL2Nkay9tZW51L21lbnUtdHJpZ2dlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7QUFFSCxPQUFPLEVBQUMsU0FBUyxFQUFFLFVBQVUsRUFBRSxNQUFNLEVBQUUsTUFBTSxFQUFZLE1BQU0sZUFBZSxDQUFDO0FBQy9FLE9BQU8sRUFBQyxjQUFjLEVBQUMsTUFBTSxtQkFBbUIsQ0FBQztBQUNqRCxPQUFPLEVBR0wsT0FBTyxFQUNQLGFBQWEsRUFDYixvQ0FBb0MsRUFDcEMsaUNBQWlDLEdBQ2xDLE1BQU0sc0JBQXNCLENBQUM7QUFDOUIsT0FBTyxFQUNMLFVBQVUsRUFDVixLQUFLLEVBQ0wsY0FBYyxFQUNkLFVBQVUsRUFDVixXQUFXLEVBQ1gsS0FBSyxFQUNMLFFBQVEsR0FDVCxNQUFNLHVCQUF1QixDQUFDO0FBQy9CLE9BQU8sRUFBQyxlQUFlLEVBQUMsTUFBTSx1QkFBdUIsQ0FBQztBQUN0RCxPQUFPLEVBQUMscUJBQXFCLEVBQUMsTUFBTSxtQkFBbUIsQ0FBQztBQUN4RCxPQUF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bnRNZW51ICYmIGlzUGFyZW50VmVydGljYWwgJiYgdGhpcy5fZGlyZWN0aW9uYWxpdHk/LnZhbHVlICE9PSAncnRsJykge1xuICAgICAgICAgICAgZXZlbnQucHJldmVudERlZmF1bHQoKTtcbiAgICAgICAgICAgIHRoaXMub3BlbigpO1xuICAgICAgICAgICAgdGhpcy5jaGlsZE1lbnU/LmZvY3VzRmlyc3RJdGVtKCdrZXlib2FyZCcpO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBicmVhaztcblxuICAgICAgY2FzZSBMRUZUX0FSUk9XOlxuICAgICAgICBpZiAoIWhhc01vZGlmaWVyS2V5KGV2ZW50KSkge1xuICAgICAgICAgIGlmICh0aGlzLl9wYXJlbnRNZW51ICYmIGlzUGFyZW50VmVydGljYWwgJiYgdGhpcy5fZGlyZWN0aW9uYWxpdHk/LnZhbHVlID09PSAncnRsJykge1xuICAgICAgICAgICAgZXZlbnQucHJldmVudERlZmF1bHQoKTtcbiAgICAgICAgICAgIHRoaXMub3BlbigpO1xuICAgICAgICAgICAgdGhpcy5jaGlsZE1lbnU/LmZvY3VzRmlyc3RJdGVtKCdrZXlib2FyZCcpO1xuICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgICAgICBicmVhaztcblxuICAgICAgY2FzZSBET1dOX0FSUk9XOlxuICAgICAgY2FzZSBVUF9BUlJPVzpcbiAgICAgICAgaWYgKCFoYXNNb2RpZmllcktleShldmVudCkpIHtcbiAgICAgICAgICBpZiAoIWlzUGFyZW50VmVydGljYWwpIHtcbiAgICAgICAgICAgIGV2ZW50LnByZXZlbnREZWZhdWx0KCk7XG4gICAgICAgICAgICB0aGlzLm9wZW4oKTtcbiAgICAgICAgICAgIGV2ZW50LmtleUNvZGUgPT09IERPV05fQVJST1dcbiAgICAgICAgICAgICAgPyB0aGlzLmNoaWxkTWVudT8uZm9jdXNGaXJzdEl0ZW0oJ2tleWJvYXJkJylcbiAgICAgICAgICAgICAgOiB0aGlzLmNoaWx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