|
4 | 4 |
|
5 | 5 | var noopNgModelController = { $setViewValue: noop, $render: noop };
|
6 | 6 |
|
| 7 | +function setOptionAsSelected(optionEl) { |
| 8 | + optionEl.prop('selected', true); // needed for IE |
| 9 | + optionEl.attr('selected', true); |
| 10 | +} |
| 11 | + |
7 | 12 | /**
|
8 | 13 | * @ngdoc type
|
9 | 14 | * @name select.SelectController
|
@@ -292,11 +297,6 @@ var SelectController =
|
292 | 297 | }
|
293 | 298 | });
|
294 | 299 | };
|
295 |
| - |
296 |
| - function setOptionAsSelected(optionEl) { |
297 |
| - optionEl.prop('selected', true); // needed for IE |
298 |
| - optionEl.attr('selected', true); |
299 |
| - } |
300 | 300 | }];
|
301 | 301 |
|
302 | 302 | /**
|
@@ -611,11 +611,18 @@ var selectDirective = function() {
|
611 | 611 | includes(value, selectCtrl.selectValueMap[option.value]));
|
612 | 612 | var currentlySelected = option.selected;
|
613 | 613 |
|
614 |
| - // IE and Edge will de-select selected options when you set the selected property again, e.g. |
615 |
| - // when you add to the selection via shift+click/UP/DOWN |
616 |
| - // Therefore, only set it if necessary |
617 |
| - if ((shouldBeSelected && !currentlySelected) || (!shouldBeSelected && currentlySelected)) { |
618 |
| - option.selected = shouldBeSelected; |
| 614 | + // IE and Edge, adding options to the selection via shift+click/UP/DOWN, |
| 615 | + // will de-select already selected options if "selected" on those options was set |
| 616 | + // more than once (i.e. when the options were already selected) |
| 617 | + // So we only modify the selected property if neccessary. |
| 618 | + // Note: this behavior cannot be replicated via unit tests because it only shows in the |
| 619 | + // actual user interface. |
| 620 | + if ((shouldBeSelected && !currentlySelected)) { |
| 621 | + setOptionAsSelected(jqLite(option)); |
| 622 | + } else if ((!shouldBeSelected && currentlySelected)) { |
| 623 | + option.selected = shouldBeSelected; |
| 624 | + // Remove attribute to not confuse screen readers |
| 625 | + option.removeAttribute('selected'); |
619 | 626 | }
|
620 | 627 |
|
621 | 628 | });
|
|
0 commit comments