Skip to content

[docs] Fix clearing, layout shift, and prop leak in Pickers demos#23191

Merged
LukasTy merged 5 commits into
mui:masterfrom
LukasTy:claude/pickers-overview-clear-bug-ee5809
Jul 22, 2026
Merged

[docs] Fix clearing, layout shift, and prop leak in Pickers demos#23191
LukasTy merged 5 commits into
mui:masterfrom
LukasTy:claude/pickers-overview-clear-bug-ee5809

Conversation

@LukasTy

@LukasTy LukasTy commented Jul 21, 2026

Copy link
Copy Markdown
Member

Three fixes to Pickers documentation demos, all surfaced on the Pickers overview page.

Clear button no-op in the birthday demo

The "Enter your birthday" DateField in the Pickers overview main demo was controlled (value={dayjs(...)}) with no onChange and no defaultValue. Because a controlled input's value is locked to the prop, the clearable clear button (and manual typing) could never change it, so clicking clear was a no-op. Switched to defaultValue so the field is uncontrolled and clearing works, consistent with the sibling demos (Clock, CustomLayoutRangePicker). The field has been controlled-without-onChange since it was first written, so this is a long-standing demo bug rather than a recent regression.

Layout shift when clearing the birthday field

The birthday Card used maxWidth with no fixed width, so it shrank to fit its content. The field's intrinsic width (which includes the clearable clear button) drove the width of the whole right column, so clearing the field - which unmounts the clear button - narrowed the card and shifted the entire column, including the clock card above it. Pinned the card to a fixed width so it stays a constant size.

slotProps / inputRef prop leak in the custom Button field demos

The custom Button field spread forwardedProps from useSplitFieldProps directly onto a Material <Button>. useSplitFieldProps only extracts the value/format/validation props into internalProps; the rest (id, slots, slotProps, inputRef, ...) stays in forwardedProps for the default text field. Spreading those onto a <Button> forwarded slotProps and inputRef down to the DOM <button>, producing React does not recognize the ... prop on a DOM element console errors. Typed the forwarded field-only props on the field component (via Pick<DateFieldProps, ...>, and SingleInputDateRangeFieldProps for the range demo) and destructured them out before spreading. This affected the overview PickerButton demo and the canonical behavior-button custom-field examples that users copy from.

Verification

  • Reproduced both field bugs in jsdom: the buggy Button pattern emits 2 warnings (slotProps, inputRef), the fixed pattern emits 0; clearing is a no-op with value and empties the field with defaultValue.

  • Confirmed live on the running overview page: the clear button now empties the birthday field, the does not recognize console errors are gone, and clearing no longer shifts the layout - the birthday card, the clock card, and the Submit button all keep their exact position (measured zero delta before/after clear; without the fix they moved 11px).

  • .js demo files regenerated via pnpm docs:typescript:formatted; docs TypeScript, ESLint (no cache) and Prettier all clean.

  • I have followed (at least) the PR section of the contributing guide.

🤖 Generated with Claude Code

Two fixes in the Pickers documentation demos:

- The Pickers overview "Enter your birthday" DateField used a controlled
  `value` with no `onChange`, which made the clearable clear button a
  no-op. Switch to `defaultValue` (uncontrolled) so clearing works,
  matching the sibling demos.

- The custom Button field demos spread `forwardedProps` from
  `useSplitFieldProps` onto a Material `<Button>`. Those props include
  `slots`, `slotProps` and `inputRef`, which target the default text
  field, so `slotProps` and `inputRef` leaked onto the DOM `<button>` and
  triggered React "does not recognize the prop" warnings. Destructure them
  out before spreading. Applies to the overview PickerButton demo and the
  canonical behavior-button custom-field examples.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@code-infra-dashboard

code-infra-dashboard Bot commented Jul 21, 2026

Copy link
Copy Markdown

Deploy preview

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 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers-pro 0B(0.00%) 0B(0.00%)
@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 LukasTy added type: bug It doesn't behave as expected. docs Improvements or additions to the documentation. scope: pickers Changes related to the date/time pickers. labels Jul 21, 2026
LukasTy and others added 3 commits July 21, 2026 17:54
`DatePickerFieldProps` / `DateRangePickerFieldProps` do not type `slots`,
`slotProps` and `inputRef` (the picker forwards them at runtime for the
default text field), so destructuring them out of `forwardedProps` did
not compile. Cast to add the optional keys before stripping them.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Type the forwarded `slots` / `slotProps` / `inputRef` on the custom Button
field components with a prop-type intersection
(`Pick<DateFieldProps, ...>`, and `SingleInputDateRangeFieldProps` for the
range demo) rather than casting `forwardedProps` in the body. Same runtime
behavior, cleaner and cast-free.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
The birthday card had `maxWidth` but no fixed `width`, so it shrink-to-fit
its content. Clearing the field unmounts the clear button, which narrowed
the card - and because the card's content drove the right column width, the
whole column (including the clock card above it) shifted. Use a fixed
`width` so the card stays a constant size.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@LukasTy LukasTy changed the title [docs] Fix clear button and prop leak in Pickers demos [docs] Fix clearing, layout shift, and prop leak in Pickers demos Jul 21, 2026
Keeping the type-only `DateFieldProps` / `SingleInputDateRangeFieldProps`
import last means its elision during transpilation no longer leaves a blank
line in the middle of the generated `.js` imports.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@LukasTy
LukasTy marked this pull request as ready for review July 22, 2026 07:07
@LukasTy

LukasTy commented Jul 22, 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

This PR fixes three user-visible issues in the Pickers overview docs demos: a non-functional clear button caused by an inadvertently controlled DateField, layout shift when clearing due to content-driven sizing, and React console warnings caused by leaking slotProps/inputRef onto a DOM <button> in custom field demos.

Changes:

  • Switch the birthday demo DateField from value to defaultValue so clearing (and typing) works as expected.
  • Prevent layout shift on clear by pinning the birthday card to a fixed width.
  • Avoid leaking field-only props (slots, slotProps, inputRef) onto <Button> in custom “button field” demos by destructuring them out before spreading.

Reviewed changes

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

Show a summary per file
File Description
docs/src/modules/components/overview/pickers/mainDemo/PickerButton.tsx Filters out field-only props before spreading onto MUI <Button> to avoid React DOM-prop warnings in the overview demo.
docs/src/modules/components/overview/pickers/mainDemo/Birthday.tsx Makes the field clearable by using defaultValue and prevents layout shift by fixing the card width.
docs/data/date-pickers/custom-field/behavior-button/MaterialDateRangePicker.tsx Filters out slots/slotProps/inputRef from forwarded props before spreading onto <Button> in the TS demo.
docs/data/date-pickers/custom-field/behavior-button/MaterialDateRangePicker.js Regenerated JS demo reflecting the same prop-filtering fix.
docs/data/date-pickers/custom-field/behavior-button/MaterialDatePicker.tsx Filters out slots/slotProps/inputRef from forwarded props before spreading onto <Button> in the TS demo.
docs/data/date-pickers/custom-field/behavior-button/MaterialDatePicker.js Regenerated JS demo reflecting the same prop-filtering fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: b20b68d8e0

ℹ️ 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".

@LukasTy
LukasTy merged commit d40922c into mui:master Jul 22, 2026
22 checks passed
@LukasTy
LukasTy deleted the claude/pickers-overview-clear-bug-ee5809 branch July 22, 2026 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to the documentation. 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.

3 participants