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

Method constructor

src/aria/menu/menu.ts:152–203  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

150 readonly expansionDelay = input<number>(100); // Arbitrarily chosen.
151
152 constructor() {
153 this._pattern = new MenuPattern({
154 ...this,
155 parent: computed(() => this.parent()?._pattern),
156 items: this._itemPatterns,
157 multi: () => false,
158 focusMode: () => 'roving',
159 orientation: () => 'vertical',
160 selectionMode: () => 'explicit',
161 activeItem: signal(undefined),
162 element: computed(() => this._elementRef.nativeElement),
163 itemSelected: (value: V | undefined) => this.itemSelected.emit(value),
164 });
165
166 afterRenderEffect({
167 write: () => {
168 const parent = this.parent();
169 if (parent instanceof MenuItem && parent.parent instanceof MenuBar) {
170 this._deferredContentAware?.contentVisible.set(true);
171 } else {
172 this._deferredContentAware?.contentVisible.set(this._pattern.visible());
173 }
174 },
175 });
176
177 // Focuses an active menu item when the menu becomes visible. This is needed to
178 // properly restore focus to the active item when returning to a menu, and to
179 // focus the first item when navigating into a submenu with hover.
180 afterRenderEffect({
181 write: () => {
182 if (this.visible()) {
183 const activeItem = untracked(() => this._pattern.inputs.activeItem());
184 this._pattern.listBehavior.goto(activeItem!);
185 }
186 },
187 });
188
189 afterRenderEffect({write: () => this._pattern.setDefaultStateEffect()});
190
191 // Check for any violations after the DOM has been updated.
192 if (typeof ngDevMode === 'undefined' || ngDevMode) {
193 afterRenderEffect({
194 read: () => {
195 reportViolations(this._pattern.validate(), this.element);
196 },
197 });
198 }
199
200 afterNextRender(() => {
201 this._collection.startObserving(this.element);
202 });
203 }
204
205 ngOnDestroy() {
206 this._collection.stopObserving();

Callers

nothing calls this directly

Calls 11

reportViolationsFunction · 0.90
computedFunction · 0.85
signalFunction · 0.85
parentMethod · 0.80
setMethod · 0.80
visibleMethod · 0.80
activeItemMethod · 0.80
startObservingMethod · 0.80
gotoMethod · 0.45
setDefaultStateEffectMethod · 0.45
validateMethod · 0.45

Tested by

no test coverage detected