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

Method _initKeyManager

src/material/select/select.ts:1164–1196  ·  view source on GitHub ↗

Sets up a key manager to listen to keyboard events on the overlay panel.

()

Source from the content-addressed store, hash-verified

1162
1163 /** Sets up a key manager to listen to keyboard events on the overlay panel. */
1164 private _initKeyManager() {
1165 this._keyManager = new ActiveDescendantKeyManager<MatOption>(this.options)
1166 .withTypeAhead(this.typeaheadDebounceInterval)
1167 .withVerticalOrientation()
1168 .withHorizontalOrientation(this._isRtl() ? 'rtl' : 'ltr')
1169 .withHomeAndEnd()
1170 .withPageUpDown()
1171 .withAllowedModifierKeys(['shiftKey'])
1172 .skipPredicate(this._skipPredicate);
1173
1174 this._keyManager.tabOut.subscribe(() => {
1175 if (this.panelOpen) {
1176 // Select the active item when tabbing away. This is consistent with how the native
1177 // select behaves. Note that we only want to do this in single selection mode.
1178 if (!this.multiple && this._keyManager.activeItem) {
1179 this._keyManager.activeItem._selectViaInteraction();
1180 }
1181
1182 // Restore focus to the trigger before closing. Ensures that the focus
1183 // position won't be lost if the user got focus into the overlay.
1184 this.focus();
1185 this.close();
1186 }
1187 });
1188
1189 this._keyManager.change.subscribe(() => {
1190 if (this._panelOpen && this.panel) {
1191 this._scrollOptionIntoView(this._keyManager.activeItemIndex || 0);
1192 } else if (!this._panelOpen && !this.multiple && this._keyManager.activeItem) {
1193 this._keyManager.activeItem._selectViaInteraction();
1194 }
1195 });
1196 }
1197
1198 /** Drops current option subscriptions and IDs and resets from scratch. */
1199 private _resetOptions(): void {

Callers 1

ngAfterContentInitMethod · 0.95

Calls 12

_isRtlMethod · 0.95
focusMethod · 0.95
closeMethod · 0.95
_scrollOptionIntoViewMethod · 0.95
skipPredicateMethod · 0.80
withPageUpDownMethod · 0.80
withHomeAndEndMethod · 0.80
withTypeAheadMethod · 0.80
_selectViaInteractionMethod · 0.80

Tested by

no test coverage detected