From 107ac8ca3c9eff90d6c969d80e6faa02a4d21336 Mon Sep 17 00:00:00 2001 From: Georgios Kalpakas Date: Thu, 8 Dec 2016 19:05:11 +0200 Subject: [PATCH 1/2] fix(ngOptions): do not unset the `selected` property unless necessary Previously, when updating the value of a `select[multiple]` element, all options were first set to `selected = false` and then the selected ones were set to `true`. By setting an already selected option to `selected = false` and then `true` again - essentially unselecting and reselecting it - caused some browsers (including Firefox, IE and under some circumstances Chrome) to unexpectedly scroll to the last selected option. This commit fixes it by ensuring that the `selected` property is only set if its current value is different than the new one and even then it is set to its final value at once (i.e. without first setting it to `false`), thus avoiding the undesirable behavior. Fixes #15477 --- src/ng/directive/ngOptions.js | 24 ++++++--- test/ng/directive/ngOptionsSpec.js | 81 ++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 8 deletions(-) diff --git a/src/ng/directive/ngOptions.js b/src/ng/directive/ngOptions.js index 7265a1f6e892..ce39d3ee4118 100644 --- a/src/ng/directive/ngOptions.js +++ b/src/ng/directive/ngOptions.js @@ -506,16 +506,16 @@ var ngOptionsDirective = ['$compile', '$document', '$parse', function($compile, } else { selectCtrl.writeValue = function writeNgOptionsMultiple(value) { + // Only set `