Skip to content

Fix NumberField blur during CalendarCell focus - #11000

Open
sarthakkatta wants to merge 2 commits into
adobe:mainfrom
sarthakkatta:fix-10935-numberfield-flushsync
Open

sarthakkatta wants to merge 2 commits into
adobe:mainfrom
sarthakkatta:fix-10935-numberfield-flushsync

Conversation

@sarthakkatta

Copy link
Copy Markdown

Closes #10935

Summary

When a CalendarCell receives focus through a React effect, it can cause a previously focused NumberField input to blur while React is executing a passive effect.

The NumberField blur handler uses flushSync to commit the value. This can trigger a React lifecycle warning and prevent the corrected value from being announced properly.

This PR addresses the issue by deferring CalendarCell's effect-driven focus to a microtask, allowing the React effect to finish before focus triggers the blur handler.

Additional safeguards ensure that the element is still mounted and referenced before focusing it. Existing keyboard scrolling behavior is preserved.

📝 Test Instructions

Regression test added:
packages/react-aria-components/test/NumberField.test.js

Test: commits and announces a corrected value when focus moves in an effect

The test:

  • Enters 20 into a NumberField with maxValue={10}.
  • Moves focus to an auto-focused CalendarCell.
  • Verifies that the NumberField value is corrected to 10.
  • Verifies that onChange receives 10.
  • Verifies that the corrected value is announced assertively.
  • Verifies that the React flushSync lifecycle warning is not logged.

Local verification:

  • NumberField test suite: 38/38 tests passed.
  • Oxfmt: passed for both changed files.
  • Oxlint: 0 warnings and 0 errors.

The regression test was verified after the fix. Its failure against the original implementation was not independently verified.

Release impact

  • Only changes docs, tests, CI, or development tools. Nothing shipped to users changes.
  • Fixes a bug or improves existing code without changing how apps use it.
  • Adds a feature or API while keeping existing usage working.
  • May break existing usage or require changes in apps that use this code.

✅ PR Checklist

🧢 Your Project

React Spectrum (Adobe)

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.

NumberField: flushSync warning when a CalendarCell takes focus from the input

1 participant