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

Method _initKeyManager

src/cdk/listbox/listbox.ts:856–888  ·  view source on GitHub ↗

Initialize the key manager.

()

Source from the content-addressed store, hash-verified

854
855 /** Initialize the key manager. */
856 private _initKeyManager() {
857 this.listKeyManager = new ActiveDescendantKeyManager(this.options)
858 .withWrap(!this._navigationWrapDisabled)
859 .withTypeAhead()
860 .withHomeAndEnd()
861 .withAllowedModifierKeys(['shiftKey'])
862 .skipPredicate(
863 this._navigateDisabledOptions ? this._skipNonePredicate : this._skipDisabledPredicate,
864 );
865
866 if (this.orientation === 'vertical') {
867 this.listKeyManager.withVerticalOrientation();
868 } else {
869 this.listKeyManager.withHorizontalOrientation(this._dir?.value || 'ltr');
870 }
871
872 if (this.selectionModel.selected.length) {
873 Promise.resolve().then(() => this._setNextFocusToSelectedOption());
874 }
875
876 this.listKeyManager.change.subscribe(() => this._focusActiveOption());
877
878 this.options.changes.pipe(takeUntil(this.destroyed)).subscribe(() => {
879 const activeOption = this.listKeyManager.activeItem;
880
881 // If the active option was deleted, we need to reset
882 // the key manager so it can allow focus back in.
883 if (activeOption && !this.options.find(option => option === activeOption)) {
884 this.listKeyManager.setActiveItem(-1);
885 this.changeDetectorRef.markForCheck();
886 }
887 });
888 }
889
890 /** Focus the active option. */
891 private _focusActiveOption() {

Callers 1

ngAfterContentInitMethod · 0.95

Calls 12

_focusActiveOptionMethod · 0.95
skipPredicateMethod · 0.80
withHomeAndEndMethod · 0.80
withTypeAheadMethod · 0.80
withWrapMethod · 0.80
resolveMethod · 0.80
markForCheckMethod · 0.80
setActiveItemMethod · 0.45

Tested by

no test coverage detected