-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat: make Toggle support keyboard #417
base: main
Are you sure you want to change the base?
Conversation
return; | ||
} | ||
|
||
input?.click(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a normal checkbox, one would be able to tab to it to focus it and press space to toggle it, right?
Why is that not possible here, given that the Toggle
component is implemented with a checkbox?
Is it because the checkbox has display: none
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it because the checkbox has display: none?
Yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could it be solved by making the checkbox visibility: hidden
and/or height: 0
instead, or by giving it tabindex="0"
?
I think it would be preferable if we could rely on the default browser behavior instead of implementing a keydown listener.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure it is a better solution. If we do so, assuming it would work out, then we would need extra CSS and maybe even a state too to highlight correctly focus, hover and other feedback of the related UI components. One or the other...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also probably more development effort.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That said, here I just realized disabled
is not handled and should been added to handle the keyboard event in such case.
Let me know if you rather like going CSS etc. and we close the PR (and comeback to this when we've got time) or otherwise I also add a if
to handle disable state and improve this PR.
I'm fine either way, your call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either way is fine with me.
Motivation
I noticed that
Toggle
couldn't be checked per keyboard navigation. This extend their accessibility for keyboard support.Changes
keydown
support and accessibility toToggle
componentwidth: fit-content
given that the toggle can receive focus - i.e. scope active outline style to the element