/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { Directive } from '@angular/core'; import { DOWN_ARROW, ESCAPE, hasModifierKey, LEFT_ARROW, RIGHT_ARROW, TAB, UP_ARROW, } from '@angular/cdk/keycodes'; import { takeUntil } from 'rxjs/operators'; import { CdkMenuGroup } from './menu-group'; import { CDK_MENU } from './menu-interface'; import { MENU_STACK, MenuStack } from './menu-stack'; import { CdkMenuBase } from './menu-base'; import * as i0 from "@angular/core"; /** * Directive applied to an element which configures it as a MenuBar by setting the appropriate * role, aria attributes, and accessible keyboard and mouse handling logic. The component that * this directive is applied to should contain components marked with CdkMenuItem. * */ export class CdkMenuBar extends CdkMenuBase { constructor() { super(...arguments); /** The direction items in the menu flow. */ this.orientation = 'horizontal'; /** Whether the menu is displayed inline (i.e. always present vs a conditional popup that the user triggers with a trigger element). */ this.isInline = true; } ngAfterContentInit() { super.ngAfterContentInit(); this._subscribeToMenuStackEmptied(); } /** * Handle keyboard events for the Menu. * @param event The keyboard event to be handled. */ _handleKeyEvent(event) { const keyManager = this.keyManager; switch (event.keyCode) { case UP_ARROW: case DOWN_ARROW: case LEFT_ARROW: case RIGHT_ARROW: if (!hasModifierKey(event)) { const horizontalArrows = event.keyCode === LEFT_ARROW || event.keyCode === RIGHT_ARROW; // For a horizontal menu if the left/right keys were clicked, or a vertical menu if the // up/down keys were clicked: if the current menu is open, close it then focus and open the // next menu. if (horizontalArrows) { event.preventDefault(); const prevIsOpen = keyManager.activeItem?.isMenuOpen(); keyManager.activeItem?.getMenuTrigger()?.close(); keyManager.setFocusOrigin('keyboard'); keyManager.onKeydown(event); if (prevIsOpen) { keyManager.activeItem?.getMenuTrigger()?.open(); } } } break; case ESCAPE: if (!hasModifierKey(event)) { event.preventDefault(); keyManager.activeItem?.getMenuTrigger()?.close(); } break; case TAB: if (!hasModifierKey(event, 'altKey', 'metaKey', 'ctrlKey')) { keyManager.activeItem?.getMenuTrigger()?.close(); } break; default: keyManager.onKeydown(event); } } /** * Set focus to either the current, previous or next item based on the FocusNext event, then * open the previous or next item. * @param focusNext The element to focus. */ _toggleOpenMenu(focusNext) { const keyManager = this.keyManager; switch (focusNext) { case 0 /* FocusNext.nextItem */: keyManager.setFocusOrigin('keyboard'); keyManager.setNextItemActive(); keyManager.activeItem?.getMenuTrigger()?.open(); break; case 1 /* FocusNext.previousItem */: keyManager.setFocusOrigin('keyboard'); keyManager.setPreviousItemActive(); keyManager.activeItem?.getMenuTrigger()?.open(); break; case 2 /* FocusNext.currentItem */: if (keyManager.activeItem) { keyManager.setFocusOrigin('keyboard'); keyManager.setActiveItem(keyManager.activeItem); } break; } } /** Subscribe to the MenuStack emptied events. */ _subscribeToMenuStackEmptied() { this.menuStack?.emptied .pipe(takeUntil(this.destroyed)) .subscribe(event => this._toggleOpenMenu(event)); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: CdkMenuBar, deps: null, target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.1", type: CdkMenuBar, isStandalone: true, selector: "[cdkMenuBar]", host: { attributes: { "role": "menubar" }, listeners: { "keydown": "_handleKeyEvent($event)" }, classAttribute: "cdk-menu-bar" }, providers: [ { provide: CdkMenuGroup, useExisting: CdkMenuBar }, { provide: CDK_MENU, useExisting: CdkMenuBar }, { provide: MENU_STACK, useFactory: () => MenuStack.inline('horizontal') }, ], exportAs: ["cdkMenuBar"], usesInheritance: true, ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: CdkMenuBar, decorators: [{ type: Directive, args: [{ selector: '[cdkMenuBar]', exportAs: 'cdkMenuBar', standalone: true, host: { 'role': 'menubar', 'class': 'cdk-menu-bar', '(keydown)': '_handleKeyEvent($event)', }, providers: [ { provide: CdkMenuGroup, useExisting: CdkMenuBar }, { provide: CDK_MENU, useExisting: CdkMenuBar }, { provide: MENU_STACK, useFactory: () => MenuStack.inline('horizontal') }, ], }] }] }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVudS1iYXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvY2RrL21lbnUvbWVudS1iYXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBRUgsT0FBTyxFQUFtQixTQUFTLEVBQUMsTUFBTSxlQUFlLENBQUM7QUFDMUQsT0FBTyxFQUNMLFVBQVUsRUFDVixNQUFNLEVBQ04sY0FBYyxFQUNkLFVBQVUsRUFDVixXQUFXLEVBQ1gsR0FBRyxFQUNILFFBQVEsR0FDVCxNQUFNLHVCQUF1QixDQUFDO0FBQy9CLE9BQU8sRUFBQyxTQUFTLEVBQUMsTUFBTSxnQkFBZ0IsQ0FBQztBQUN6QyxPQUFPLEVBQUMsWUFBWSxFQUFDLE1BQU0sY0FBYyxDQUFDO0FBQzFDLE9BQU8sRUFBQyxRQUFRLEVBQUMsTUFBTSxrQkFBa0IsQ0FBQztBQUMxQyxPQUFPLEVBQVksVUFBVSxFQUFFLFNBQVMsRUFBQyxNQUFNLGNBQWMsQ0FBQztBQUM5RCxPQUFPLEVBQUMsV0FBVyxFQUFDLE1BQU0sYUFBYSxDQUFDOztBQUV4Qzs7Ozs7R0FLRztBQWdCSCxNQUFNLE9BQU8sVUFBVyxTQUFRLFdBQVc7SUFmM0M7O1FBZ0JFLDRDQUE0QztRQUMxQixnQkFBVyxHQUFHLFlBQVksQ0FBQztRQUU3Qyx1SUFBdUk7UUFDckgsYUFBUSxHQUFHLElBQUksQ0FBQztLQTJGbkM7SUF6RlUsa0JBQWtCO1FBQ3pCLEtBQUssQ0FBQyxrQkFBa0IsRUFBRSxDQUFDO1FBQzNCLElBQUksQ0FBQyw0Qk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