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

[docs] Base Portal style revisions and final review #32157

Merged
merged 13 commits into from
May 12, 2022
Merged

[docs] Base Portal style revisions and final review #32157

merged 13 commits into from
May 12, 2022

Conversation

mapache-salvaje
Copy link
Contributor

@mapache-salvaje mapache-salvaje commented Apr 7, 2022

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/

@mapache-salvaje mapache-salvaje added docs Improvements or additions to the documentation component: Portal The React component. package: base-ui Specific to @mui/base labels Apr 7, 2022
@mui-bot
Copy link

mui-bot commented Apr 7, 2022

No bundle size changes

Generated by 🚫 dangerJS against 8973451

@mapache-salvaje mapache-salvaje requested a review from a team April 7, 2022 01:47
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 8, 2022
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 25, 2022
## 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.
Copy link
Member

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

Copy link
Contributor Author

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>
Copy link
Member

@oliviertassinari oliviertassinari May 4, 2022

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 &lt;code&gt;Portal&lt;/code&gt; 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

Screenshot 2022-05-04 at 17 40 29

I think that the following would be better, not talking about React, but the pattern in general and without a disturbing style change:

Suggested 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>

Screenshot 2022-05-04 at 17 42 54

Copy link
Contributor Author

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.

Copy link
Member

@oliviertassinari oliviertassinari May 4, 2022

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)

Copy link
Contributor Author

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).
Copy link
Member

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:

Suggested change
`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?

Copy link
Contributor Author

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.

Copy link
Member

@mbrookes mbrookes May 7, 2022

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"

Copy link
Contributor Author

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.

docs/data/base/components/portal/portal.md Show resolved Hide resolved
docs/data/base/components/portal/portal.md Outdated Show resolved Hide resolved
docs/data/base/components/portal/portal.md Outdated Show resolved Hide resolved
docs/data/base/components/portal/portal.md Outdated Show resolved Hide resolved
docs/data/base/components/portal/portal.md Outdated Show resolved Hide resolved
Copy link
Contributor

@danilo-leal danilo-leal left a 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>
Copy link
Member

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:

Suggested change
<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>

Copy link
Contributor Author

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Contributor Author

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.

@mbrookes
Copy link
Member

mbrookes commented May 7, 2022

Once finalised is the content going to be copied in the Material UI docs?

@mapache-salvaje
Copy link
Contributor Author

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.

Copy link
Member

@michaldudak michaldudak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mapache-salvaje mapache-salvaje merged commit feddf0e into mui:master May 12, 2022
@nuarhu
Copy link

nuarhu commented Jul 20, 2022

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.

@michaldudak
Copy link
Member

michaldudak commented Jul 27, 2022

Could you explain what you mean by "two separate child components in the component tree"?
Would you like to be able to render the same content in two places?

@nuarhu
Copy link

nuarhu commented Jul 29, 2022

@michaldudak thanks for your response!

This was my use case:

The app has a toolbar, a drawer with RouterTab navigation, and main content.
The main content changes based on the selection in the sidebar, which triggers a route change.

The toolbar might contain different actions based on the selected route.
The main content and the toolbar are different child components of a base component that contains the Outlet for the routing.

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!
Chantal

@mapache-salvaje mapache-salvaje deleted the base-portal-style-review branch April 3, 2024 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: Portal The React component. docs Improvements or additions to the documentation package: base-ui Specific to @mui/base
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants