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

Added htmlFor prop for CustomInput #1417

Merged
merged 2 commits into from Mar 4, 2019

Conversation

Dakkers
Copy link
Contributor

@Dakkers Dakkers commented Feb 27, 2019

  • Bug fix
  • New feature
  • Chore
  • Breaking change
  • There is an open issue which this change addresses
  • I have read the CONTRIBUTING document.
  • My commits follow the Git Commit Guidelines
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

I have a niche scenario where I'm using a custom input but don't want the label to be bound to the checkbox. The way I did this with regular inputs is overriding the htmlFor, but I couldn't do that with the custom ones. So I've added that here, along with some tests.

@Dakkers
Copy link
Contributor Author

Dakkers commented Mar 2, 2019

@eddywashere @TheSharpieOne is there anything I'm missing here? 👀

@TheSharpieOne
Copy link
Member

I suppose nothing is missing, but the use-case goes against best practices and a11y and will prevent the component from working as it's intended to if the label isn't tied to the input via htmlFor.
Without a label bound to the input, there is no way for the user to check the checkbox. The checkbox itself is hidden, the one you see if fake (part of the label). The standard (non-custom) checkboxes work since the checkbox itself is visible and can be checked.
I wonder if you really need the CustomInput or if you are just need another custom component.

@Dakkers if you confirmed that you have tried this solution with your use-case and that it works as expected, I will merge it since it really shouldn't affect anyone due to it being opt-in via the htmlFor prop. But I believe that setting this prop can only have negative impacts so I want to make sure that you validated it has a positive impact for your use-case.

@Dakkers
Copy link
Contributor Author

Dakkers commented Mar 4, 2019

@TheSharpieOne I understand un-binding it will prevent the checkbox from working on its own - my use case is that I have a container surrounding the checkbox which is clickable. Let me confirm this works (I have to use my fork as an npm dependency) and I'll comment back.

@Dakkers
Copy link
Contributor Author

Dakkers commented Mar 4, 2019

Additionally, unsetting htmlFor manually worked fine with the regular checkboxes, which I was using before, but now I have to use the custom checkboxes (unfortunately).

@Dakkers
Copy link
Contributor Author

Dakkers commented Mar 4, 2019

@TheSharpieOne I can confirm this fixes my issue. I can add some documentation regarding the a11y violation if you'd like too (where would I put that?)

@TheSharpieOne TheSharpieOne merged commit a590880 into reactstrap:master Mar 4, 2019
@danconnell
Copy link

Is it possible to have a release published with this change, @TheSharpieOne?

Thanks!

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

Successfully merging this pull request may close these issues.

None yet

3 participants