MCPcopy Index your code
hub / github.com/angular/components / _onSelect

Method _onSelect

src/material/select/select.ts:1223–1262  ·  view source on GitHub ↗

Invoked when an option is clicked.

(option: MatOption, isUserInput: boolean)

Source from the content-addressed store, hash-verified

1221
1222 /** Invoked when an option is clicked. */
1223 private _onSelect(option: MatOption, isUserInput: boolean): void {
1224 const wasSelected = this._selectionModel.isSelected(option);
1225
1226 if (!this.canSelectNullableOptions && option.value == null && !this._multiple) {
1227 option.deselect();
1228 this._selectionModel.clear();
1229
1230 if (this.value != null) {
1231 this._propagateChanges(option.value);
1232 }
1233 } else {
1234 if (wasSelected !== option.selected) {
1235 option.selected
1236 ? this._selectionModel.select(option)
1237 : this._selectionModel.deselect(option);
1238 }
1239
1240 if (isUserInput) {
1241 this._keyManager.setActiveItem(option);
1242 }
1243
1244 if (this.multiple) {
1245 this._sortValues();
1246
1247 if (isUserInput) {
1248 // In case the user selected the option with their mouse, we
1249 // want to restore focus back to the trigger, in order to
1250 // prevent the select keyboard controls from clashing with
1251 // the ones from `mat-option`.
1252 this.focus();
1253 }
1254 }
1255 }
1256
1257 if (wasSelected !== this._selectionModel.isSelected(option)) {
1258 this._propagateChanges();
1259 }
1260
1261 this.stateChanges.next();
1262 }
1263
1264 /** Sorts the selected values in the selected based on their order in the panel. */
1265 private _sortValues() {

Callers 1

_resetOptionsMethod · 0.95

Calls 9

_propagateChangesMethod · 0.95
_sortValuesMethod · 0.95
focusMethod · 0.95
isSelectedMethod · 0.65
deselectMethod · 0.65
clearMethod · 0.65
selectMethod · 0.65
setActiveItemMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected