Skip to content

fix: avoid duplicate Space presses on form buttons - #10694

Open
minwookshin wants to merge 1 commit into
adobe:mainfrom
minwookshin:fix/button-space-activation
Open

minwookshin wants to merge 1 commit into
adobe:mainfrom
minwookshin:fix/button-space-activation

Conversation

@minwookshin

Copy link
Copy Markdown
Contributor

Closes #10658

Space should activate a form button once while preserving its native submit/reset behavior. usePress currently handles the keyup and then treats the browser's following click as a second, virtual press.

Keep the existing emulated-click guard set through that native click, and clear it on the next task even when the browser click is canceled. Browser tests cover repeated Space presses, Enter, submit/reset defaults, and subsequent mouse/programmatic activation.

AI-assisted implementation and verification with Codex, following AGENTS.md and the contribution guidance.

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated tests for this change: real-browser Button regression coverage; no new visual states or Storybook API.
  • Filled out test instructions.
  • Reviewed documentation needs: no public API or documented behavior change.
  • Looked at the Accessibility Practices for this feature - Button Pattern.
  • 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:

Run yarn vitest run --config=vitest.browser.config.ts packages/react-aria-components/test/Button.browser.test.tsx. The submit/reset Space cases fail before the fix in Chromium, Firefox, and WebKit; all 12 cases pass afterward.

Also verified:

  • Full Jest suite: 8,361 passed, 16 skipped.
  • SSR suite: 74 passed.
  • Full desktop browser suite, running each browser sequentially: 414 passed, 63 skipped.
  • yarn lint, including formatting, types, constraints, and package checks.

Keyboard, mouse, and programmatic clicks are covered. Screen-reader interaction was not manually tested.

🧢 Your Project:

Independent open-source contribution.

// Native controls may click after Space keyup. Keep their default action, but
// don't handle that click as another press. Clear this even if the click is canceled.
state.ignoreEmulatedMouseEvents = true;
setTimeout(() => {

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.

can we clear it any other way that doesn't rely on timeouts? if not, we'll want to explore other approaches before choosing this one

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Tested microtask cleanup: submit/reset still double-fire in Chromium and WebKit. Clearing only on click swallows the next virtual activation after a canceled keyup in all three browsers; would you prefer exploring dispatch from the native click instead?

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.

Space on a type="submit" or type="reset" Button calls onPress and onClick twice

2 participants