/** * @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, EventEmitter, inject, Output } from '@angular/core'; import { ESCAPE, hasModifierKey, LEFT_ARROW, RIGHT_ARROW, TAB } from '@angular/cdk/keycodes'; import { takeUntil } from 'rxjs/operators'; import { CdkMenuGroup } from './menu-group'; import { CDK_MENU } from './menu-interface'; import { PARENT_OR_NEW_INLINE_MENU_STACK_PROVIDER } from './menu-stack'; import { MENU_TRIGGER } from './menu-trigger-base'; import { CdkMenuBase } from './menu-base'; import * as i0 from "@angular/core"; /** * Directive which configures the element as a Menu which should contain child elements marked as * CdkMenuItem or CdkMenuGroup. Sets the appropriate role and aria-attributes for a menu and * contains accessible keyboard and mouse handling logic. * * It also acts as a RadioGroup for elements marked with role `menuitemradio`. */ export class CdkMenu extends CdkMenuBase { constructor() { super(); this._parentTrigger = inject(MENU_TRIGGER, { optional: true }); /** Event emitted when the menu is closed. */ this.closed = new EventEmitter(); /** The direction items in the menu flow. */ this.orientation = 'vertical'; /** Whether the menu is displayed inline (i.e. always present vs a conditional popup that the user triggers with a trigger element). */ this.isInline = !this._parentTrigger; this.destroyed.subscribe(this.closed); this._parentTrigger?.registerChildMenu(this); } ngAfterContentInit() { super.ngAfterContentInit(); this._subscribeToMenuStackEmptied(); } ngOnDestroy() { super.ngOnDestroy(); this.closed.complete(); } /** * Handle keyboard events for the Menu. * @param event The keyboard event to be handled. */ _handleKeyEvent(event) { const keyManager = this.keyManager; switch (event.keyCode) { case LEFT_ARROW: case RIGHT_ARROW: if (!hasModifierKey(event)) { event.preventDefault(); keyManager.setFocusOrigin('keyboard'); keyManager.onKeydown(event); } break; case ESCAPE: if (!hasModifierKey(event)) { event.preventDefault(); this.menuStack.close(this, { focusNextOnEmpty: 2 /* FocusNext.currentItem */, focusParentTrigger: true, }); } break; case TAB: if (!hasModifierKey(event, 'altKey', 'metaKey', 'ctrlKey')) { this.menuStack.closeAll({ focusParentTrigger: true }); } break; default: keyManager.onKeydown(event); } } /** * Set focus the either the current, previous or next item based on the FocusNext event. * @param focusNext The element to focus. */ _toggleMenuFocus(focusNext) { const keyManager = this.keyManager; switch (focusNext) { case 0 /* FocusNext.nextItem */: keyManager.setFocusOrigin('keyboard'); keyManager.setNextItemActive(); break; case 1 /* FocusNext.previousItem */: keyManager.setFocusOrigin('keyboard'); keyManager.setPreviousItemActive(); 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._toggleMenuFocus(event)); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: CdkMenu, deps: [], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.1", 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: [ { provide: CdkMenuGroup, useExisting: CdkMenu }, { provide: CDK_MENU, useExisting: CdkMenu }, PARENT_OR_NEW_INLINE_MENU_STACK_PROVIDER('vertical'), ], exportAs: ["cdkMenu"], usesInheritance: true, ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: CdkMenu, decorators: [{ type: Directive, args: [{ selector: '[cdkMenu]', exportAs: 'cdkMenu', standalone: true, host: { 'role': 'menu', 'class': 'cdk-menu', '[class.cdk-menu-inline]': 'isInline', '(keydown)': '_handleKeyEvent($event)', }, providers: [ { provide: CdkMenuGroup, useExisting: CdkMenu }, { provide: CDK_MENU, useExisting: CdkMenu }, PARENT_OR_NEW_INLINE_MENU_STACK_PROVIDER('vertical'), ], }] }], ctorParameters: function () { return []; }, propDecorators: { closed: [{ type: Output }] } }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVudS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uL3NyYy9jZGsvbWVudS9tZW51LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRztBQUVILE9BQU8sRUFBbUIsU0FBUyxFQUFFLFlBQVksRUFBRSxNQUFNLEVBQWEsTUFBTSxFQUFDLE1BQU0sZUFBZSxDQUFDO0FBQ25HLE9BQU8sRUFBQyxNQUFNLEVBQUUsY0FBYyxFQUFFLFVBQVUsRUFBRSxXQUFXLEVBQUUsR0FBRyxFQUFDLE1BQU0sdUJBQXVCLENBQUM7QUFDM0YsT0FBTyxFQUFDLFNBQVMsRUFBQyxNQUFNLGdCQUFnQixDQUFDO0FBQ3pDLE9BQU8sRUFBQyxZQUFZLEVBQUMsTUFBTSxjQUFjLENBQUM7QUFDMUMsT0FBTyxFQUFDLFFBQVEsRUFBQyxNQUFNLGtCQUFrQixDQUFDO0FBQzFDLE9BQU8sRUFBWSx3Q0FBd0MsRUFBQyxNQUFNLGNBQWMsQ0FBQztBQUNqRixPQUFPLEVBQUMsWUFBWSxFQUFDLE1BQU0scUJBQXFCLENBQUM7QUFDakQsT0FBTyxFQUFDLFdBQVcsRUFBQyxNQUFNLGFBQWEsQ0FBQzs7QUFFeEM7Ozs7OztHQU1HO0FBaUJILE1BQU0sT0FBTyxPQUFRLFNBQVEsV0FBVztJQVl0QztRQUNFLEtBQUssRUFBRSxDQUFDO1FBWkYsbUJBQWMsR0FBRyxNQUFNLENBQUMsWUFBWSxFQUFFLEVBQUMsUUFBUSxFQUFFLElBQUksRUFBQyxDQUFDLENBQUM7UUFFaEUsNkNBQTZDO1FBQzF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