Repository navigation
fix(usePress): only skip Enter default prevention on macOS for Control + Enter - #10820
Merged
Merged
Conversation
…l + Enter The macOS context menu exemption in shouldPreventDefaultKeyboard checked only the key, so plain Enter was no longer default-prevented on macOS. When a press handler moves focus during keydown (for example a Select option restoring focus to its trigger), the browser then fires a native click on the newly focused element and reopens the Select. Pass the keyboard event to shouldPreventDefaultKeyboard and require ctrlKey for the exemption, so Control + Enter still reaches the native contextmenu path while plain Enter is prevented as before. Fixes adobe#10741
Contributor
|
Duplicate of #10786. I don't really mind though. |
snowystinger
approved these changes
Oct 22, 2026
snowystinger
left a comment
Member
There was a problem hiding this comment.
Added a test to represent the reported bug without relying on usePress details.
Member
reidbarber
approved these changes
Oct 22, 2026
Contributor
Author
|
@snowystinger CLA is signed and the check is green now. Thanks for adding the test. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #10741
On macOS,
shouldPreventDefaultKeyboardreturnedfalsefor every Enter keypress. The #10237 exemption for Control + Enter (native context menu) only checked the key, so plain Enter stopped being default-prevented too. When a press handler moves focus during keydown, as a Select option does when it restores focus to its trigger, the browser fires its native click on the newly focused trigger and the Select reopens.This passes the event to
shouldPreventDefaultKeyboardand requiresctrlKeyfor the exemption. Control + Enter keeps its default, so thecontextmenupath is unchanged. Plain Enter falls through to the existing rules, so links, submit buttons and inputs keep their native Enter behaviour.✅ Pull Request Checklist:
📝 Test Instructions:
Two new cases in
usePress.test.jswith the platform mocked to macOS: plain Enter on a pressable element is default-prevented on keydown and keyup (fails onmain), Control + Enter is not.usePressanduseContextMenusuites: 129/129.Manually on a Mac: open a React Aria Components Select, arrow to an option, press Enter. The list closes, focus returns to the trigger and the list stays closed. On a
MenuTrigger trigger="contextMenu"target, Control + Enter still opens the context menu.🧢 Your Project:
Nclusion