A portal component for rendering content in an overlay, supporting fixed positions, anchored positioning, backdrop variants, and offset control.
index.tsx styles.css
<Flex gap="4" wrap="wrap" align="center" justify="center" className="w-full" >
<Portal.Root >
<Portal.Trigger >
<Box className ="border" px ="2" py ="1" >
<Text > Open Portal</Text >
</Box >
</Portal.Trigger >
<Portal.Backdrop variant ="shadow" />
<Portal.Content >
<Box
p ="4"
m ="4"
className ="bg-[rgb(var(--bg-2))] border border-[rgb(var(--border-1))]"
>
<Text > Portal Content</Text >
</Box >
</Portal.Content >
</Portal.Root >
</Flex >
Anatomy
<Portal .Root >
<Portal.Trigger />
<Portal.Backdrop />
<Portal.Content />
</Portal .Root >
Examples
Positions
The position prop on Portal.Content controls where the content appears on screen. Available positions are tl, top, tr, left, center, right, bl, bottom, and br.
<Flex gap="4" wrap="wrap" align="center" justify="center" className="w-full" >
{["tl" , "top" , "tr" , "left" , "center" , "right" , "bl" , "bottom" , "br" ].map (
(position ) => (
<Portal.Root key ={position} >
<Portal.Trigger >
<Box className ="border" px ="2" py ="1" >
<Text > {position.toUpperCase()}</Text >
</Box >
</Portal.Trigger >
<Portal.Backdrop variant ="shadow" />
<Portal.Content position ={position} >
<Box
p ="4"
m ="4"
className ="bg-[rgb(var(--bg-2))] border border-[rgb(var(--border-1))]"
>
<Text > {position.toUpperCase()}</Text >
</Box >
</Portal.Content >
</Portal.Root >
),
)}
</Flex >
Variants
The Portal.Backdrop component supports three variants: clear, shadow, and blurred.
<Flex gap="4" wrap="wrap" align="center" justify="center" className="w-full" >
{["clear" , "shadow" , "blurred" ].map ((variant ) => (
<Portal.Root key ={variant} >
<Portal.Trigger >
<Box className ="border" px ="2" py ="1" >
<Text > {variant.charAt(0).toUpperCase() + variant.slice(1)}</Text >
</Box >
</Portal.Trigger >
<Portal.Backdrop variant ={variant} />
<Portal.Content >
<Panel variant ="outlined" p ="4" >
<Text > {variant.charAt(0).toUpperCase() + variant.slice(1)}</Text >
</Panel >
</Portal.Content >
</Portal.Root >
))}
</Flex >
Anchor
When the anchored prop is set on Portal.Content, the content is positioned relative to the trigger element.
<Flex gap="4" wrap="wrap" align="center" justify="center" className="w-full" >
<Portal.Root >
<Portal.Trigger >
<Box className ="border" px ="2" py ="1" >
<Text > Anchor</Text >
</Box >
</Portal.Trigger >
<Portal.Backdrop />
<Portal.Content anchored side ="bottom" align ="end" >
<Box className ="p-4 bg-[rgb(var(--bg-2))] border border-[rgb(var(--border-1))] rounded" >
<Text > Anchor</Text >
</Box >
</Portal.Content >
</Portal.Root >
</Flex >
Anchor Positions
The side prop controls which side of the trigger the anchored content appears on: top, right, bottom, or left.
<Flex gap="4" wrap="wrap" align="center" justify="center" className="w-full" >
{["top" , "right" , "bottom" , "left" ].map ((side ) => (
<Portal.Root key ={side} >
<Portal.Trigger >
<Box className ="border" px ="2" py ="1" >
<Text > {side.charAt(0).toUpperCase() + side.slice(1)}</Text >
</Box >
</Portal.Trigger >
<Portal.Backdrop />
<Portal.Content anchored side ={side} >
<Box className ="p-4 bg-[rgb(var(--bg-2))] border border-[rgb(var(--border-1))] rounded" >
<Text > {side.charAt(0).toUpperCase() + side.slice(1)}</Text >
</Box >
</Portal.Content >
</Portal.Root >
))}
</Flex >
Anchor Aligns
The align prop controls the alignment of the anchored content relative to the trigger: start, center, or end.
<Flex gap="4" wrap="wrap" align="center" justify="center" className="w-full" >
{["start" , "center" , "end" ].map ((align ) => (
<Portal.Root key ={align} >
<Portal.Trigger >
<Box className ="border" px ="2" py ="1" >
<Text > {align.charAt(0).toUpperCase() + align.slice(1)}</Text >
</Box >
</Portal.Trigger >
<Portal.Backdrop />
<Portal.Content anchored side ="bottom" align ={align} >
<Box className ="p-4 bg-[rgb(var(--bg-2))] border border-[rgb(var(--border-1))] rounded" >
<Text > {align.charAt(0).toUpperCase() + align.slice(1)}</Text >
</Box >
</Portal.Content >
</Portal.Root >
))}
</Flex >
Offset
Use sideOffset and alignOffset to fine-tune the position of anchored content.
<Flex gap="4" wrap="wrap" align="center" justify="center" className="w-full" >
<Portal.Root >
<Portal.Trigger >
<Box className ="border" px ="2" py ="1" >
<Text > Side Offset</Text >
</Box >
</Portal.Trigger >
<Portal.Backdrop />
<Portal.Content anchored side ="bottom" align ="start" sideOffset ="32" >
<Box className ="p-4 bg-[rgb(var(--bg-2))] border border-[rgb(var(--border-1))] rounded" >
<Text > Side Offset of 32px</Text >
</Box >
</Portal.Content >
</Portal.Root >
<Portal.Root >
<Portal.Trigger >
<Box className ="border" px ="2" py ="1" >
<Text > Align Offset</Text >
</Box >
</Portal.Trigger >
<Portal.Backdrop />
<Portal.Content anchored side ="bottom" align ="start" alignOffset ="32" >
<Box className ="p-4 bg-[rgb(var(--bg-2))] border border-[rgb(var(--border-1))] rounded" >
<Text > Align Offset of 32px</Text >
</Box >
</Portal.Content >
</Portal.Root >
</Flex >