/** * @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 { ChangeDetectorRef, Directive, ElementRef, inject, NgZone } from '@angular/core'; import { InputModalityDetector } from '@angular/cdk/a11y'; import { Directionality } from '@angular/cdk/bidi'; import { Overlay, OverlayConfig, STANDARD_DROPDOWN_ADJACENT_POSITIONS, STANDARD_DROPDOWN_BELOW_POSITIONS, } from '@angular/cdk/overlay'; import { DOWN_ARROW, ENTER, hasModifierKey, LEFT_ARROW, RIGHT_ARROW, SPACE, UP_ARROW, } from '@angular/cdk/keycodes'; import { _getEventTarget } from '@angular/cdk/platform'; import { fromEvent } from 'rxjs'; import { filter, takeUntil } from 'rxjs/operators'; import { CDK_MENU } from './menu-interface'; import { PARENT_OR_NEW_MENU_STACK_PROVIDER } from './menu-stack'; import { MENU_AIM } from './menu-aim'; import { CdkMenuTriggerBase, MENU_TRIGGER } from './menu-trigger-base'; import { eventDispatchesNativeClick } from './event-detection'; import * as i0 from "@angular/core"; /** * A directive that turns its host element into a trigger for a popup menu. * It can be combined with cdkMenuItem to create sub-menus. If the element is in a top level * MenuBar it will open the menu on click, or if a sibling is already opened it will open on hover. * If it is inside of a Menu it will open the attached Submenu on hover regardless of its sibling * state. */ export class CdkMenuTrigger extends CdkMenuTriggerBase { constructor() { super(); this._elementRef = inject(ElementRef); this._overlay = inject(Overlay); this._ngZone = inject(NgZone); this._changeDetectorRef = inject(ChangeDetectorRef); this._inputModalityDetector = inject(InputModalityDetector); this._directionality = inject(Directionality, { optional: true }); /** The parent menu this trigger belongs to. */ this._parentMenu = inject(CDK_MENU, { optional: true }); /** The menu aim service used by this menu. */ this._menuAim = inject(MENU_AIM, { optional: true }); this._setRole(); this._registerCloseHandler(); this._subscribeToMenuStackClosed(); this._subscribeToMouseEnter(); this._subscribeToMenuStackHasFocus(); this._setType(); } /** Toggle the attached menu. */ toggle() { this.isOpen() ? this.close() : this.open(); } /** Open the attached menu. */ open() { if (!this.isOpen() && this.menuTemplateRef != null) { this.opened.next(); this.overlayRef = this.overlayRef || this._overlay.create(this._getOverlayConfig()); this.overlayRef.attach(this.getMenuContentPortal()); this._changeDetectorRef.markForCheck(); this._subscribeToOutsideClicks(); } } /** Close the opened menu. */ close() { if (this.isOpen()) { this.closed.next(); this.overlayRef.detach(); this._changeDetectorRef.markForCheck(); } this._closeSiblingTriggers(); } /** * Get a reference to the rendered Menu if the Menu is open and rendered in the DOM. */ getMenu() { return this.childMenu; } /** * Handles keyboard events for the menu item. * @param event The keyboard event to handle */ _toggleOnKeydown(event) { const isParentVertical = this._parentMenu?.orientation === 'vertical'; switch (event.keyCode) { case SPACE: case ENTER: // Skip events that will trigger clicks so the handler doesn't get triggered twice. if (!hasModifierKey(event) && !eventDispatchesNativeClick(this._elementRef, event)) { this.toggle(); this.childMenu?.focusFirstItem('keyboard'); } break; case RIGHT_ARROW: if (!hasModifierKey(event)) { if (this._parentMenu && isParentVertical && this._directionality?.value !== 'rtl') { event.preventDefault(); this.open(); this.childMenu?.focusFirstItem('keyboard'); } } break; case LEFT_ARROW: if (!hasModifierKey(event)) { if (this._parentMenu && isParentVertical && this._directionality?.value === 'rtl') { event.preventDefault(); this.open(); this.childMenu?.focusFirstItem('keyboard'); } } break; case DOWN_ARROW: case UP_ARROW: if (!hasModifierKey(event)) { if (!isParentVertical) { event.preventDefault(); this.open(); event.keyCode === DOWN_ARROW ? this.childMenu?.focusFirstItem('keyboard') : this.childMenu?.focusLastItem('keyboard'); } } break; } } /** Handles clicks on the menu trigger. */ _handleClick() { this.toggle(); this.childMenu?.focusFirstItem('mouse'); } /** * Sets whether the trigger's menu stack has focus. * @param hasFocus Whether the menu stack has focus. */ _setHasFocus(hasFocus) { if (!this._parentMenu) { this.menuStack.setHasFocus(hasFocus); } } /** * Subscribe to the mouseenter events and close any sibling menu items if this element is moused * into. */ _subscribeToMouseEnter() { this._ngZone.runOutsideAngular(() => { fromEvent(this._elementRef.nativeElement, 'mouseenter') .pipe(filter(() => { return ( // Skip fake `mouseenter` events dispatched by touch devices. this._inputModalityDetector.mostRecentModality !== 'touch' && !this.menuStack.isEmpty() && !this.isOpen()); }), takeUntil(this.destroyed)) .subscribe(() => { // Closes any sibling menu items and opens the menu associated with this trigger. const toggleMenus = () => this._ngZone.run(() => { this._closeSiblingTriggers(); this.open(); }); if (this._menuAim) { this._menuAim.toggle(toggleMenus); } else { toggleMenus(); } }); }); } /** Close out any sibling menu trigger menus. */ _closeSiblingTriggers() { if (this._parentMenu) { // If nothing was removed from the stack and the last element is not the parent item // that means that the parent menu is a menu bar since we don't put the menu bar on the // stack const isParentMenuBar = !this.menuStack.closeSubMenuOf(this._parentMenu) && this.menuStack.peek() !== this._parentMenu; if (isParentMenuBar) { this.menuStack.closeAll(); } } else { this.menuStack.closeAll(); } } /** Get the configuration object used to create the overlay. */ _getOverlayConfig() { return new OverlayConfig({ positionStrategy: this._getOverlayPositionStrategy(), scrollStrategy: this._overlay.scrollStrategies.reposition(), direction: this._directionality || undefined, }); } /** Build the position strategy for the overlay which specifies where to place the menu. */ _getOverlayPositionStrategy() { return this._overlay .position() .flexibleConnectedTo(this._elementRef) .withLockedPosition() .withGrowAfterOpen() .withPositions(this._getOverlayPositions()); } /** Get the preferred positions for the opened menu relative to the menu item. */ _getOverlayPositions() { return (this.menuPosition ?? (!this._parentMenu || this._parentMenu.orientation === 'horizontal' ? STANDARD_DROPDOWN_BELOW_POSITIONS : STANDARD_DROPDOWN_ADJACENT_POSITIONS)); } /** * Subscribe to the MenuStack close events if this is a standalone trigger and close out the menu * this triggers when requested. */ _registerCloseHandler() { if (!this._parentMenu) { this.menuStack.closed.pipe(takeUntil(this.destroyed)).subscribe(({ item }) => { if (item === this.childMenu) { this.close(); } }); } } /** * Subscribe to the overlays outside pointer events stream and handle closing out the stack if a * click occurs outside the menus. */ _subscribeToOutsideClicks() { if (this.overlayRef) { this.overlayRef .outsidePointerEvents() .pipe(takeUntil(this.stopOutsideClicksListener)) .subscribe(event => { const target = _getEventTarget(event); const element = this._elementRef.nativeElement; if (target !== element && !element.contains(target)) { if (!this.isElementInsideMenuStack(target)) { this.menuStack.closeAll(); } else { this._closeSiblingTriggers(); } } }); } } /** Subscribe to the MenuStack hasFocus events. */ _subscribeToMenuStackHasFocus() { if (!this._parentMenu) { this.menuStack.hasFocus.pipe(takeUntil(this.destroyed)).subscribe(hasFocus => { if (!hasFocus) { this.menuStack.closeAll(); } }); } } /** Subscribe to the MenuStack closed events. */ _subscribeToMenuStackClosed() { if (!this._parentMenu) { this.menuStack.closed.subscribe(({ focusParentTrigger }) => { if (focusParentTrigger && !this.menuStack.length()) { this._elementRef.nativeElement.focus(); } }); } } /** Sets the role attribute for this trigger if needed. */ _setRole() { // If this trigger is part of another menu, the cdkMenuItem directive will handle setting the // role, otherwise this is a standalone trigger, and we should ensure it has role="button". if (!this._parentMenu) { this._elementRef.nativeElement.setAttribute('role', 'button'); } } /** Sets thte `type` attribute of the trigger. */ _setType() { const element = this._elementRef.nativeElement; if (element.nodeName === 'BUTTON' && !element.getAttribute('type')) { // Prevents form submissions. element.setAttribute('type', 'button'); } } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: CdkMenuTrigger, deps: [], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.1", type: CdkMenuTrigger, isStandalone: true, selector: "[cdkMenuTriggerFor]", inputs: { menuTemplateRef: ["cdkMenuTriggerFor", "menuTemplateRef"], menuPosition: ["cdkMenuPosition", "menuPosition"], menuData: ["cdkMenuTriggerData", "menuData"] }, outputs: { opened: "cdkMenuOpened", closed: "cdkMenuClosed" }, host: { listeners: { "focusin": "_setHasFocus(true)", "focusout": "_setHasFocus(false)", "keydown": "_toggleOnKeydown($event)", "click": "_handleClick()" }, properties: { "attr.aria-haspopup": "menuTemplateRef ? \"menu\" : null", "attr.aria-expanded": "menuTemplateRef == null ? null : isOpen()" }, classAttribute: "cdk-menu-trigger" }, providers: [ { provide: MENU_TRIGGER, useExisting: CdkMenuTrigger }, PARENT_OR_NEW_MENU_STACK_PROVIDER, ], exportAs: ["cdkMenuTriggerFor"], usesInheritance: true, ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: CdkMenuTrigger, decorators: [{ type: Directive, args: [{ selector: '[cdkMenuTriggerFor]', exportAs: 'cdkMenuTriggerFor', standalone: true, host: { 'class': 'cdk-menu-trigger', '[attr.aria-haspopup]': 'menuTemplateRef ? "menu" : null', '[attr.aria-expanded]': 'menuTemplateRef == null ? null : isOpen()', '(focusin)': '_setHasFocus(true)', '(focusout)': '_setHasFocus(false)', '(keydown)': '_toggleOnKeydown($event)', '(click)': '_handleClick()', }, inputs: [ 'menuTemplateRef: cdkMenuTriggerFor', 'menuPosition: cdkMenuPosition', 'menuData: cdkMenuTriggerData', ], outputs: ['opened: cdkMenuOpened', 'closed: cdkMenuClosed'], providers: [ { provide: MENU_TRIGGER, useExisting: CdkMenuTrigger }, PARENT_OR_NEW_MENU_STACK_PROVIDER, ], }] }], ctorParameters: function () { return []; } }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVudS10cmlnZ2VyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vc3JjL2Nkay9tZW51L21lbnUtdHJpZ2dlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7QUFFSCxPQUFPLEVBQUMsaUJBQWlCLEVBQUUsU0FBUyxFQUFFLFVBQVUsRUFBRSxNQUFNLEVBQUUsTUFBTSxFQUFZLE1BQU0sZUFBZSxDQUFDO0FBQ2xHLE9BQU8sRUFBQyxxQkFBcUIsRUFBQyxNQUFNLG1CQUFtQixDQUFDO0FBQ3hELE9BQU8sRUFBQy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ZW50KHRoaXMuX2VsZW1lbnRSZWYubmF0aXZlRWxlbWVudCwgJ21vdXNlZW50ZXInKVxuICAgICAgICAucGlwZShcbiAgICAgICAgICBmaWx0ZXIoKCkgPT4ge1xuICAgICAgICAgICAgcmV0dXJuIChcbiAgICAgICAgICAgICAgLy8gU2tpcCBmYWtlIGBtb3VzZWVudGVyYCBldmVudHMgZGlzcGF0Y2hlZCBieSB0b3VjaCBkZXZpY2VzLlxuICAgICAgICAgICAgICB0aGlzLl9pbnB1dE1vZGFsaXR5RGV0ZWN0b3IubW9zdFJlY2VudE1vZGFsaXR5ICE9PSAndG91Y2gnICYmXG4gICAgICAgICAgICAgICF0aGlzLm1lbnVTdGFjay5pc0VtcHR5KCkgJiZcbiAgICAgICAgICAgICAgIXRoaXMuaXNPcGVuKClcbiAgICAgICAgICAgICk7XG4gICAgICAgICAgfSksXG4gICAgICAgICAgdGFrZVVudGlsKHRoaXMuZGVzdHJveWVkKSxcbiAgICAgICAgKVxuICAgICAgICAuc3Vic2NyaWJlKCgpID0+IHtcbiAgICAgICAgICAvLyBDbG9zZXMgYW55IHNpYmxpbmcgbWVudSBpdGVtcyBhbmQgb3BlbnMgdGhlIG1lbnUgYXNzb2NpYXRlZCB3aXRoIHRoaXMgdHJpZ2dlci5cbiAgICAgICAgICBjb25zdCB0b2dnbGVNZW51cyA9ICgpID0+XG4gICAgICAgICAgICB0aGlzLl9uZ1pvbmUucnVuKCgpID0+IHtcbiAgICAgICAgICAgICAgdGhpcy5fY2xvc2VTaWJsaW5nVHJpZ2dlcnMoKTtcbiAgICAgICAgICAgICAgdGhpcy5vcGVuKCk7XG4gICAgICAgICAgICB9KTtcblxuICAgICAgICAgIGlmICh0aGlzLl9tZW51QWltKSB7XG4gICAgICAgICAgICB0aGlzLl9tZW51QWltLnRvZ2dsZSh0b2dnbGVNZW51cyk7XG4gICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRvZ2dsZU1lbnVzKCk7XG4gICAgICAgICAg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