Client component

Portal

Renders its children into document.body (or a container you choose) instead of where the component sits in the tree. Content in a portal escapes the overflow: hidden and stacking context of its ancestors, which is why Modal, Drawer, Menu, Popover and the Toaster all render through it. Reach for it directly when you build a custom overlay.

This box clips anything that overflows it. The card renders into the document body, so the clipping never reaches it.

Import#

import { Portal } from "astralis-ui";

Usage#

Portalled content keeps its React context: events bubble to React parents and the theme still applies, because Portal wraps its children in the library's scoping class. The wrapper uses display: contents, so it never affects the position of what you render.

Portal renders nothing on the server, and its children appear in the first client render, in the same commit as the component that opened them. That lets a positioned panel be measured as soon as it mounts.

<Portal container={document.getElementById("overlay-root") ?? undefined}>
  <Backdrop />
</Portal>

Props#

PropTypeDefaultDescription
childrenReactNodeNoneThe content to render elsewhere.
containerHTMLElementdocument.bodyThe element to render into.

Portal has no playground: it has no appearance of its own to configure.