-
Notifications
You must be signed in to change notification settings - Fork 397
feat(Toggle and ToggleSmall): on Enter key press toggle action is being triggered. #2219
feat(Toggle and ToggleSmall): on Enter key press toggle action is being triggered. #2219
Conversation
Deploy preview for carbon-components-react ready! Built with commit f764779 https://deploy-preview-2219--carbon-components-react.netlify.com |
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.
thanks for tackling this @paschalidi! we have a set of helper functions for keyboard event handlers here that you can utilize for this PR
the object is fine to use, I believe that comment is just a note about how the |
Good discussion - For using |
LGTM basically, one question looking at your explanation on "why |
Thanks for asking @asudoh. Hope I can phrase this more clearly this time. Let me know if you still have questions please ! 👍 |
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.
Cool thank you for explaining @paschalidi!
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.
thanks for the quick changes @paschalidi! just curious, any particular reason for using onKeyUp
over onKeyDown
in this scenario? in any case, looks good to me!
@emyarod hey happy to help you have this awesome project. thanks for making this possible by making this open sourced. 🏆 I am happy you also asked and being thorough! That means you people take really good care of this code base. Really nice of you! quoting this time from MDN
and
So these two are almost the same but the first wont work for all the keys therefore is these days deprecated. Always feel free to disagree if you have an opinion that you would like to raise! Was a good discussion, hope we all learned something! ☮️ |
right I understand the desire to avoid the repeated events. my question was originally around the timing of the event firing. however that was based on my initial thought that the default behavior for inputs like checkboxes was to toggle on |
If the default behaviour is |
the default behavior for native checkbox is to change state on keyup, so we can keep the behavior as is. thanks for your help @paschalidi ! |
Was lots of fun! Thanks @emyarod |
Hello you all 👋 🌳 ! Thanks once again for giving me the opportunity to help in this amazing project!
Closes https://github.com/IBM/carbon-components-react/issues/2195
Without using a mouse navigate to the
Toggle
andToggleSmall
components and press the Enter key to activate the button. It fails to respond. Also note, this issue occurs with and without a screen reader.Changelog
Adds event
onKeyUp
to take care explicitly of thekey.which===13
(Enter key).Why
onKeyUp
Pressing Space key will also trigger the button to toggle, in my humble opinion Space and Enter press key should behave the same. Therefore I chose
onKeyUp
.Toggle
&ToggleSmall
without using a mouse to navigate pressing the Enter key changes the state of the button to its opposite state, from on to off and visa versa.Hope this makes sense!!
Have a good Tuesday 🕊