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

Checkbox label not clickable if name is not provided #188

Closed
jerefrer opened this issue Nov 9, 2023 · 4 comments · Fixed by #191
Closed

Checkbox label not clickable if name is not provided #188

jerefrer opened this issue Nov 9, 2023 · 4 comments · Fixed by #191
Assignees
Labels
assigned Someone has been assigned to this issue bug Something isn't working complete: pending Contributor has fixed this issue and will be included in their next pull request

Comments

@jerefrer
Copy link
Contributor

jerefrer commented Nov 9, 2023

Current Behavior

Omitting the name attribute when using <Checkbox> will result in the label next to the checkbox not toggling the value as one would expect.

Because there isn't any error message except the warning in the console telling me that "name" is missing, it took me quite a while to understand that one was linked to the other.

Expected Behavior

Maybe when omitting the name it could be auto-generated with a uuid or just a counter.

It seems to me that when using Svelte an input's name has very little relevance in most cases. What I like about Svelte is that it is very concise, so if I have to specify the name I expect that it must mean something in terms of my app's domain logic.

Steps To Reproduce

  1. Use the component with a label, omitting to provide the name attribute
    let checked = false;
    <Checkbox bind:checked={checked }>
    <Checkbox.Label slot="label">Checked</Checkbox.Label>
    </Checkbox>
  2. Click on the label next to the checkbox
  3. Notice that the checkbox doesn't get toggled. Nothing happens.

Link to Reproduction / Stackblitz

No response

More Information

No response

@jerefrer jerefrer added the bug Something isn't working label Nov 9, 2023
@N00nDay
Copy link
Owner

N00nDay commented Nov 13, 2023

The issue with this is that based on the structure the for property of the label needs to be linked to the id property of the input field and this is all directly tied to the name property provided to the Checkbox component. This just comes back to how html works unfortunately. As for generating an id and for property, if the name property is omitted I can auto generate this utilizing the nanoid package. If this is going to happen it should be expanded to all form elements not just the Checkbox in my opinion.

@jerefrer
Copy link
Contributor Author

Indeed it's tied to basic HTML (as I remember from my days working with Rails :) but that doesn't mean this "implementation detail" should not be hidden from the developer. So auto-filling of the name attribute would make a lot of sense and doesn't seem to have any drawback as far as I know.

Thank you for mentioning nanoid, I've just switched to it instead of uuid in my current project :)

@N00nDay N00nDay self-assigned this Nov 13, 2023
@N00nDay N00nDay added in progress Someone has been assigned and has started work assigned Someone has been assigned to this issue labels Nov 13, 2023
@N00nDay
Copy link
Owner

N00nDay commented Nov 13, 2023

  • Autocomplete
  • Checkbox
  • Currency
  • DatePicker
  • FilePicker
  • Input
  • InputNumber
  • Radio
  • Rating
  • Select
  • Toggle

@N00nDay N00nDay added complete: pending Contributor has fixed this issue and will be included in their next pull request and removed in progress Someone has been assigned and has started work labels Nov 13, 2023
@N00nDay N00nDay linked a pull request Nov 14, 2023 that will close this issue
@N00nDay N00nDay closed this as completed Nov 14, 2023
@jerefrer
Copy link
Contributor Author

🎉 Thank you so much :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assigned Someone has been assigned to this issue bug Something isn't working complete: pending Contributor has fixed this issue and will be included in their next pull request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants