Skip to content

Layout

Portal root

Names, once at the top of a tree, the element the kit's portals open in: a select's list, an alert dialog, a drawer.

Installation

Terminal
pnpm add @elsikora/keystone-ui-kit

Usage

Import
import { PortalRoot } from "@elsikora/keystone-ui-kit";
docs/portal-root/default.example.tsx
import { useState } from "react";
import { PortalRoot, Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@elsikora/keystone-ui-kit";
export default function PortalRootDefaultExample() {  const [root, setRoot] = useState<HTMLDivElement | null>(null);
  return (    <div className="flex w-full max-w-88 flex-col gap-3">      <PortalRoot container={root}>        <Select defaultValue="1">          <SelectTrigger aria-label="Clock">            <SelectValue />          </SelectTrigger>          <SelectContent>            <SelectItem value="0.25">0.25×</SelectItem>            <SelectItem value="1">1×</SelectItem>            <SelectItem value="4">4×</SelectItem>          </SelectContent>        </Select>      </PortalRoot>      <div ref={setRoot} data-portal-root="" />    </div>  );}

Examples

Default

The select's list opens in the element under it, not in the document's body.

API reference

PortalRoot

PropTypeDefaultDescription
containerElement | DocumentFragment | null-The element the kit's portals open in, for every part below it; null is the body.

Notes

  • A tree drawn in a shadow root sets an element of that root: the document's body, where portals open without it, is outside the reach of the root's sheet.
  • A part's own container prop wins over the PortalRoot's.