Skip to content

fix(usePress): only skip Enter default prevention on macOS for Control + Enter - #10820

Merged
snowystinger merged 2 commits into
adobe:mainfrom
jsabutis:fix/usepress-mac-enter-10741
Oct 23, 2026
Merged

snowystinger merged 2 commits into
adobe:mainfrom
jsabutis:fix/usepress-mac-enter-10741

Conversation

@jsabutis

Copy link
Copy Markdown
Contributor

Closes #10741

On macOS, shouldPreventDefaultKeyboard returned false for 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 shouldPreventDefaultKeyboard and requires ctrlKey for the exemption. Control + Enter keeps its default, so the contextmenu path is unchanged. Plain Enter falls through to the existing rules, so links, submit buttons and inputs keep their native Enter behaviour.

✅ 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
  • I understand every change in this PR and can explain why it's there.
  • If AI-assisted, I followed our AI contribution guidance and pointed my assistant at AGENTS.md.

📝 Test Instructions:

Two new cases in usePress.test.js with the platform mocked to macOS: plain Enter on a pressable element is default-prevented on keydown and keyup (fails on main), Control + Enter is not. usePress and useContextMenu suites: 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

…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
@nwidynski

nwidynski commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Duplicate of #10786. I don't really mind though.

@snowystinger snowystinger left a comment

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.

Added a test to represent the reported bug without relying on usePress details.

@snowystinger

Copy link
Copy Markdown
Member

@jsabutis jsabutis closed this Oct 23, 2026
@jsabutis jsabutis reopened this Oct 23, 2026
@jsabutis

Copy link
Copy Markdown
Contributor Author

@snowystinger CLA is signed and the check is green now. Thanks for adding the test.

@snowystinger
snowystinger added this pull request to the merge queue Oct 23, 2026
Merged via the queue into adobe:main with commit d5fb723 Oct 23, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

usePress: moving focus during onSelectionChange in ListBox via keyboard causes new activeElement to be "pressed"

4 participants