Closed miztroh-zz closed 8 years ago
We should update the documentation to indicate this
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.
@bicknellr is correct, it's a little funky that attrForSelected actually uses attributes or properties--and checks properties first.
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>
@miztroh My thoughts exactly. PR coming in just a moment.
While working with a
paper-dropdown-menu
,paper-menu
, andpaper-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 thatattr-for-selected
expects a camelcase value. Declaringattr-for-selected="foo-bar"
breaks things as described above. Changing that toattr-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.