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

Method _highlightCorrectOption

src/material/select/select.ts:1301–1321  ·  view source on GitHub ↗

* Highlights the selected item. If no option is selected, it will highlight * the first *enabled* option.

()

Source from the content-addressed store, hash-verified

1299 * the first *enabled* option.
1300 */
1301 private _highlightCorrectOption(): void {
1302 if (this._keyManager) {
1303 if (this.empty) {
1304 // Find the index of the first *enabled* option. Avoid calling `_keyManager.setActiveItem`
1305 // because it activates the first option that passes the skip predicate, rather than the
1306 // first *enabled* option.
1307 let firstEnabledOptionIndex = -1;
1308 for (let index = 0; index < this.options.length; index++) {
1309 const option = this.options.get(index)!;
1310 if (!option.disabled) {
1311 firstEnabledOptionIndex = index;
1312 break;
1313 }
1314 }
1315
1316 this._keyManager.setActiveItem(firstEnabledOptionIndex);
1317 } else {
1318 this._keyManager.setActiveItem(this._selectionModel.selected[0]);
1319 }
1320 }
1321 }
1322
1323 /** Whether the panel is allowed to open. */
1324 protected _canOpen(): boolean {

Callers 1

openMethod · 0.95

Calls 2

getMethod · 0.65
setActiveItemMethod · 0.45

Tested by

no test coverage detected