Skip to content

[material-ui][Modal] Add the mountNode prop#40211

Closed
arminbashizade wants to merge 1 commit into
mui:v5.xfrom
arminbashizade:shadow-modal
Closed

[material-ui][Modal] Add the mountNode prop#40211
arminbashizade wants to merge 1 commit into
mui:v5.xfrom
arminbashizade:shadow-modal

Conversation

@arminbashizade

Copy link
Copy Markdown

fixes #39636

I want to know your thoughts about this approach before I add tests and docs.

Currently the suggested way to add a Dialog inside a shadow root is to use props.container, but I'm thinking a new input is needed on Modal to fix #39636, something like props.mountNode to differentiate between

  • the container where the Portal is created; and
  • the container that is used in ModalManager to handle styling

Because a Dialog can be inside a container or use document.body, additionally it can be inside a Shadow DOM or not. These two properties are independent of each other and one cannot be inferred from the other.

To use this new prop to add a dialog in a Shadow DOM, follow the MUI docs but instead of setting container set mountNode, this will keep using container (which is document.body by default) in ModalManager and shadowRootElement to create the Portal:

const theme = createTheme({
  components: {
    MuiModal: {
      defaultProps: {
        mountNode: shadowRootElement,
      },
    },
  },
});

@arminbashizade arminbashizade changed the title Add mountNode input to Modal Add mountNode prop to Modal Dec 15, 2023
@arminbashizade arminbashizade changed the title Add mountNode prop to Modal [mui-material][Modal] Add mountNode prop to Modal Dec 15, 2023
@mui-bot

mui-bot commented Dec 15, 2023

Copy link
Copy Markdown

Netlify deploy preview

https://deploy-preview-40211--material-ui.netlify.app/

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against 19f6d86

@zannager zannager added the scope: modal Changes related to the modal. label Dec 15, 2023
@zannager
zannager requested a review from mnajdova December 15, 2023 11:03
@danilo-leal danilo-leal changed the title [mui-material][Modal] Add mountNode prop to Modal [material-ui][Modal] Add the mountNode prop Dec 15, 2023
@danilo-leal danilo-leal added type: new feature Expand the scope of the product to solve a new problem. package: material-ui labels Dec 15, 2023
@ZeeshanTamboli

Copy link
Copy Markdown
Member

Closing in favor of #48826. We don't need a new prop. When the container is inside a Shadow Root, we can apply the scrollbar compensation directly to document.body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: modal Changes related to the modal. type: new feature Expand the scope of the product to solve a new problem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ModalManager] Dialog in Shadow DOM creates scroll jump

6 participants