/** * @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, ElementRef, EventEmitter, inject, Input, NgZone, Output, } from '@angular/core'; import { coerceBooleanProperty } from '@angular/cdk/coercion'; import { InputModalityDetector } from '@angular/cdk/a11y'; import { ENTER, hasModifierKey, LEFT_ARROW, RIGHT_ARROW, SPACE } from '@angular/cdk/keycodes'; import { Directionality } from '@angular/cdk/bidi'; import { fromEvent, Subject } from 'rxjs'; import { filter, takeUntil } from 'rxjs/operators'; import { CdkMenuTrigger } from './menu-trigger'; import { CDK_MENU } from './menu-interface'; import { MENU_STACK } from './menu-stack'; import { MENU_AIM } from './menu-aim'; import { eventDispatchesNativeClick } from './event-detection'; import * as i0 from "@angular/core"; /** * Directive which provides the ability for an element to be focused and navigated to using the * keyboard when residing in a CdkMenu, CdkMenuBar, or CdkMenuGroup. It performs user defined * behavior when clicked. */ export class CdkMenuItem { /** Whether the CdkMenuItem is disabled - defaults to false */ get disabled() { return this._disabled; } set disabled(value) { this._disabled = coerceBooleanProperty(value); } /** Whether the menu item opens a menu. */ get hasMenu() { return this._menuTrigger?.menuTemplateRef != null; } constructor() { this._dir = inject(Directionality, { optional: true }); this._elementRef = inject(ElementRef); this._ngZone = inject(NgZone); this._inputModalityDetector = inject(InputModalityDetector); /** The menu aim service used by this menu. */ this._menuAim = inject(MENU_AIM, { optional: true }); /** The stack of menus this menu belongs to. */ this._menuStack = inject(MENU_STACK); /** The parent menu in which this menuitem resides. */ this._parentMenu = inject(CDK_MENU, { optional: true }); /** Reference to the CdkMenuItemTrigger directive if one is added to the same element */ this._menuTrigger = inject(CdkMenuTrigger, { optional: true, self: true }); this._disabled = false; /** * If this MenuItem is a regular MenuItem, outputs when it is triggered by a keyboard or mouse * event. */ this.triggered = new EventEmitter(); /** * The tabindex for this menu item managed internally and used for implementing roving a * tab index. */ this._tabindex = -1; /** Whether the item should close the menu if triggered by the spacebar. */ this.closeOnSpacebarTrigger = true; /** Emits when the menu item is destroyed. */ this.destroyed = new Subject(); this._setupMouseEnter(); this._setType(); if (this._isStandaloneItem()) { this._tabindex = 0; } } ngOnDestroy() { this.destroyed.next(); this.destroyed.complete(); } /** Place focus on the element. */ focus() { this._elementRef.nativeElement.focus(); } /** * If the menu item is not disabled and the element does not have a menu trigger attached, emit * on the cdkMenuItemTriggered emitter and close all open menus. * @param options Options the configure how the item is triggered * - keepOpen: specifies that the menu should be kept open after triggering the item. */ trigger(options) { const { keepOpen } = { ...options }; if (!this.disabled && !this.hasMenu) { this.triggered.next(); if (!keepOpen) { this._menuStack.closeAll({ focusParentTrigger: true }); } } } /** Return true if this MenuItem has an attached menu and it is open. */ isMenuOpen() { return !!this._menuTrigger?.isOpen(); } /** * Get a reference to the rendered Menu if the Menu is open and it is visible in the DOM. * @return the menu if it is open, otherwise undefined. */ getMenu() { return this._menuTrigger?.getMenu(); } /** Get the CdkMenuTrigger associated with this element. */ getMenuTrigger() { return this._menuTrigger; } /** Get the label for this element which is required by the FocusableOption interface. */ getLabel() { return this.typeaheadLabel || this._elementRef.nativeElement.textContent?.trim() || ''; } /** Reset the tabindex to -1. */ _resetTabIndex() { if (!this._isStandaloneItem()) { this._tabindex = -1; } } /** * Set the tab index to 0 if not disabled and it's a focus event, or a mouse enter if this element * is not in a menu bar. */ _setTabIndex(event) { if (this.disabled) { return; } // don't set the tabindex if there are no open sibling or parent menus if (!event || !this._menuStack.isEmpty()) { this._tabindex = 0; } } /** * Handles keyboard events for the menu item, specifically either triggering the user defined * callback or opening/closing the current menu based on whether the left or right arrow key was * pressed. * @param event the keyboard event to handle */ _onKeydown(event) { 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.trigger({ keepOpen: event.keyCode === SPACE && !this.closeOnSpacebarTrigger }); } break; case RIGHT_ARROW: if (!hasModifierKey(event)) { if (this._parentMenu && this._isParentVertical()) { if (this._dir?.value !== 'rtl') { this._forwardArrowPressed(event); } else { this._backArrowPressed(event); } } } break; case LEFT_ARROW: if (!hasModifierKey(event)) { if (this._parentMenu && this._isParentVertical()) { if (this._dir?.value !== 'rtl') { this._backArrowPressed(event); } else { this._forwardArrowPressed(event); } } } break; } } /** Whether this menu item is standalone or within a menu or menu bar. */ _isStandaloneItem() { return !this._parentMenu; } /** * Handles the user pressing the back arrow key. * @param event The keyboard event. */ _backArrowPressed(event) { const parentMenu = this._parentMenu; if (this._menuStack.hasInlineMenu() || this._menuStack.length() > 1) { event.preventDefault(); this._menuStack.close(parentMenu, { focusNextOnEmpty: this._menuStack.inlineMenuOrientation() === 'horizontal' ? 1 /* FocusNext.previousItem */ : 2 /* FocusNext.currentItem */, focusParentTrigger: true, }); } } /** * Handles the user pressing the forward arrow key. * @param event The keyboard event. */ _forwardArrowPressed(event) { if (!this.hasMenu && this._menuStack.inlineMenuOrientation() === 'horizontal') { event.preventDefault(); this._menuStack.closeAll({ focusNextOnEmpty: 0 /* FocusNext.nextItem */, focusParentTrigger: true, }); } } /** * Subscribe to the mouseenter events and close any sibling menu items if this element is moused * into. */ _setupMouseEnter() { if (!this._isStandaloneItem()) { const closeOpenSiblings = () => this._ngZone.run(() => this._menuStack.closeSubMenuOf(this._parentMenu)); 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.hasMenu); }), takeUntil(this.destroyed)) .subscribe(() => { if (this._menuAim) { this._menuAim.toggle(closeOpenSiblings); } else { closeOpenSiblings(); } })); } } /** * Return true if the enclosing parent menu is configured in a horizontal orientation, false * otherwise or if no parent. */ _isParentVertical() { return this._parentMenu?.orientation === 'vertical'; } /** Sets the `type` attribute of the menu item. */ _setType() { const element = this._elementRef.nativeElement; if (element.nodeName === 'BUTTON' && !element.getAttribute('type')) { // Prevent form submissions. element.setAttribute('type', 'button'); } } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: CdkMenuItem, deps: [], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.1", type: CdkMenuItem, isStandalone: true, selector: "[cdkMenuItem]", inputs: { disabled: ["cdkMenuItemDisabled", "disabled"], typeaheadLabel: ["cdkMenuitemTypeaheadLabel", "typeaheadLabel"] }, outputs: { triggered: "cdkMenuItemTriggered" }, host: { attributes: { "role": "menuitem" }, listeners: { "blur": "_resetTabIndex()", "focus": "_setTabIndex()", "click": "trigger()", "keydown": "_onKeydown($event)" }, properties: { "tabindex": "_tabindex", "attr.aria-disabled": "disabled || null" }, classAttribute: "cdk-menu-item" }, exportAs: ["cdkMenuItem"], ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: CdkMenuItem, decorators: [{ type: Directive, args: [{ selector: '[cdkMenuItem]', exportAs: 'cdkMenuItem', standalone: true, host: { 'role': 'menuitem', 'class': 'cdk-menu-item', '[tabindex]': '_tabindex', '[attr.aria-disabled]': 'disabled || null', '(blur)': '_resetTabIndex()', '(focus)': '_setTabIndex()', '(click)': 'trigger()', '(keydown)': '_onKeydown($event)', }, }] }], ctorParameters: function () { return []; }, propDecorators: { disabled: [{ type: Input, args: ['cdkMenuItemDisabled'] }], typeaheadLabel: [{ type: Input, args: ['cdkMenuitemTypeaheadLabel'] }], triggered: [{ type: Output, args: ['cdkMenuItemTriggered'] }] } }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWVudS1pdGVtLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vc3JjL2Nkay9tZW51L21lbnUtaXRlbS50cyJdLCJuYW1lcyI6W10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GlzLl9lbGVtZW50UmVmLm5hdGl2ZUVsZW1lbnQsICdtb3VzZWVudGVyJylcbiAgICAgICAgICAucGlwZShcbiAgICAgICAgICAgIGZpbHRlcigoKSA9PiB7XG4gICAgICAgICAgICAgIHJldHVybiAoXG4gICAgICAgICAgICAgICAgLy8gU2tpcCBmYWtlIGBtb3VzZWVudGVyYCBldmVudHMgZGlzcGF0Y2hlZCBieSB0b3VjaCBkZXZpY2VzLlxuICAgICAgICAgICAgICAgIHRoaXMuX2lucHV0TW9kYWxpdHlEZXRlY3Rvci5tb3N0UmVjZW50TW9kYWxpdHkgIT09ICd0b3VjaCcgJiZcbiAgICAgICAgICAgICAgICAhdGhpcy5fbWVudVN0YWNrLmlzRW1wdHkoKSAmJlxuICAgICAgICAgICAgICAgICF0aGlzLmhhc01lbnVcbiAgICAgICAgICAgICAgKTtcbiAgICAgICAgICAgIH0pLFxuICAgICAgICAgICAgdGFrZVVudGlsKHRoaXMuZGVzdHJveWVkKSxcbiAgICAgICAgICApXG4gICAgICAgICAgLnN1YnNjcmliZSgoKSA9PiB7XG4gICAgICAgICAgICBpZiAodGhpcy5fbWVudUFpbSkge1xuICAgICAgICAgICAgICB0aGlzLl9tZW51QWltLnRvZ2dsZShjbG9zZU9wZW5TaWJsaW5ncyk7XG4gICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICBjbG9zZU9wZW5TaWJsaW5ncygpO1xuICAgICAgICAgICAgfVxuICAgICAgICAgIH0pLFxuICAgICAgKTtcbiAgICB9XG4gIH1cblxuICAvKipcbiAgICogUmV0dXJuIHRydWUgaWYgdGhlIGVuY2xvc2luZyBwYXJlbnQgbWVudSBpcyBjb25maWd1cmVkIGluIGEgaG9yaXpvbnRhbCBvcmllbnRhdGlvbiwgZmFsc2VcbiAgICogb3RoZXJ3aXNlIG9yIGlmIG5vIHBhcmVudC5cbiAgICovXG4gIHByaXZhdGUgX2lzUGFyZW50VmVydGljYWwoKSB7XG4gICAgcmV0dXJuIHRo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