/** * @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 { CdkMenuGroup } from './menu-group'; import { ContentChildren, Directive, ElementRef, inject, Input, NgZone, QueryList, } from '@angular/core'; import { FocusKeyManager } from '@angular/cdk/a11y'; import { CdkMenuItem } from './menu-item'; import { merge, Subject } from 'rxjs'; import { Directionality } from '@angular/cdk/bidi'; import { mapTo, mergeAll, mergeMap, startWith, switchMap, takeUntil } from 'rxjs/operators'; import { MENU_STACK } from './menu-stack'; import { PointerFocusTracker } from './pointer-focus-tracker'; import { MENU_AIM } from './menu-aim'; import * as i0 from "@angular/core"; /** Counter used to create unique IDs for menus. */ let nextId = 0; /** * Abstract directive that implements shared logic common to all menus. * This class can be extended to create custom menu types. */ export class CdkMenuBase extends CdkMenuGroup { constructor() { super(...arguments); /** The menu's native DOM host element. */ this.nativeElement = inject(ElementRef).nativeElement; /** The Angular zone. */ this.ngZone = inject(NgZone); /** The stack of menus this menu belongs to. */ this.menuStack = inject(MENU_STACK); /** The menu aim service used by this menu. */ this.menuAim = inject(MENU_AIM, { optional: true, self: true }); /** The directionality (text direction) of the current page. */ this.dir = inject(Directionality, { optional: true }); /** The id of the menu's host element. */ this.id = `cdk-menu-${nextId++}`; /** 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 = false; /** Emits when the MenuBar is destroyed. */ this.destroyed = new Subject(); /** Whether this menu's menu stack has focus. */ this._menuStackHasFocus = false; } ngAfterContentInit() { if (!this.isInline) { this.menuStack.push(this); } this._setKeyManager(); this._subscribeToMenuStackHasFocus(); this._subscribeToMenuOpen(); this._subscribeToMenuStackClosed(); this._setUpPointerTracker(); } ngOnDestroy() { this.keyManager?.destroy(); this.destroyed.next(); this.destroyed.complete(); this.pointerTracker?.destroy(); } /** * Place focus on the first MenuItem in the menu and set the focus origin. * @param focusOrigin The origin input mode of the focus event. */ focusFirstItem(focusOrigin = 'program') { this.keyManager.setFocusOrigin(focusOrigin); this.keyManager.setFirstItemActive(); } /** * Place focus on the last MenuItem in the menu and set the focus origin. * @param focusOrigin The origin input mode of the focus event. */ focusLastItem(focusOrigin = 'program') { this.keyManager.setFocusOrigin(focusOrigin); this.keyManager.setLastItemActive(); } /** Gets the tabindex for this menu. */ _getTabIndex() { const tabindexIfInline = this._menuStackHasFocus ? -1 : 0; return this.isInline ? tabindexIfInline : null; } /** * Close the open menu if the current active item opened the requested MenuStackItem. * @param menu The menu requested to be closed. * @param options Options to configure the behavior on close. * - `focusParentTrigger` Whether to focus the parent trigger after closing the menu. */ closeOpenMenu(menu, options) { const { focusParentTrigger } = { ...options }; const keyManager = this.keyManager; const trigger = this.triggerItem; if (menu === trigger?.getMenuTrigger()?.getMenu()) { trigger?.getMenuTrigger()?.close(); // If the user has moused over a sibling item we want to focus the element under mouse focus // not the trigger which previously opened the now closed menu. if (focusParentTrigger) { if (trigger) { keyManager.setActiveItem(trigger); } else { keyManager.setFirstItemActive(); } } } } /** Setup the FocusKeyManager with the correct orientation for the menu. */ _setKeyManager() { this.keyManager = new FocusKeyManager(this.items).withWrap().withTypeAhead().withHomeAndEnd(); if (this.orientation === 'horizontal') { this.keyManager.withHorizontalOrientation(this.dir?.value || 'ltr'); } else { this.keyManager.withVerticalOrientation(); } } /** * Subscribe to the menu trigger's open events in order to track the trigger which opened the menu * and stop tracking it when the menu is closed. */ _subscribeToMenuOpen() { const exitCondition = merge(this.items.changes, this.destroyed); this.items.changes .pipe(startWith(this.items), mergeMap((list) => list .filter(item => item.hasMenu) .map(item => item.getMenuTrigger().opened.pipe(mapTo(item), takeUntil(exitCondition)))), mergeAll(), switchMap((item) => { this.triggerItem = item; return item.getMenuTrigger().closed; }), takeUntil(this.destroyed)) .subscribe(() => (this.triggerItem = undefined)); } /** Subscribe to the MenuStack close events. */ _subscribeToMenuStackClosed() { this.menuStack.closed .pipe(takeUntil(this.destroyed)) .subscribe(({ item, focusParentTrigger }) => this.closeOpenMenu(item, { focusParentTrigger })); } /** Subscribe to the MenuStack hasFocus events. */ _subscribeToMenuStackHasFocus() { if (this.isInline) { this.menuStack.hasFocus.pipe(takeUntil(this.destroyed)).subscribe(hasFocus => { this._menuStackHasFocus = hasFocus; }); } } /** * Set the PointerFocusTracker and ensure that when mouse focus changes the key manager is updated * with the latest menu item under mouse focus. */ _setUpPointerTracker() { if (this.menuAim) { this.ngZone.runOutsideAngular(() => { this.pointerTracker = new PointerFocusTracker(this.items); }); this.menuAim.initialize(this, this.pointerTracker); } } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: CdkMenuBase, deps: null, target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.1", type: CdkMenuBase, inputs: { id: "id" }, host: { attributes: { "role": "menu" }, listeners: { "focus": "focusFirstItem()", "focusin": "menuStack.setHasFocus(true)", "focusout": "menuStack.setHasFocus(false)" }, properties: { "tabindex": "_getTabIndex()", "id": "id", "attr.aria-orientation": "orientation", "attr.data-cdk-menu-stack-id": "menuStack.id" } }, queries: [{ propertyName: "items", predicate: CdkMenuItem, descendants: true }], usesInheritance: true, ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: CdkMenuBase, decorators: [{ type: Directive, args: [{ host: { 'role': 'menu', 'class': '', '[tabindex]': '_getTabIndex()', '[id]': 'id', '[attr.aria-orientation]': 'orientation', '[attr.data-cdk-menu-stack-id]': 'menuStack.id', '(focus)': 'focusFirstItem()', '(focusin)': 'menuStack.setHasFocus(true)', '(focusout)': 'menuStack.setHasFocus(false)', }, }] }], propDecorators: { id: [{ type: Input }], items: [{ type: ContentChildren, args: [CdkMenuItem, { descendants: true }] }] } }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWV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