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

<Label> has no way of providing the input value #568

Open
schnittchen opened this issue Feb 22, 2022 · 2 comments
Open

<Label> has no way of providing the input value #568

schnittchen opened this issue Feb 22, 2022 · 2 comments

Comments

@schnittchen
Copy link

Describe the bug

The Label component internally uses input_id/2, never input_id/3. The generated for attribute is never correct for a radio button or checkbox.

As a workaround, I am currently doing

<Label opts={for: nil}>
  <RadioButton value="value" />
  label text
</Label>

How to reproduce it

Clicking on the label text with this markup

<Label>
  <RadioButton value="value" />
  label text
</Label>

There are probably also legitimate use cases where wrapping the around the input is not feasible, so it would be good to allow <Label value={...}>text</Label> or similar.

does not select the nested radio button.

Your Environment

Surface: v0.7.0
LiveView: v0.17.6
Elixir: v1.13.0 (compiled with Erlang/OTP 24)

@miguel-s
Copy link
Collaborator

miguel-s commented Feb 23, 2022

Hi @schnittchen!

RadioButton as a child of Label

I could reproduce the issue, thanks for catching and reporting it!
For now as you alredy mentioned you can make it work by passing the for option to the Label component. Either <Label opts={for: nil}> or <Label opts={for: input_id(form, field, value)}> will work.

RadioButton as a sibling of Label

This is working as intended, following the example set by Phoenix. Basically it requires explicitely passing the for option to Label.

Example:

<Form for={:form} :let={form: f}>
  <Field name={:radio}>
    <Label opts={for: input_id(f, :radio, "value")} />
    <RadioButton value="value" />
  </Field>
</Form>

See an older discussion here for more context.

@schnittchen
Copy link
Author

Thanks! I suggest the Label documentation gets Radio/Checkbox examples (child + sibling) when this is fixed

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

2 participants