Skip to content

fix: focus first segment when calling focus() on DateField/TimeField ref - #11011

Open
poulet42 wants to merge 1 commit into
adobe:mainfrom
poulet42:fix/datefield-ref-focus
Open

poulet42 wants to merge 1 commit into
adobe:mainfrom
poulet42:fix/datefield-ref-focus

Conversation

@poulet42

@poulet42 poulet42 commented Nov 20, 2026 •

Copy link
Copy Markdown

Closes

Summary

Calling .focus() on the ref passed to the root DateField/TimeField does nothing: the ref points at a plain wrapper <div> with no tabindex. Form validation already focuses the first segment on submit (via useDateField's internal focus manager), so users expect the root ref to behave the same.

Expected: ref.current.focus() moves focus to the first segment. Actual: focus is not moved (and is lost after a failed required-field submit if the app tries to refocus via the ref).

Fix: a small useFocusFirstSegment helper exposes the root div through useImperativeHandle with focus() delegating to createFocusManager(fieldRef).focusFirst(). The ref type stays HTMLDivElement.

issue was especially visible when working with react-hook-form; the library gives you a ref that will be later used to focus invalid fields. Passing the ref to textfield does focus the field upon submit, but it's not the case for date-field, and I think it would make sense that refs passed to*Field components resolve to the right focusable child consistently.

Wdyt?

Not covered: DatePicker / DateRangePicker root refs have the same gap.

📝 Test Instructions

  • yarn jest packages/react-aria-components/test/DateField.test.js packages/react-aria-components/test/TimeField.test.js packages/react-aria-components/test/DatePicker.test.js → 3 suites, 69 tests pass.
  • New regression test in DateField.test.js (focuses the first segment when focus() is called on the root ref). I did not run it against the unfixed code to confirm it fails.
  • tsc --noEmit: no errors in react-aria-components.
  • TimeField has no dedicated test for the new behavior.

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

  • I followed the contributing guide.
  • I tested this change locally and included the results in Test Instructions, or explained why testing does not apply.
  • I understand and can explain every change in this PR. If I used AI assistance, I followed the AI contribution guidance.

🧢 Your Project

Qonto


AI disclosure: written with Claude Code assistance.

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@poulet42
poulet42 marked this pull request as ready for review November 20, 2026 13:42
@poulet42 poulet42 closed this Nov 20, 2026
@poulet42 poulet42 reopened this Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant