Portal
Edit this pageWhen an element requires rendering outside of the usual document flow, challenges related to stacking contents and z-index can interfere with the desired intention or look of an application.
<Portal>
helps with this by putting elements in a different place in the document, bringing an element into the document flow so they can render as expected.
The content nested within <Portal>
is rendered and positioned by default at the end of the document body.
This can be changed by passing a mount
prop to <Portal>
.
The mount
prop accepts a DOM node, which will be used as the mount point for the portal content.
Using <Portal>
can be particularly useful in cases where elements, like information popups, might be clipped or obscured due to the overflow settings of their parent elements.
By putting the element outside of the parent element, it is no longer bound by the overflow settings of its parent.
This creates a more accessible experience for users, as the content is no longer obscured.
<Portal>
will render wrapped unless specifically targeting document.head
.
This is so events propagate through the Portal according to the component hierarchy instead of the elements hierarchy.
By default, children will wrap in a <div>
. If you portal into an SVG, then the isSVG
prop must be used to avoid wrapping the children in a <div>
and wrap in a <g>
instead.