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

Class MenuPattern

src/aria/private/menu/menu.ts:81–490  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79
80/** The menu ui pattern class. */
81export class MenuPattern<V> {
82 /** The unique ID of the menu. */
83 readonly id: SignalLike<string>;
84
85 /** The role of the menu. */
86 readonly role = () => 'menu';
87
88 /** Whether the menu is disabled. */
89 readonly disabled = () => this.inputs.disabled();
90
91 /** Whether the menu is visible. */
92 readonly visible = computed(() =>
93 this.inputs.parent() ? !!this.inputs.parent()?.expanded() : true,
94 );
95
96 /** Controls list behavior for the menu items. */
97 readonly listBehavior: List<MenuItemPattern<V>, V | undefined>;
98
99 /** Whether the menu or any of its child elements are currently focused. */
100 readonly isFocused = signal(false);
101
102 /** Whether the menu has received interaction. */
103 readonly hasBeenInteracted = signal(false);
104
105 /** Whether the menu trigger has been hovered. */
106 readonly hasBeenHovered = signal(false);
107
108 /** Items currently inside the menu. */
109 readonly items = () => this.inputs.items();
110
111 /** Timeout used to open sub-menus on hover. */
112 private _openTimeout: ReturnType<typeof setTimeout> | undefined;
113
114 /** Timeout used to close sub-menus on hover out. */
115 private _closeTimeout: ReturnType<typeof setTimeout> | undefined;
116
117 /** The tab index of the menu. */
118 readonly tabIndex = () => this.listBehavior.tabIndex();
119
120 /** Whether the menu should be focused on mouse over. */
121 readonly shouldFocus = computed(() => {
122 const root = this.root();
123
124 if (root instanceof MenuTriggerPattern) {
125 return true;
126 }
127
128 if (root instanceof MenuBarPattern || root instanceof MenuPattern) {
129 return root.isFocused();
130 }
131
132 return false;
133 });
134
135 /** The key used to expand sub-menus. */
136 private readonly _expandKey = computed(() => {
137 return this.inputs.textDirection() === 'rtl' ? 'ArrowLeft' : 'ArrowRight';
138 });

Callers

nothing calls this directly

Calls 15

nextMethod · 0.95
prevMethod · 0.95
firstMethod · 0.95
lastMethod · 0.95
triggerMethod · 0.95
closeAllMethod · 0.95
expandMethod · 0.95
collapseMethod · 0.95
computedFunction · 0.90
signalFunction · 0.90
parentMethod · 0.80
expandedMethod · 0.80

Tested by

no test coverage detected