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

Method ngAfterContentInit

src/material/menu/menu.ts:290–327  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

288 }
289
290 ngAfterContentInit() {
291 this._updateDirectDescendants();
292 this._keyManager = new FocusKeyManager(this._directDescendantItems)
293 .withWrap()
294 .withTypeAhead()
295 .withHomeAndEnd()
296 .skipPredicate(item => item.disabled && !item.disabledInteractive);
297
298 this._keyManager.tabOut.subscribe(() => this.closed.emit('tab'));
299
300 // If a user manually (programmatically) focuses a menu item, we need to reflect that focus
301 // change back to the key manager. Note that we don't need to unsubscribe here because _focused
302 // is internal and we know that it gets completed on destroy.
303 this._directDescendantItems.changes
304 .pipe(
305 startWith(this._directDescendantItems),
306 switchMap(items => merge(...items.map((item: MatMenuItem) => item._focused))),
307 )
308 .subscribe(focusedItem => this._keyManager.updateActiveItem(focusedItem as MatMenuItem));
309
310 this._directDescendantItems.changes.subscribe((itemsList: QueryList<MatMenuItem>) => {
311 // Move focus to another item, if the active item is removed from the list.
312 // We need to debounce the callback, because multiple items might be removed
313 // in quick succession.
314 const manager = this._keyManager;
315
316 if (this._panelAnimationState === 'enter' && manager.activeItem?._hasFocus()) {
317 const items = itemsList.toArray();
318 const index = Math.max(0, Math.min(items.length - 1, manager.activeItemIndex || 0));
319
320 if (items[index] && !items[index].disabled) {
321 manager.setActiveItem(index);
322 } else {
323 manager.setNextItemActive();
324 }
325 }
326 });
327 }
328
329 ngOnDestroy() {
330 this._keyManager?.destroy();

Callers

nothing calls this directly

Calls 11

skipPredicateMethod · 0.80
withHomeAndEndMethod · 0.80
withTypeAheadMethod · 0.80
withWrapMethod · 0.80
updateActiveItemMethod · 0.80
setNextItemActiveMethod · 0.80
_hasFocusMethod · 0.45
maxMethod · 0.45
minMethod · 0.45
setActiveItemMethod · 0.45

Tested by

no test coverage detected