-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[docs] Base Portal style revisions and final review #32157
[docs] Base Portal style revisions and final review #32157
Conversation
Co-authored-by: Michał Dudak <[email protected]>
## Basic usage | ||
|
||
Normally, children of a component are rendered within that component's DOM tree. | ||
But sometimes it's necessary to mount a child to a different location in the DOM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? We should give here example/explanation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a little bit of rearranging to elaborate on this. Let me know what you think!
@@ -8,18 +8,28 @@ packageName: '@mui/base' | |||
|
|||
# Portal | |||
|
|||
<p class="description">The portal component renders its children into a new "subtree" outside of the current DOM hierarchy.</p> | |||
<p class="description">The <code>Portal</code> component lets you render its children into a DOM node that exists outside of its own DOM hierarchy.</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work with Google:
<meta name="description" content="The <code>Portal</code> component lets you render its children into a DOM node that exists outside of its own DOM hierarchy."/>
It would show like this, no go
I think that the following would be better, not talking about React, but the pattern in general and without a disturbing style change:
<p class="description">The <code>Portal</code> component lets you render its children into a DOM node that exists outside of its own DOM hierarchy.</p> | |
<p class="description">The portal component lets you render its children into a DOM node that exists outside of its own DOM hierarchy.</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah shoot, this is something we'll have to fix across the board with the Base docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible to duplicate the description, having one specific for SEO, but personally, I would encourage we make a change so that the docs throw an error when <code>
or any HTML element is used in the description (easy change)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. Two descriptions could get messy pretty quickly. I think we should still capitalize it here at least, since we're talking about our specific component rather than the general concept.
|
||
The children of the portal component will be appended to the `container` specified. | ||
The component is used internally by the [`Modal`](/material-ui/react-modal/) and [`Popper`](/material-ui/react-popper/) components. | ||
`Portal` is a utility component built around [React's `createPortal()` API](https://reactjs.org/docs/portals.html). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It think that we can keep the content more "lightweight" (easier to read, less style change interruption) with:
`Portal` is a utility component built around [React's `createPortal()` API](https://reactjs.org/docs/portals.html). | |
Portal is a utility component built around [React's `createPortal()` API](https://reactjs.org/docs/portals.html). |
We don't need to really React in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's helpful here to differentiate between Portal
(the component) vs. any generic portal generated by the createPortal()
API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The distinction already seems clear from "Portal is a utility component".
Looking at the Material UI docs, we don't seem to be consistent in the use of backticks for component names. It does seem the be the predominant style, but it isn't necessarily better. The capitalisation seems sufficient, along with an indefinite article: "a portal" vs. "Portal"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the Material UI docs, we don't seem to be consistent in the use of backticks for component names. It does seem the be the predominant style, but it isn't necessarily better. The capitalisation seems sufficient, along with an indefinite article: "a portal" vs. "Portal"
I thought we had established a house rule for this in the Style guide, but I'm not seeing anything about it now that I'm looking through it. Must have been deep in some PR comments somewhere.
In the Base docs, I've been trying to stick to a consistent format of backticks and capitalization anytime I'm referring to the component specifically, in the interest of being as clear and precise as possible.
In any case, this is a question that applies to all of the Base docs, so I propose that we leave it as is for now, and continue this conversation about formatting to my next PR which will be a final pass covering all of these pages.
Co-authored-by: Matt <[email protected]>
Co-authored-by: Matt <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
@@ -8,18 +8,33 @@ packageName: '@mui/base' | |||
|
|||
# Portal | |||
|
|||
<p class="description">The portal component renders its children into a new "subtree" outside of the current DOM hierarchy.</p> | |||
<p class="description">The Portal component lets you render its children into a DOM node that exists outside of its own DOM hierarchy.</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For most other components we describe the general use, so:
<p class="description">The Portal component lets you render its children into a DOM node that exists outside of its own DOM hierarchy.</p> | |
<p class="description">A portal lets you render its children into a DOM node that exists outside of its own DOM hierarchy.</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been doing a mix of both across the Base docs—sometimes one makes more sense than the other. See: Button vs Click-away listener.
In the case of the Portal, I think it makes sense either way.
See [this GitHub issue](https://github.com/facebook/react/issues/13097) for details. | ||
::: | ||
|
||
The `Portal` component cannot be used to render child elements on the server—client-side hydration is necessary. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The `Portal` component cannot be used to render child elements on the server—client-side hydration is necessary. | |
Portal can't be used to render child elements on the server—client-side hydration is necessary. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as this comment, I propose we return to this question in the next PR that I will open for a final pass across all Base docs at once.
Once finalised is the content going to be copied in the Material UI docs? |
Great question! There is some overlap between the Base and Material UI docs, so when I do move on to revamp the latter in the next couple months, I will most likely start with these pages. Unless you think we should move this content over ASAP. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Looking for an example on how to integrate a portal in two separate child components in the component tree, I stumbled over this issue here. I would really wish there would be a more complex example in the MUI documentation that shows how to do that. The current documentation is kindof simple in terms of the container ref being used in a single component. There might be a basic React solution how to do that but some pointers or hints on this page would be really helpful (for me at least). Once I've found out how to do this, I might be able to contribute but right now I'm still looking for the solution to this problem. |
Could you explain what you mean by "two separate child components in the component tree"? |
@michaldudak thanks for your response! This was my use case: The app has a toolbar, a drawer with RouterTab navigation, and main content. The toolbar might contain different actions based on the selected route. The component with the main content would have the business logic which actions to show in the toolbar. I've solved it now using state, and will use more Redux more heavily to do that. Which is probably what I should have done from the beginning? Thanks! |
This PR reviews the
Portal
doc. The content is sparse but that makes sense because there isn't much to say. 🤷♂️ This one is pretty deep in the weeds, but I think it would be worthwhile to elaborate on its use cases.Edit: the second draft explains more about portals and their usage.
https://deploy-preview-32157--material-ui.netlify.app/base/react-portal/