Skip to content

fix: delegate checkbox/radio/switch label keydown to native inputs#9972

Open
nami8824 wants to merge 1 commit intoadobe:mainfrom
nami8824:fix/native-input-keydown-checkbox-radio-switch
Open

fix: delegate checkbox/radio/switch label keydown to native inputs#9972
nami8824 wants to merge 1 commit intoadobe:mainfrom
nami8824:fix/native-input-keydown-checkbox-radio-switch

Conversation

@nami8824
Copy link
Copy Markdown
Contributor

@nami8824 nami8824 commented Apr 23, 2026

Closes #6235

  • usePress's onKeyDown was stopping Enter from propagating, which prevented the hidden native input from triggering normal form submission behavior.
  • In addition to fixing this for Radio, the same issue also existed for Checkbox and Switch, so those were updated as well to let the native input handle keyboard behavior.

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

🧢 Your Project:

@github-actions github-actions Bot added the RAC label Apr 23, 2026
Copy link
Copy Markdown
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@nami8824
Copy link
Copy Markdown
Contributor Author

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.

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...?

@snowystinger
Copy link
Copy Markdown
Member

Nothing yet, lets wait for more opinions from the team

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Event Bubbling Issue with Radio Component in Form Navigation

2 participants