@@ -164,7 +164,7 @@ class _SingleSelectMode extends _SelectMode {
164
164
dom.SelectElement select,
165
165
NgModel model,
166
166
this ._nullOption)
167
- : _unknownOption = new dom.OptionElement (value: '?' ),
167
+ : _unknownOption = new dom.OptionElement (value: '?' , selected : true ),
168
168
super (options, select, model);
169
169
170
170
void onViewChange (_) {
@@ -178,31 +178,37 @@ class _SingleSelectMode extends _SelectMode {
178
178
}
179
179
180
180
void onModelChange (value) {
181
- bool found = false ;
181
+ bool anySelected = false ;
182
+ var optionsToUnselect = [];
182
183
_forEachOption ((option, i) {
183
- if (option == _unknownOption) return ;
184
+ if (identical ( option, _unknownOption) ) return ;
184
185
var selected;
185
186
if (value == null ) {
186
- selected = option == _nullOption;
187
+ selected = identical ( option, _nullOption) ;
187
188
} else {
188
189
OptionValue optionValue = options[option];
189
190
selected = optionValue == null ? false : optionValue.ngValue == value;
190
191
}
191
- found = found || selected;
192
+ anySelected = anySelected || selected;
192
193
option.selected = selected;
194
+ if (! selected) optionsToUnselect.add (option);
193
195
});
194
196
195
- if (! found) {
196
- if (! _unknownOptionActive) {
197
- select.insertBefore (_unknownOption, select.firstChild);
198
- _unknownOption.selected = true ;
199
- _unknownOptionActive = true ;
200
- }
201
- } else {
202
- if (_unknownOptionActive) {
197
+ if (anySelected) {
198
+ if (_unknownOptionActive == true ) {
203
199
_unknownOption.remove ();
204
200
_unknownOptionActive = false ;
205
201
}
202
+ } else {
203
+ if (_unknownOptionActive == false ) {
204
+ _unknownOptionActive = true ;
205
+ select.insertBefore (_unknownOption, select.firstChild);
206
+ }
207
+ // It seems that IE do not allow having no option selected. It could then happen that an
208
+ // option remains selected after the previous loop. Also IE does not enforce that only one
209
+ // option is selected so we un-select options again to end up with a single selection.
210
+ _unknownOption.selected = true ;
211
+ for (var option in optionsToUnselect) option.selected = false ;
206
212
}
207
213
}
208
214
}
0 commit comments