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

multiple select always jumps back to lowest marked element #15477

Closed
ghost opened this issue Dec 8, 2016 · 4 comments
Closed

multiple select always jumps back to lowest marked element #15477

ghost opened this issue Dec 8, 2016 · 4 comments

Comments

@ghost
Copy link

ghost commented Dec 8, 2016

Do you want to request a feature or report a bug?
Bug

What is the current behavior?

  • multiple select: In successively selecting one of the last and one of the first elements, the selector jumps back to the lowest selected element.
    I think angular background magic bred this bug.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://plnkr.co or similar (template: http://plnkr.co/edit/tpl:yBpEi4).

What is the expected behavior?

  • the select works normally without jumping.

Which versions of Angular, and which browser / OS are affected by this issue? Did this work in previous versions of Angular? Please also test with the latest stable and snapshot (https://code.angularjs.org/snapshot/) versions.

  • angularjs 1.5.6
  • Firefox / IE

Other information (e.g. stacktraces, related issues, suggestions how to fix)
sorry for my bad english, I'm from Germany.

with best regards
Sogmog

@ghost ghost changed the title multiple select jumps always to lowest marked element multiple select always jumps back to lowest marked element Dec 8, 2016
@gkalpak gkalpak added this to the Backlog milestone Dec 8, 2016
@gkalpak
Copy link
Member

gkalpak commented Dec 8, 2016

This also happens on Chrome btw.

@Narretz
Copy link
Contributor

Narretz commented Dec 8, 2016

Maybe it's because we re-set some attributes. I hope it's not because the options get re-rendered ... which shouldn't happen (haven't tested if it does)

@gkalpak
Copy link
Member

gkalpak commented Dec 8, 2016

In Chrome, it only happens if you have one element selected (e.g. select 10, then scroll back to 1, then digest). I suspect it is because of this method.

@gkalpak gkalpak self-assigned this Dec 8, 2016
gkalpak added a commit to gkalpak/angular.js that referenced this issue Dec 8, 2016
Previously, when updating the value of a `select[multiple]` element, all options
were first set to `selected = false` and then the selected ones where 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 scroll to
unexpectedly scroll to the last selected option.

This commit fixes it by ensuring that the `selected` property is set to its
final value and only if that value is different than the previous one, thus
avoiding the undesirable behavior.

Fixes angular#15477
gkalpak added a commit to gkalpak/angular.js that referenced this issue Dec 8, 2016
Previously, when updating the value of a `select[multiple]` element, all options
were first set to `selected = false` and then the selected ones where 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 scroll to
unexpectedly scroll to the last selected option.

This commit fixes it by ensuring that the `selected` property is set to its
final value and only if that value is different than the previous one, thus
avoiding the undesirable behavior.

Fixes angular#15477
gkalpak added a commit to gkalpak/angular.js that referenced this issue Dec 8, 2016
Previously, when updating the value of a `select[multiple]` element, all options
were first set to `selected = false` and then the selected ones where 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 scroll to
unexpectedly scroll to the last selected option.

This commit fixes it by ensuring that the `selected` property is set to its
final value and only if that value is different than the previous one, thus
avoiding the undesirable behavior.

Fixes angular#15477
gkalpak added a commit to gkalpak/angular.js that referenced this issue Dec 8, 2016
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 if 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 angular#15477
gkalpak added a commit to gkalpak/angular.js that referenced this issue Dec 8, 2016
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 angular#15477
@gkalpak
Copy link
Member

gkalpak commented Dec 8, 2016

Here is a demo with the fix from #15478.

gkalpak added a commit that referenced this issue Dec 19, 2016
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

Closes #15478
ellimist pushed a commit to ellimist/angular.js that referenced this issue Mar 15, 2017
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 angular#15477

Closes angular#15478
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.