Skip to content

[fields] Keep the selected section on blank space clicks - #23318

Merged
LukasTy merged 3 commits into
mui:masterfrom
LukasTy:claude/happy-meninsky-6003dc
Aug 11, 2026
Merged

LukasTy merged 3 commits into
mui:masterfrom
LukasTy:claude/happy-meninsky-6003dc

Conversation

@LukasTy

@LukasTy LukasTy commented Aug 7, 2026 •

Copy link
Copy Markdown
Member

Fixes #23304

Problem

The sections container stretches to fill the field, so a click after the last section lands on it. #22285 sent that click to the section whose horizontal center is closest, on the premise that it matched the native date input. The benchmark in the issue shows the premise was wrong: the native input selects the first section on the first click, and Chrome keeps the current section on every later click in the empty area.

That also left no way to tell a click on the trailing blank space from a click on the year, so a controlled selectedSections could not keep the first section selected.

Changes

  • A click on the blank space selects the first section when it enters the field, and keeps the current section afterwards. This matches Chrome.
  • A 4px tolerance extends the sections on both sides, so a click that just misses the outermost section still selects it. Without it, a sloppy click 2px past the year does nothing at all.
  • The field padding now follows the same rule. It sits inside the field root but outside the sections container, so the mousedown handler used to return early there and never called preventDefault. The browser then blurred the focused section, and the field visibly blurred and focused again, coming back on the first section rather than the one the user had. Outside the sections container the handler only claims the field root itself, which is the target of a click on the padding, so the adornments keep their own focus behavior.

Clicks on the container padding and on separator gaps still resolve to the closest section. Only the area past the rendered sections changes.

Testing

Each test was confirmed to fail without its fix.

  • selection.DateField.test.tsx, browser only, since jsdom rects are 0x0 and no click point can fall outside the sections there: first click selects the first section, a later click keeps the current one, the boundary and the tolerance band both select the year.
  • selection.DateField.test.tsx, jsdom and browser: a mousedown on the field padding is default prevented, and a mousedown on an adornment is not, for both a button and a non-interactive adornment.
  • test/e2e/index.test.ts: the blur and the Chromium focus delegation are browser default actions, so only trusted pointer input reproduces them. Two tests cover the blank space and the padding with real clicks.

The sections container stretches to fill the field, so a click after the
last section lands on it. mui#22285 sent
that click to the section whose horizontal center is closest. It chose
that behavior on the premise that it matched the native date input.

The benchmark in the issue shows the premise was wrong. The native input
selects the first section on the first click. Chrome then keeps the
current section on every later click in the empty area. This commit
aligns the field with that behavior.

A 4px tolerance extends the sections on both sides, so a click that just
misses the outermost section still selects it. Without the tolerance, a
sloppy click 2px past the year does nothing at all.

The field padding now follows the same rule. It sits inside the field
root but outside the sections container, so the mousedown handler used to
return early there and never called `preventDefault`. The browser then
blurred the focused section, and the field visibly blurred and focused
again. Outside the sections container the handler only claims the field
root itself, which is the target of a click on the padding, so the
adornments keep their own focus behavior. The active bar gets
`pointer-events: none` because it is decorative and overlaps the padding.

The rest of the design from that PR stays. Clicks on the container
padding and on separator gaps still resolve to the closest section. Only
the area past the last section changes.

Fixes mui#23304

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@LukasTy LukasTy self-assigned this Aug 7, 2026
@LukasTy LukasTy added type: bug It doesn't behave as expected. scope: pickers Changes related to the date/time pickers. feature: Keyboard editing Related to the pickers keyboard edition labels Aug 7, 2026
@code-infra-dashboard

code-infra-dashboard Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-23318--material-ui-x.netlify.app/
QR code for https://deploy-preview-23318--material-ui-x.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/x-data-grid 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-pro 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-premium 0B(0.00%) 0B(0.00%)
@mui/x-charts 0B(0.00%) 0B(0.00%)
@mui/x-charts-pro 0B(0.00%) 0B(0.00%)
@mui/x-charts-premium 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers 🔺+369B(+0.18%) 🔺+122B(+0.21%)
@mui/x-date-pickers-pro 🔺+369B(+0.14%) 🔺+113B(+0.15%)
@mui/x-tree-view 0B(0.00%) 0B(0.00%)
@mui/x-tree-view-pro 0B(0.00%) 0B(0.00%)
@mui/x-scheduler 0B(0.00%) 0B(0.00%)
@mui/x-scheduler-premium 0B(0.00%) 0B(0.00%)
@mui/x-chat 0B(0.00%) 0B(0.00%)
@mui/x-license 0B(0.00%) 0B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

LukasTy and others added 2 commits August 7, 2026 16:35
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
It is out of scope: the strip behaves as before this PR without it, and a
test would need an open range picker and a 2px trusted-input target.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@LukasTy
LukasTy requested a balanced review from Copilot August 10, 2026 07:18
@LukasTy

LukasTy commented Aug 10, 2026

Copy link
Copy Markdown
Member Author

@codex review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates date-field blank-space clicks to match native Chrome behavior while preserving section focus.

Changes:

  • Preserves the current section on trailing-space and field-padding clicks.
  • Adds a 4px outer-section click tolerance.
  • Adds browser and end-to-end regression coverage.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
useFieldRootProps.ts Implements blank-space detection and focus preservation.
selection.DateField.test.tsx Tests padding, adornments, boundaries, and selection behavior.
test/e2e/index.test.ts Tests trusted blank-space and padding clicks.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: c639348aff

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@JCQuintas JCQuintas 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.

The PR description mentions

the native input selects the first section on the first click, and Chrome keeps the current section on every later click in the empty area.

But it seems the first click depends highlight depends on where it is clicked inside the field

Screen.Recording.2026-08-10.at.16.27.28.mov

It probably makes sense, but I wanted to point it out just so we are sure this is the intended behaviour.

@LukasTy

LukasTy commented Aug 11, 2026

Copy link
Copy Markdown
Member Author

@JCQuintas, thanks for pointing it out.
Yes, that's the expected behavior and has been there more or less from the start. 👌

@LukasTy
LukasTy merged commit 173ca1d into mui:master Aug 11, 2026
23 checks passed
@LukasTy
LukasTy deleted the claude/happy-meninsky-6003dc branch August 11, 2026 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature: Keyboard editing Related to the pickers keyboard edition scope: pickers Changes related to the date/time pickers. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DateField] Clicking trailing whitespace after the last section prevents controlling the initial selected section

3 participants