Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide label element linked to input #34

Open
themre opened this issue Aug 14, 2016 · 8 comments
Open

Provide label element linked to input #34

themre opened this issue Aug 14, 2016 · 8 comments

Comments

@themre
Copy link

themre commented Aug 14, 2016

Hi,
Great component, however I'm missing functionality to provide label with for attribute that would link to input element. Would it be possible to include this property?

@nkbt
Copy link
Collaborator

nkbt commented Aug 14, 2016

We pass-through all props to the component, so for should be present too.

@nkbt
Copy link
Collaborator

nkbt commented Aug 14, 2016

Ah, I see. All props are passed to wrapper <div>, not to every individual radio element...

@nkbt
Copy link
Collaborator

nkbt commented Aug 15, 2016

Now I understand what you mean (I think so)

You should use something like:

<RadioGroup for="blah" Component="label">
  <Radio>
   // ...

@danielberndt
Copy link
Collaborator

note it's htmlFor not just for
i.e.
<RadioGroup htmlFor="blah" Component="label">

@themre
Copy link
Author

themre commented Aug 15, 2016

My own hack was to use uuid, since ids need to be unique:
let num = 0 return <RadioGroup {...this.props} > { this.props.sources.map((item) => { let id = uuid.v4() num++ return <span><Radio id={id} key={num} value={item.name} /><label htmlFor={id}>{item.name}</label></span> } )} </RadioGroup>
perhaps it would be more nice if there was some built-in method for this?

@nkbt
Copy link
Collaborator

nkbt commented Aug 15, 2016

If you wrap Radio into label, you will need neither id nor htmlFor.
On Mon, 15 Aug 2016 at 22:47, themre notifications@github.com wrote:

My own hack was to use uuid, since ids need to be unique:
let num = 0
return <RadioGroup {...this.props} >
{
this.props.sources.map((item) => {
let id = uuid.v4()
num++
return {item.name}
}
)}

perhaps it would be more nice if there was some built-in method for this?


You are receiving this because you commented.

Reply to this email directly, view it on GitHub
#34 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAKsoJ2_eAlpqxv8rgLNfl6Bi9bAm6M8ks5qgF-0gaJpZM4Jj7zP
.

@themre
Copy link
Author

themre commented Aug 15, 2016

ok, that would then solve the problem label not being clickable. thanks.

@gabrielmicko
Copy link

gabrielmicko commented Aug 7, 2017

What if you use it like this?
<RadioGroup name="published"> <label className="radio" name="published"> <Radio value="1" /> <span>Yes</span> </label> <label className="radio" name="published"> <Radio value="0" /> <span>No</span> </label> </RadioGroup>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants