ember-radio-button icon indicating copy to clipboard operation
ember-radio-button copied to clipboard

How do I add data attributes to radio-button ?

Open pRatikSathaye opened this issue 5 years ago • 6 comments

I want to use data-test-selectors and for that purpose I wanted to add data attributes to my radio button. I tried adding some data attributes but they did not work.

pRatikSathaye avatar May 10 '19 09:05 pRatikSathaye

We don't currently have a good way to support data-test attributes directly on the input element. I would recommend putting a data-test attribute on an ancestor and then using something like [data-test-my-ancestor] input[type=radio]

raycohen avatar May 14 '19 00:05 raycohen

Hello @raycohen 😃 I am also running into the same issue in my applications, and I find it more less than ideal and, more like a workaround to be adding data-* attributes to the parent and referring the child element(i.e. radio-button).

I'll be happy to send a PR for adding this enhancement. I was thinking of adding a new property, say dataAttributes which accepts an hash of data-* key/value pairs, which gets added to the radio buttons' dom - just like the other attributes that is being done currently, like ariaLabelledby, tabindex, etc

shankarsridhar avatar Jun 30 '19 19:06 shankarsridhar

I would love to see support for data-* attributes on this!

barryofguilder avatar Aug 08 '19 12:08 barryofguilder

What would really be nice is if the components supported attribute forwarding (AKA splattributes, ...attributes in the template).

Depending on the Ember version support matrix and the tolerance for either providing or requiring a polyfill, that would allow you to add whatever attribute you want to a <RadioButton /> component and have the attributes passed along to the underlying input.

alexlafroscia avatar Oct 01 '19 20:10 alexlafroscia

What would really be nice is if the components supported attribute forwarding (AKA splattributes, ...attributes in the template).

Depending on the Ember version support matrix and the tolerance for either providing or requiring a polyfill, that would allow you to add whatever attribute you want to a <RadioButton /> component and have the attributes passed along to the underlying input.

Hmm know any addons that use this kind of polyfill? I'm running into this and would like to submit a PR.

~I'd try out a local workaround, but it doesn't sound like this is extensible.~

Never mind — if you're using modern Ember (support splattributes), you can generate a component override for radio-button.js/.hbs. You'll need to copy over the template from the addon and insert the attribute spread in the label:

  <label
    class="ember-radio-button {{if checked checkedClass}} {{joinedClassNames}}"
    for={{radioId}}
    ...attributes
  >

Nevertheless, we should build out support :)

allthesignals avatar May 10 '20 21:05 allthesignals

Any progress on this? Seems it's not possible to apply a modifier to the radio button

lougreenwood avatar Jan 13 '21 15:01 lougreenwood