Invoked when an option is clicked.
(option: MatOption, isUserInput: boolean)
| 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() { |
no test coverage detected