fix: delegate checkbox/radio/switch label keydown to native inputs#9972
fix: delegate checkbox/radio/switch label keydown to native inputs#9972nami8824 wants to merge 1 commit intoadobe:mainfrom
Conversation
snowystinger
left a comment
There was a problem hiding this comment.
One big thing to note, Enter can no longer be used to toggle a switch or checkbox with this PR. It could be argued that Space should be the only way to do it as that is how native inputs work, but we've had this behaviour for 6+ years, so I don't know if we can change it lightly.
|
|
||
| // Let the hidden input handle keyboard events natively so Enter can | ||
| // submit forms like a native checkbox/switch control. | ||
| delete labelProps.onKeyDown; |
There was a problem hiding this comment.
there's another usePress call, does it have the same problem?
|
|
||
| // Let the hidden radio input handle keyboard events natively so Enter can | ||
| // submit forms like a native radio control. | ||
| delete labelProps.onKeyDown; |
There was a problem hiding this comment.
I'm not sure that deleting the keydown handler is quite the right thing to do, seems like we should selectively delegate some keys but not others to the pressProps onKeyDown. ie only ignore Enter, not Space?
I hadn't noticed this impact. I think disabling Enter-to-toggle is necessary to properly address this issue, because allowing Enter to both toggle a checkbox/radio/switch and submit a form at the same time feels like unexpected behavior. How should Enter be handled for these elements...? |
|
Nothing yet, lets wait for more opinions from the team |
Closes #6235
usePress'sonKeyDownwas stopping Enter from propagating, which prevented the hidden native input from triggering normal form submission behavior.Radio, the same issue also existed forCheckboxandSwitch, so those were updated as well to let the native input handle keyboard behavior.✅ Pull Request Checklist:
📝 Test Instructions:
🧢 Your Project: