MCPcopy Create free account
hub / github.com/angular/components / CdkMenuItem

Class CdkMenuItem

src/cdk/menu/menu-item.ts:52–327  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50 },
51})
52export class CdkMenuItem implements FocusableOption, FocusableElement, Toggler, OnDestroy {
53 protected readonly _dir = inject(Directionality, {optional: true});
54 readonly _elementRef: ElementRef<HTMLElement> = inject(ElementRef);
55 protected _ngZone = inject(NgZone);
56 private readonly _inputModalityDetector = inject(InputModalityDetector);
57 private readonly _renderer = inject(Renderer2);
58 private _cleanupMouseEnter: (() => void) | undefined;
59
60 /** The menu aim service used by this menu. */
61 private readonly _menuAim = inject(MENU_AIM, {optional: true});
62
63 /** The stack of menus this menu belongs to. */
64 private readonly _menuStack = inject(MENU_STACK);
65
66 /** The parent menu in which this menuitem resides. */
67 readonly _parentMenu = inject(CDK_MENU, {optional: true});
68
69 /** Reference to the CdkMenuItemTrigger directive if one is added to the same element */
70 private readonly _menuTrigger = inject(CdkMenuTrigger, {optional: true, self: true});
71
72 /** Whether the CdkMenuItem is disabled - defaults to false */
73 @Input({alias: 'cdkMenuItemDisabled', transform: booleanAttribute}) disabled: boolean = false;
74
75 /**
76 * The text used to locate this item during menu typeahead. If not specified,
77 * the `textContent` of the item will be used.
78 */
79 @Input('cdkMenuitemTypeaheadLabel') typeaheadLabel: string | null = null;
80
81 /**
82 * If this MenuItem is a regular MenuItem, outputs when it is triggered by a keyboard or mouse
83 * event.
84 */
85 @Output('cdkMenuItemTriggered') readonly triggered: EventEmitter<void> = new EventEmitter();
86
87 /** Whether the menu item opens a menu. */
88 get hasMenu() {
89 return this._menuTrigger?.menuTemplateRef != null;
90 }
91
92 /**
93 * The tabindex for this menu item managed internally and used for implementing roving a
94 * tab index.
95 */
96 _tabindex: 0 | -1 = -1;
97
98 /** Whether the item should close the menu if triggered by the spacebar. */
99 protected closeOnSpacebarTrigger = true;
100
101 /** Emits when the menu item is destroyed. */
102 protected readonly destroyed = new Subject<void>();
103
104 constructor() {
105 this._setupMouseEnter();
106 this._setType();
107
108 if (this._isStandaloneItem()) {
109 this._tabindex = 0;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected