Fidely UI v1 beta is now available!. 🚀

Portal

Used to render an element outside the DOM hierarchy.

Usage

The Portal uses the ReactDOM.createPortal API to render an element at the end of document.body or specific container.

import { Portal } from '@fidely-ui/react'
<Portal>
  <div>From Portal</div>
</Portal>

Custom Container

Use the container prop to render the portal in a custom container.

import { Portal } from '@fidely-ui/react/portal'

const Container = () => {
  const ref = React.useRef()
  return (
    <>
      <Portal container={ref}>
        <div>Portal content</div>
      </Portal>
      <div ref={containerRef} />
    </>
  )
}

Disabled

Use the disabled prop to disable the portal. This will render the children in the same DOM hierarchy.

import { Portal } from '@fidely-ui/react/portal'

const Disabled = () => {
  return (
    <Portal disabled>
      <div>Portal disabled in place</div>
    </Portal>
  )
}

Props

PropTypeDefaultDescription
asReact.ElementType-The underlying element to render.
asChildbooleanfalseUse the provided child element as the default rendered element.
disabledboolean—-
containerRefObject<HTMLElement | null>nullThe content to render on the server or before the client has mounted.