* Sets the selected option based on a value. If no option can be * found with the designated value, the select trigger is cleared.
(value: any | any[])
| 1034 | * found with the designated value, the select trigger is cleared. |
| 1035 | */ |
| 1036 | private _setSelectionByValue(value: any | any[]): void { |
| 1037 | this.options.forEach(option => option.setInactiveStyles()); |
| 1038 | this._selectionModel.clear(); |
| 1039 | |
| 1040 | if (this.multiple && value) { |
| 1041 | if (!Array.isArray(value) && (typeof ngDevMode === 'undefined' || ngDevMode)) { |
| 1042 | throw getMatSelectNonArrayValueError(); |
| 1043 | } |
| 1044 | |
| 1045 | value.forEach((currentValue: any) => this._selectOptionByValue(currentValue)); |
| 1046 | this._sortValues(); |
| 1047 | } else { |
| 1048 | const correspondingOption = this._selectOptionByValue(value); |
| 1049 | |
| 1050 | // Shift focus to the active item. Note that we shouldn't do this in multiple |
| 1051 | // mode, because we don't know what option the user interacted with last. |
| 1052 | if (correspondingOption) { |
| 1053 | this._keyManager.updateActiveItem(correspondingOption); |
| 1054 | } else if (!this.panelOpen) { |
| 1055 | // Otherwise reset the highlighted option. Note that we only want to do this while |
| 1056 | // closed, because doing it while open can shift the user's focus unnecessarily. |
| 1057 | this._keyManager.updateActiveItem(-1); |
| 1058 | } |
| 1059 | } |
| 1060 | |
| 1061 | this._changeDetectorRef.markForCheck(); |
| 1062 | } |
| 1063 | |
| 1064 | /** |
| 1065 | * Finds and selects and option based on its value. |
no test coverage detected