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