View Source

Portal

A higher-order component for the rendering of components outside the normal React tree.

Portal is used in other components such as Popover to render content to places like the HTML <body> tag, avoiding style leakage and parent layout contexts. Only accepts a single top-level child; naked text, etc will be wrapped in a <div>.

Installation#

npm i --save boundless-portal

Portal can also just be directly used from the main Boundless library. This is recommended when you're getting started to avoid maintaining the package versions of several components:

npm i boundless --save

the ES6 import statement then becomes like:

import { Portal } from 'boundless';

Props#

Required Props#

There are no required props.

Optional Props#

NameImplementationDescription
*
Expects
any

any React-supported attribute

children
Expects
any renderable
Default Value
null

any normal React child, but must be singular; multiple sibling children must have a common wrapper, such as a "layout" <div>

✅ OK:

<Portal>
  foo
</Portal>

<Portal>
  <div>foo</div>
</Portal>

<Portal>
  <div>
      <div>foo</div>
      <div>bar</div>
  </div>
</Portal>

⛔️ Not OK:

<Portal>
  <div>foo</div>
  <div>bar</div>
</Portal>
destination
Expects
HTMLElement
Default Value
document.body

the location to append the generated portal and child elements

portalId
Expects
string
Default Value
null

the ID used to link the portal origin to the destination; added to generated <div> appended to the destination HTML node