UNPKG

16.1 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, EventEmitter, inject, Output } from '@angular/core';
9import { ESCAPE, hasModifierKey, LEFT_ARROW, RIGHT_ARROW, TAB } from '@angular/cdk/keycodes';
10import { takeUntil } from 'rxjs/operators';
11import { CdkMenuGroup } from './menu-group';
12import { CDK_MENU } from './menu-interface';
13import { PARENT_OR_NEW_INLINE_MENU_STACK_PROVIDER } from './menu-stack';
14import { MENU_TRIGGER } from './menu-trigger-base';
15import { CdkMenuBase } from './menu-base';
16import * as i0 from "@angular/core";
17/**
18 * Directive which configures the element as a Menu which should contain child elements marked as
19 * CdkMenuItem or CdkMenuGroup. Sets the appropriate role and aria-attributes for a menu and
20 * contains accessible keyboard and mouse handling logic.
21 *
22 * It also acts as a RadioGroup for elements marked with role `menuitemradio`.
23 */
24class CdkMenu extends CdkMenuBase {
25 constructor() {
26 super();
27 this._parentTrigger = inject(MENU_TRIGGER, { optional: true });
28 /** Event emitted when the menu is closed. */
29 this.closed = new EventEmitter();
30 /** The direction items in the menu flow. */
31 this.orientation = 'vertical';
32 /** Whether the menu is displayed inline (i.e. always present vs a conditional popup that the user triggers with a trigger element). */
33 this.isInline = !this._parentTrigger;
34 this.destroyed.subscribe(this.closed);
35 this._parentTrigger?.registerChildMenu(this);
36 }
37 ngAfterContentInit() {
38 super.ngAfterContentInit();
39 this._subscribeToMenuStackEmptied();
40 }
41 ngOnDestroy() {
42 super.ngOnDestroy();
43 this.closed.complete();
44 }
45 /**
46 * Handle keyboard events for the Menu.
47 * @param event The keyboard event to be handled.
48 */
49 _handleKeyEvent(event) {
50 const keyManager = this.keyManager;
51 switch (event.keyCode) {
52 case LEFT_ARROW:
53 case RIGHT_ARROW:
54 if (!hasModifierKey(event)) {
55 event.preventDefault();
56 keyManager.setFocusOrigin('keyboard');
57 keyManager.onKeydown(event);
58 }
59 break;
60 case ESCAPE:
61 if (!hasModifierKey(event)) {
62 event.preventDefault();
63 this.menuStack.close(this, {
64 focusNextOnEmpty: 2 /* FocusNext.currentItem */,
65 focusParentTrigger: true,
66 });
67 }
68 break;
69 case TAB:
70 if (!hasModifierKey(event, 'altKey', 'metaKey', 'ctrlKey')) {
71 this.menuStack.closeAll({ focusParentTrigger: true });
72 }
73 break;
74 default:
75 keyManager.onKeydown(event);
76 }
77 }
78 /**
79 * Set focus the either the current, previous or next item based on the FocusNext event.
80 * @param focusNext The element to focus.
81 */
82 _toggleMenuFocus(focusNext) {
83 const keyManager = this.keyManager;
84 switch (focusNext) {
85 case 0 /* FocusNext.nextItem */:
86 keyManager.setFocusOrigin('keyboard');
87 keyManager.setNextItemActive();
88 break;
89 case 1 /* FocusNext.previousItem */:
90 keyManager.setFocusOrigin('keyboard');
91 keyManager.setPreviousItemActive();
92 break;
93 case 2 /* FocusNext.currentItem */:
94 if (keyManager.activeItem) {
95 keyManager.setFocusOrigin('keyboard');
96 keyManager.setActiveItem(keyManager.activeItem);
97 }
98 break;
99 }
100 }
101 /** Subscribe to the MenuStack emptied events. */
102 _subscribeToMenuStackEmptied() {
103 this.menuStack.emptied
104 .pipe(takeUntil(this.destroyed))
105 .subscribe(event => this._toggleMenuFocus(event));
106 }
107 static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: CdkMenu, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
108 static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.0.0", type: CdkMenu, isStandalone: true, selector: "[cdkMenu]", outputs: { closed: "closed" }, host: { attributes: { "role": "menu" }, listeners: { "keydown": "_handleKeyEvent($event)" }, properties: { "class.cdk-menu-inline": "isInline" }, classAttribute: "cdk-menu" }, providers: [
109 { provide: CdkMenuGroup, useExisting: CdkMenu },
110 { provide: CDK_MENU, useExisting: CdkMenu },
111 PARENT_OR_NEW_INLINE_MENU_STACK_PROVIDER('vertical'),
112 ], exportAs: ["cdkMenu"], usesInheritance: true, ngImport: i0 }); }
113}
114export { CdkMenu };
115i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: CdkMenu, decorators: [{
116 type: Directive,
117 args: [{
118 selector: '[cdkMenu]',
119 exportAs: 'cdkMenu',
120 standalone: true,
121 host: {
122 'role': 'menu',
123 'class': 'cdk-menu',
124 '[class.cdk-menu-inline]': 'isInline',
125 '(keydown)': '_handleKeyEvent($event)',
126 },
127 providers: [
128 { provide: CdkMenuGroup, useExisting: CdkMenu },
129 { provide: CDK_MENU, useExisting: CdkMenu },
130 PARENT_OR_NEW_INLINE_MENU_STACK_PROVIDER('vertical'),
131 ],
132 }]
133 }], ctorParameters: function () { return []; }, propDecorators: { closed: [{
134 type: Output
135 }] } });
136//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVudS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uL3NyYy9jZGsvbWVudS9tZW51LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRztBQUVILE9BQU8sRUFBbUIsU0FBUyxFQUFFLFlBQVksRUFBRSxNQUFNLEVBQWEsTUFBTSxFQUFDLE1BQU0sZUFBZSxDQUFDO0FBQ25HLE9BQU8sRUFBQyxNQUFNLEVBQUUsY0FBYyxFQUFFLFVBQVUsRUFBRSxXQUFXLEVBQUUsR0FBRyxFQUFDLE1BQU0sdUJBQXVCLENBQUM7QUFDM0YsT0FBTyxFQUFDLFNBQVMsRUFBQyxNQUFNLGdCQUFnQixDQUFDO0FBQ3pDLE9BQU8sRUFBQyxZQUFZLEVBQUMsTUFBTSxjQUFjLENBQUM7QUFDMUMsT0FBTyxFQUFDLFFBQVEsRUFBQyxNQUFNLGtCQUFrQixDQUFDO0FBQ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