Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 4385e12

Browse files
committed
fix(select): keep original selection when using shift to add options in IE/Edge
In IE9-11 + Edge, the selected options were previously incorrect under the following circumstances: - at least two options are selected - shift+click or shift+down/up is used to add to the selection (any number of options) In these cases, only the last of the previously selected options and the newly selected options would be selected. The problems seems to be that the render engine gets confused when an option that already has selected = true gets selected = true set again. Note that this is not testable via unit test because it's not possible to simulate click / keyboard events on option elements (the events are delegated to the select element change event), and the problem also doesn't appear when modifying the option elements directly and then using the selectController API. It seems that this only happens when you manipulate the select directly in the user interface. Fixes #15675 Closes #15676
1 parent ba8b924 commit 4385e12

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/ng/directive/select.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,17 @@ var selectDirective = function() {
607607
// Write value now needs to set the selected property of each matching option
608608
selectCtrl.writeValue = function writeMultipleValue(value) {
609609
forEach(element.find('option'), function(option) {
610-
option.selected = !!value && (includes(value, option.value) ||
611-
includes(value, selectCtrl.selectValueMap[option.value]));
610+
var shouldBeSelected = !!value && (includes(value, option.value) ||
611+
includes(value, selectCtrl.selectValueMap[option.value]));
612+
var currentlySelected = option.selected;
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;
619+
}
620+
612621
});
613622
};
614623

0 commit comments

Comments
 (0)