Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting default portal container #19552

Closed
sandorvasas opened this issue Feb 4, 2020 · 9 comments
Closed

Setting default portal container #19552

sandorvasas opened this issue Feb 4, 2020 · 9 comments
Labels
component: Portal The React component. support: question Community support but can be turned into an improvement

Comments

@sandorvasas
Copy link

sandorvasas commented Feb 4, 2020

Hi,
How is it possible to set the default portal container for MUI? I need to use the global portal, but I also need the elements to appear inside my root div, so they are still inside various <XXProvider> components. We have a large app and it'd be tedious to refactor each component to use its own <Portal>.

@eps1lon eps1lon added the support: Stack Overflow Please ask the community on Stack Overflow label Feb 4, 2020
@support
Copy link

support bot commented Feb 4, 2020

👋 Thanks for using Material-UI!

We use GitHub issues exclusively as a bug and feature requests tracker, however,
this issue appears to be a support request.

For support, please check out https://material-ui.com/getting-started/support/. Thanks!

If you have a question on StackOverflow, you are welcome to link to it here, it might help others.
If your issue is subsequently confirmed as a bug, and the report follows the issue template, it can be reopened.

@support support bot closed this as completed Feb 4, 2020
@oliviertassinari
Copy link
Member

oliviertassinari commented Feb 4, 2020

(It's possible)

@sandorvasas
Copy link
Author

I'm reposting this as a bug as I find there's no global portal setting for its container.

@oliviertassinari oliviertassinari added component: Portal The React component. and removed support: Stack Overflow Please ask the community on Stack Overflow labels Feb 4, 2020
@support support bot reopened this Feb 4, 2020
@oliviertassinari oliviertassinari added the new feature New feature or request label Feb 4, 2020
@oliviertassinari
Copy link
Member

oliviertassinari commented Feb 4, 2020

Right, this seems accurate. We could introduce a getThemeProps into the Portal component so developers can set a container prop globally with theme.props.MuiPortal.container.

The workaround is to set the prop it at the parent level.

@oliviertassinari oliviertassinari added status: waiting for author Issue with insufficient information and removed new feature New feature or request labels Feb 4, 2020
@oliviertassinari
Copy link
Member

oliviertassinari commented Feb 4, 2020

so they are still inside various components.

@sandorvasas I'm confused by this part. What's your use case for not using document.body as a DOM container of the portals?

@oliviertassinari
Copy link
Member

but I want the elements to appear inside the root div of the app, so they are still wrapped in the appwise components (Redux, Apollo, etc).

Ok, it seems to answer my previous question. So you don't need to change the container.

@oliviertassinari oliviertassinari added support: question Community support but can be turned into an improvement and removed status: waiting for author Issue with insufficient information labels Feb 6, 2020
@sag1v
Copy link

sag1v commented Jan 7, 2021

@olegberman Isn't this a bug? Considering theres no way to pass props to Portal via the theme like any other component.
If you do consider this as a bug, will this get fixed in v4 as well?

BTW, a lot of use cases of containers are related to shadow-dom

@oliviertassinari
Copy link
Member

See #17473 for the support of shadow dom. It's not something we are supporting natively.

@SuchMonkey
Copy link

Setting default props for the Portal via the theme would indeed be very helpful. Alternatively a PortalRootProvider component could also work. Similar to the CacheProvider component where we can specify the insertion point for generated css.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: Portal The React component. support: question Community support but can be turned into an improvement
Projects
None yet
Development

No branches or pull requests

5 participants