iron-selector icon indicating copy to clipboard operation
iron-selector copied to clipboard

Selected element not updated when DOM elements are reordered

Open sklobovskaya opened this issue 9 years ago • 0 comments

Description

When the selectable elements in an iron-selector are reordered, the selected element is not updated.

Demo and steps to reproduce

http://jsbin.com/huyupeh/edit?html,js,output

  1. Open the demo above, which contains an iron-selector and a dom-repeat inside, which generates a list of selectable items from an array, using attrForSelected to identify each item's value.
  2. Click the 'Change order' button. This will reset the dom-repeat array with a brand new list of items, containing the same number of items with the same values, but in a different order.
  3. Observe the currently-selected item in the list.

Actual outcome

The second item in the list remains selected even as the order of the items is changed and the second item's value is now "four", not "two".

Expected outcome

The item with the name "two" should be selected, since the selected value "two" did not change and there is still a valid item with this value in the list.

I believe this is happening because a simple re-ordering of the dom-repeat array only results in the attrForSelected attribute values being updated, with no DOM nodes being added or removed, so updateItems/updateSelected is not called.

sklobovskaya avatar Jul 27 '16 05:07 sklobovskaya