PolymerElements / iron-selector

Manages a list of elements that can be selected
32 stars 55 forks source link

Setting a sane `selected` value when selected item is removed/replaced from the DOM #65

Open zinkkrysty opened 9 years ago

zinkkrysty commented 9 years ago

Consider a dynamic list, as it's typical in many apps. When this list changes, and the selected value doesn't exist anymore in the new list, what should it equal to afterwards?

There are 2 example cases and I am writing failing tests for both right now, but I want to start a discussion on what you think it should happen to the selected property:

  1. You use an iron-selector with attr-for-selected set to my-attr. The children are generated with a dom-repeat, and the currently selected item has my-attr=foo. You then swap the children with different ones. The initially selected value foo is no longer found in the new set of items. What is the selected item and its value?
  2. You have a list of n items (item0, item1, item2 ... itemn), and the user selects the last item (itemn). As a result to another user action, itemn gets removed from the list. What should the selected item be now?
zinkkrysty commented 9 years ago

Can someone confirm, is this actually working sane enough right now, maybe I'm seeing issues where there are none...? It all started with me trying to debug a paper-dropdown-menu and a paper-menu problem with dynamic children...

mattprivman commented 9 years ago

Having the same problem. Did you manage to find a workaround for this?

mattprivman commented 9 years ago

Best solution so far seems to be firing iron-select with an object containing a label and a value property, as seen here. Credit to @davidrissato from the Polymer slack group.

davidrissato commented 9 years ago

@mattppp: I'm sorry, but I've changed by mistake my original example with another thing completely different. You can find the old example in this snapshot: http://jsbin.com/raleni/7/edit?html,output