PolymerElements / iron-selector

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

The value of attr-for-selected must be camel-cased, not hyphenated? #57

Closed miztroh-zz closed 8 years ago

miztroh-zz commented 9 years ago

While working with a paper-dropdown-menu, paper-menu, and paper-item, I couldn't understand why some of the dropdowns weren't displaying the initially selected item or allowing me to change the selection. I finally discovered through lots of trial and error that attr-for-selected expects a camelcase value. Declaring attr-for-selected="foo-bar" breaks things as described above. Changing that to attr-for-selected="fooBar" makes things work as expected. I suggest that iron-selector be fixed to allow things to work either way, or update the documentation to make it clear that camelcase is required.

notwaldorf commented 8 years ago

We should update the documentation to indicate this

bicknellr commented 8 years ago

I think the issue is a little different - see this line. IronSelectableBehavior uses the same raw string - what's set as attr-for-selected - to first try direct property lookup on the item and then to try finding the attribute value if that property doesn't exist. So, if you're using non-reflected properties, you have to set attr-for-selected to a camel case property name, but then your hyphenated attributes stop working. However, if all of your items either have the hyphenated attribute or a property by that name with reflectToAttribute: true, then hyphenation will also work. So, attr-for-selected accidentally has two distinct modes that break when combined and needs to have its input normalized.

arthurevans commented 8 years ago

@bicknellr is correct, it's a little funky that attrForSelected actually uses attributes or properties--and checks properties first.

miztroh-zz commented 8 years ago

IMO, it should use the attribute / hyphenated version. That way, it matches what developers will be putting on the selectable elements:

<iron-selector attr-for-selection="vehicle-type">
    <div vehicle-type="planes">Planes</div>
    <div vehicle-type="trains">Trains</div>
    <div vehicle-type="automobiles">Automobiles</div>
</iron-selector>
bicknellr commented 8 years ago

@miztroh My thoughts exactly. PR coming in just a moment.