Initialize the key manager.
()
| 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() { |
no test coverage detected