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

Method _onSelect

src/material/select/select.ts:1225–1264  ·  view source on GitHub ↗

Invoked when an option is clicked.

(option: MatOption, isUserInput: boolean)

Source from the content-addressed store, hash-verified

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