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

EUIRadio with a label and no id behaves unexpectedly #3248

Closed
oatkiller opened this issue Apr 3, 2020 · 2 comments · Fixed by #3382
Closed

EUIRadio with a label and no id behaves unexpectedly #3248

oatkiller opened this issue Apr 3, 2020 · 2 comments · Fixed by #3382

Comments

@oatkiller
Copy link

Hi there. Thanks for the work on EUI. I've really been enjoying using it. I found some behavior that I think is unexpected and threw me for a loop.

If you define an EuiRadio with a label and no id, onChange will not be triggered from a click.

    <EuiRadio
      label="EUIRadio with a label and no ID"
      onChange={useCallback(() => alert("changed"), [])}
    />

Check my codesandbox to see the example.

If the label property is passed an HTML <label /> element will entirely obscure the <input /> element. The <label /> element isn't the parent of the <input /> and so if no id attribute associates them, the click event on the <label /> will not trigger a change event on the <input />.

Reproduce this

  • Create an EUIRadio with label and onChange properties. The onChange property should be a function which calls alert or runs some other code that you can use to assert that the function ran.
  • Load the code in a browser and click the EUIRadio component.
  • The function will not have run, and no alert will be shown.

Expected

  • If the onChange property is provided it will be run, even if label is provided and id is not.
  • OR, the id should be required if label is passed.
  • OR, the behavior should be documented
@anishagg17
Copy link
Contributor

Expected
If the onChange property is provided it will be run, even if label is provided and id is not.
OR, the id should be required if label is passed.
OR, the behavior should be documented

which is the required behaviour?

@chandlerprall
Copy link
Contributor

which is the required behaviour?

id should be required if there is a label provided, as it is necessary for the label->radio interaction.

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

Successfully merging a pull request may close this issue.

3 participants