UNPKG

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