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

Class MenuTrigger

src/aria/menu/menu-trigger.ts:57–112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55 },
56})
57export class MenuTrigger<V> {
58 /** A reference to the host element. */
59 private readonly _elementRef = inject(ElementRef);
60
61 /** A reference to the host element. */
62 readonly element = this._elementRef.nativeElement as HTMLElement;
63
64 /** The directionality (LTR / RTL) context for the application (or a subtree of it). */
65 readonly textDirection = inject(Directionality).valueSignal;
66
67 /** The menu associated with the trigger. */
68 readonly menu = input<Menu<V> | undefined>(undefined);
69
70 /** Whether the menu is expanded. */
71 readonly expanded = computed(() => this._pattern.expanded());
72
73 /** Whether the menu trigger has a popup. */
74 readonly hasPopup = computed(() => this._pattern.hasPopup());
75
76 /** Whether the menu trigger is disabled. */
77 readonly disabled = input(false, {transform: booleanAttribute});
78
79 /** Whether the menu trigger is soft disabled. */
80 readonly softDisabled = input(true, {transform: booleanAttribute});
81
82 /** Tab index of the menu trigger. */
83 readonly tabIndex = computed(() => this._pattern.tabIndex());
84
85 /** The menu trigger ui pattern instance. */
86 readonly _pattern: MenuTriggerPattern<V> = new MenuTriggerPattern({
87 textDirection: this.textDirection,
88 element: computed(() => this._elementRef.nativeElement),
89 menu: computed(() => this.menu()?._pattern),
90 disabled: () => this.disabled(),
91 });
92
93 constructor() {
94 effect(() => this.menu()?.parent.set(this));
95 effect(() => this._pattern.pendingFocusEffect());
96
97 // Automatically prevent form submission.
98 if (this.element.tagName === 'BUTTON' && !this.element.hasAttribute('type')) {
99 this.element.setAttribute('type', 'button');
100 }
101 }
102
103 /** Opens the menu focusing on the first menu item. */
104 open() {
105 this._pattern.open({first: true});
106 }
107
108 /** Closes the menu. */
109 close() {
110 this._pattern.close();
111 }
112}

Callers

nothing calls this directly

Calls 6

inputFunction · 0.85
computedFunction · 0.85
expandedMethod · 0.80
tabIndexMethod · 0.45
menuMethod · 0.45
disabledMethod · 0.45

Tested by

no test coverage detected