Skip to content

[material-ui][Drawer] Remove ModalProps - #49930

Open
albinjiji wants to merge 2 commits into
mui:masterfrom
albinjiji:drawer-remove-modalprops
Open

albinjiji wants to merge 2 commits into
mui:masterfrom
albinjiji:drawer-remove-modalprops

Conversation

@albinjiji

Copy link
Copy Markdown
Contributor

Part of #49337 (Drawer: remove ModalProps in favor of slotProps.root). This is the v10 removal that follows the deprecation in #49844.

Changes (breaking)

  • Remove ModalProps from Drawer. Use slotProps.root instead; a nested slotProps.root.slotProps.backdrop is merged with the Drawer's own backdrop props.
  • SwipeableDrawer no longer reads ModalProps. Its keepMounted: true default for temporary drawers now goes through slotProps.root, and a user-provided slotProps.root.keepMounted still takes precedence.
  • Update docs, the integration spec and tests that used ModalProps.
  • Add a "Drawer ModalProps removed" section to the v10 upgrade guide. The drawer-props codemod already migrates the prop.
  • Remove the ModalProps entry from the deprecated APIs page, as in [material-ui][InputBase] Remove the deprecated disableInjectingGlobalStyles prop #49777.
  • Tests: backdrop prop merging, and the SwipeableDrawer keepMounted default and override.

Notes

  • Props nested in ModalProps such as slots and slotProps.backdrop were not forwarded to the Modal before (useSlot consumed them), but they take effect when passed through slotProps.root. The drawer-props codemod moves ModalProps into slotProps.root, so such values now apply. Nested slotProps.root.slots still replaces a custom top-level slots.backdrop, and a nested backdrop ref still replaces SwipeableDrawer's internal one; both match the existing slotProps.root behavior.

@code-infra-dashboard

code-infra-dashboard Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Deploy preview

Bundle size

Bundle Parsed size Gzip size
@mui/material 🔺+113B(+0.02%) 🔺+60B(+0.04%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/private-theming 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes

Performance

No regressions in 32 benchmarks · precise to ±5.4% (±15.4% at worst) · ran 2m 18s · details


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

@Janpot
Janpot requested a review from a team November 27, 2026 09:34

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

Thanks for following up on #49844. The direction matches the item in #49337, and the backdrop merge fixes two things that are broken on master: a nested slotProps.root.slotProps.backdrop no longer drops transitionDuration, and it no longer breaks swiping in SwipeableDrawer.

A few things before this can go in:

1. A callback-form nested backdrop gets the Drawer root classes

mergeSlotProps returns a callback when either argument is a function, and that callback adds ownerState.className. Modal resolves it with its own owner state, whose className is the Drawer root's. With

<Drawer open slotProps={{ root: { slotProps: { backdrop: () => ({}) } } }} />

the backdrop gets MuiDrawer-root MuiDrawer-modal plus the user's className, and its computed z-index goes from -1 to 1200. On master this case renders a clean backdrop, so it is a regression. Resolving both sides before merging avoids the function branch:

const rootSlotPropsWithBackdrop = (rootOwnerState) => {
  const resolvedRootSlotProps = resolveComponentProps(slotProps.root, rootOwnerState);
  const nestedBackdrop = resolvedRootSlotProps?.slotProps?.backdrop;
  const ownBackdrop = externalForwardedProps.slotProps.backdrop;
  return {
    ...resolvedRootSlotProps,
    slotProps: {
      ...resolvedRootSlotProps?.slotProps,
      backdrop: (backdropOwnerState) =>
        mergeSlotProps(
          resolveComponentProps(nestedBackdrop, backdropOwnerState),
          resolveComponentProps(ownBackdrop, backdropOwnerState),
        ),
    },
  };
};

A top-level callback slotProps.backdrop already has this problem on master, so that part is out of scope here.

2. Merge slots as well

slotProps.root.slots, even an empty object, replaces the slots.backdrop passed through additionalProps. The codemod now moves ModalProps.slots under slotProps.root, so I'd merge it the same way as slotProps:

slots: { backdrop: slots.backdrop, ...resolvedRootSlotProps?.slots },

3. Stale entries in scripts/generateProptypes.ts

'ModalProps' is still listed for SwipeableDrawer in useExternalDocumentation and ignoreExternalDocumentation.

4. Upgrade guide

"Props nested inside ModalProps, such as slots and slotProps.backdrop, are applied when moved to slotProps.root" doesn't say they were ignored before, so it doesn't read as a behavior change. Something like: "slots and slotProps nested inside ModalProps were previously ignored. They take effect once moved to slotProps.root." It's also worth saying that the codemod covers ModalProps in the theme's defaultProps.

5. Tests

The new Drawer test covers the className merge. Could you add one asserting that transitionDuration reaches the backdrop when a nested backdrop is set, and one with the nested backdrop as a callback? The second would have caught point 1.

@albinjiji

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review. Addressed in 8525631:

  1. The nested backdrop and the Drawer's own backdrop props are both resolved before merging, so a callback-form backdrop no longer gets the Drawer root classes. The new test failed before the change.
  2. slotProps.root.slots is merged with the Drawer's slots.backdrop. Tests added for a custom backdrop surviving an empty slots and for a nested one winning.
  3. Removed the stale ModalProps entries from generateProptypes.ts.
  4. Updated the upgrade guide and mentioned the codemod's theme defaultProps coverage. I narrowed the "previously ignored" sentence to slots.backdrop and slotProps.backdrop: from reading the code, ModalProps.slots.root and ModalProps.slotProps.root did take effect for the Drawer's root before, so a broader sentence would be inaccurate. I haven't run master to confirm that, so correct me if I've misread it.
  5. Added tests for transitionDuration reaching a nested backdrop (it already passed before the change, so it is a regression guard) and for the callback backdrop.

I also made a small related fix in SwipeableDrawer: with a callback slotProps.root, the user's className was applied twice on the root element, because merging a callback adds the owner state's className. The callback is now resolved before keepMounted is merged, with a test. Happy to drop it from this PR if you'd rather keep it separate.

This branch has not been deployed

No deployments
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.

2 participants