Overlay Components
[06] Overlay Components
Popup
A floating element anchored to a trigger element using CSS Anchor Positioning. Supports 12 placement options, width matching, and click-outside dismissal.
Popup holds content that floats beside the element that opened it, and Menu and Tooltip are built on it. It renders a <div> with role="dialog" unless role says otherwise. For a short hover hint, use a Tooltip; for a dialog that blocks the page, use a Modal. Its surface defaults are md, flex column, padding, gap, rounded, border, shadow, primary, outline, wFit and placeBottom.
Browser support: Popup uses the CSS Anchor Positioning API (Chrome/Edge 129+, for the span-* alignment it relies on). Other browsers fall back to a JS positioning path that recomputes on scroll/resize.
Basic usage
A controlled floating element anchored to a button. Closes on outside click or Escape. Pass an anchorRef pointing at the trigger element.
const [open, setOpen] = useState(false);const anchorRef = useRef<HTMLButtonElement>(null);
return ( <> <Button ref={anchorRef} onClick={() => setOpen(!open)}>Toggle</Button> <Popup open={open} onClose={() => setOpen(false)} anchorRef={anchorRef}> <Text>Popup content</Text> </Popup> </>);Uncontrolled with defaultOpen
Skip open/onClose and let Popup manage its own state. Use onOpenChange to react to opens/closes without owning the state.
const anchorRef = useRef<HTMLButtonElement>(null);
return ( <> <Button ref={anchorRef}>Trigger</Button> <Popup defaultOpen anchorRef={anchorRef} onOpenChange={(o) => console.log(o)}> <Text>Uncontrolled popup</Text> </Popup> </>);PopupTrigger (click)
PopupTrigger is a convenience wrapper that manages open/close state and ref wiring automatically. No useState or useRef needed: wrap the trigger element and provide popup content via the popup prop. Default trigger mode is "click".
<PopupTrigger popup={<Text sm>Click-triggered popup</Text>}> <Button>Click Me</Button></PopupTrigger>PopupTrigger (hover)
Set triggerOnHover to show on mouse enter and hide on mouse leave. openDelay (default 0) delays appearance; closeDelay (default 150) delays dismissal so the user can move the cursor over the popup. Keyboard focus also opens it for accessibility.
<PopupTrigger triggerOnHover openDelay={200} popup={<Text sm>Tooltip text</Text>}> <Button>Hover Me</Button></PopupTrigger>PopupTrigger (focus)
Set triggerOnFocus to show on focus and hide on blur. Useful for search autocomplete, input hints, and dropdown suggestions.
<PopupTrigger triggerOnFocus popup={<Text sm>Search suggestions...</Text>}> <Input placeholder="Search..." /></PopupTrigger>All 12 placements
Placement is set via boolean props: placeTop, placeTopStart, placeTopEnd, placeBottom, placeBottomStart, placeBottomEnd, placeLeft, placeLeftStart, placeLeftEnd, placeRight, placeRightStart, placeRightEnd. Exactly one wins (first-truthy per category). Default is placeBottom.
const ref = useRef<HTMLButtonElement>(null);const [open, setOpen] = useState(false);
return ( <> <Button ref={ref} onClick={() => setOpen(!open)}>Anchor</Button>
{/* Above the anchor, aligned to the anchor's left edge */} <Popup placeTopStart open={open} onClose={() => setOpen(false)} anchorRef={ref}> <Text>Top Start</Text> </Popup>
{/* Centered to the right of the anchor */} <Popup placeRight open={open} onClose={() => setOpen(false)} anchorRef={ref}> <Text>Right</Text> </Popup>
{/* Below the anchor, aligned to the anchor's right edge */} <Popup placeBottomEnd open={open} onClose={() => setOpen(false)} anchorRef={ref}> <Text>Bottom End</Text> </Popup> </>);When the requested placement would overflow the viewport, Popup falls back through flip-block → flip-inline → shift → clamp and exposes the resolved placement via the data-placement attribute.
Size, shape, variant and appearance
Popup is md, rounded, outline and primary by default. Size drives the frame's padding, gap and radius together.
const xsRef = useRef<HTMLButtonElement>(null);const xlRef = useRef<HTMLButtonElement>(null);const sharpRef = useRef<HTMLButtonElement>(null);const filledRef = useRef<HTMLButtonElement>(null);
return ( <Row flexWrap> <Button ref={xsRef}>xs</Button> <Popup xs defaultOpen anchorRef={xsRef}><Text xs>Extra small frame</Text></Popup>
<Button ref={xlRef}>xl</Button> <Popup xl defaultOpen anchorRef={xlRef}><Text>Extra large frame</Text></Popup>
<Button ref={sharpRef}>sharp</Button> <Popup sharp defaultOpen anchorRef={sharpRef}><Text>Sharp corners</Text></Popup>
<Button ref={filledRef}>filled info</Button> <Popup filled info defaultOpen anchorRef={filledRef}><Text>Filled info surface</Text></Popup> </Row>);Match anchor width
matchWidth makes the popup track the anchor's width, useful for select-like dropdowns. It sets the popup width to the anchor's width, overriding the default wFit.
const [open, setOpen] = useState(false);const anchorRef = useRef<HTMLButtonElement>(null);
return ( <> <Button ref={anchorRef} onClick={() => setOpen(!open)} wFull>Select option</Button> <Popup matchWidth open={open} onClose={() => setOpen(false)} anchorRef={anchorRef}> <Text>Same width as the anchor</Text> </Popup> </>);Rich content
Children render directly inside the Popup surface. Use layout primitives (Col, Row, Stack) to compose multi-element content. Avoid nesting another Card inside; Popup already provides the bordered, padded, shadowed surface.
const [open, setOpen] = useState(false);const anchorRef = useRef<HTMLButtonElement>(null);
return ( <> <Button ref={anchorRef} onClick={() => setOpen(!open)}>Account</Button> <Popup open={open} onClose={() => setOpen(false)} anchorRef={anchorRef}> <Text fontBold>User Menu</Text> <Divider /> <Button>Profile</Button> <Button danger>Sign Out</Button> </Popup> </>);Tooltip pattern
Pair triggerOnHover with arrow for a classic tooltip. The arrow auto-rotates to match the resolved placement.
<PopupTrigger triggerOnHover openDelay={300} popupProps={{ placeTop: true, arrow: true, role: "tooltip", sm: true }} popup={<Text sm>Save your changes to the server</Text>}> <Button>Save</Button></PopupTrigger>Dropdown via Popup
Popup is a low-level primitive. For action menus with keyboard navigation, focus management, and item semantics, prefer the dedicated Menu component. It wraps Popup and adds MenuItem/MenuLabel with full arrow-key navigation. Reach for raw Popup only when you need a non-menu surface (filter panels, custom autocompletes, info cards).
<PopupTrigger popup={ <> <Button transparent justifyStart>Edit</Button> <Button transparent justifyStart>Duplicate</Button> <Divider /> <Button transparent justifyStart danger>Delete</Button> </>}> <Button>Actions</Button></PopupTrigger>Arrow indicator
Set arrow to render a pointer that visually links the popup to its anchor. The arrow is positioned automatically based on the resolved placement. With an arrow, offset is measured from the arrow tip, so the tip sits offset pixels from the anchor and never overlaps it (@vaneui/ui 1.5.0 or later).
const [open, setOpen] = useState(false);const anchorRef = useRef<HTMLButtonElement>(null);
return ( <> <Button ref={anchorRef} onClick={() => setOpen(!open)}>Toggle Arrow Popup</Button> <Popup arrow open={open} onClose={() => setOpen(false)} anchorRef={anchorRef}> <Text sm>Arrow points at the anchor.</Text> </Popup> </>);Click-outside behavior
By default, clicking anywhere outside the popup or anchor closes it. Set closeOnClickOutside={false} to require an explicit dismiss (e.g., a close button inside the popup). closeOnEscape={false} similarly disables the keyboard dismiss.
const [open, setOpen] = useState(false);const anchorRef = useRef<HTMLButtonElement>(null);
return ( <> <Button ref={anchorRef} onClick={() => setOpen(true)}>Open Sticky Popup</Button> <Popup open={open} onClose={() => setOpen(false)} anchorRef={anchorRef} closeOnClickOutside={false} closeOnEscape={false} > <Text>Stays open until dismissed.</Text> <Button sm onClick={() => setOpen(false)}>Close</Button> </Popup> </>);Disabled trigger
Set disabled on Popup (or PopupTrigger) to suppress opening regardless of open state. Useful for conditional UI where the trigger remains rendered but inactive.
<PopupTrigger disabled popup={<Text>Hidden</Text>}> <Button disabled>Cannot open</Button></PopupTrigger>Advanced props
Popup supports additional configuration props:
| Prop | Default | Description |
|---|---|---|
offset | 4 | Distance from anchor in pixels; with arrow, measured from the arrow tip |
style | Merged with the positioning styles, which win on a conflict (before 1.5.0 it replaced them) | |
closeOnEscape | true | Close on Escape key press |
closeOnClickOutside | true | Close when clicking outside the popup or anchor |
portal | true | Render via portal into document.body |
keepMounted | false | Keep DOM node mounted when closed |
noAnimation | false | Disable enter/exit transitions |
transitionDuration | 200 | Animation duration in ms |
disabled | false | Prevent popup from opening |
hideWhenDetached | false | Hide when anchor scrolls out of view (uses IntersectionObserver) |
role | "dialog" | ARIA role (set "tooltip" for tooltip patterns) |
arrow | false | Render arrow pointer |
onEnterComplete | Called when the enter transition finishes | |
onExitComplete | Called when the exit transition finishes |
PopupTrigger additionally accepts:
| Prop | Default | Description |
|---|---|---|
triggerOnClick | true (when no other trigger set) | Toggle on click |
triggerOnHover | false | Open on mouse enter / focus |
triggerOnFocus | false | Open on focus only |
openDelay | 0 | ms before opening on hover |
closeDelay | 150 | ms before closing on hover-out |
popupProps | Props forwarded to the internal Popup | |
popupId | auto | Override generated id for aria-controls |
const [open, setOpen] = useState(false);const anchorRef = useRef<HTMLButtonElement>(null);
return ( <> <Button ref={anchorRef} onClick={() => setOpen(!open)}>Custom Config</Button> <Popup open={open} onClose={() => setOpen(false)} anchorRef={anchorRef} offset={8} noAnimation closeOnEscape={false} > <Text>Custom config</Text> </Popup> </>);Frequently asked questions
Does focus move into a Popup when it opens?
Only when you ask for it. PopupTrigger in click mode moves focus to the first focusable element inside, but a Popup used on its own leaves focus on its trigger unless you set autoFocus. The Popup renders at the end of <body>, so Tab from the trigger does not reach it otherwise. modal also traps Tab inside the Popup, returns focus on close and sets aria-modal.
Why don't the styles of the surrounding element reach my Popup?
The Popup renders through a portal at the end of <body>, so a selector such as .sidebar .vane-popup, the color or font a parent sets, and the data-theme of a wrapper do not apply to it. Style it with its own props and className. portal={false} renders it in place, but an ancestor with a transform or filter then becomes its containing block, which can shift or clip it.
How do I close a PopupTrigger popup from a button inside it?
Control the PopupTrigger: keep the open state in your component, pass it as open, update it in onOpenChange, and set it to false in the button's onClick. A click on the trigger, an outside click and Escape still call onOpenChange with the new state, so setting your state there keeps them working. Uncontrolled, PopupTrigger offers no close function to call.
Popup Props
| Prop | Category | Default | Description |
|---|---|---|---|
accent | Appearance | Accent color appearance (rose) | |
danger | Appearance | Danger color appearance (red) | |
info | Appearance | Info color appearance (cyan) | |
inheritAppearance | Appearance | Inherit appearance from parent — suppresses own data-appearance/data-variant, uses parent's CSS variables | |
primary | Appearance | ✓ | Primary color appearance (gray) |
secondary | Appearance | Secondary color appearance (gray) | |
success | Appearance | Success color appearance (green) | |
tertiary | Appearance | Tertiary color appearance | |
warning | Appearance | Warning color appearance (amber) | |
flex1 | Flex | Take up remaining space (= | |
flexAuto | Flex | Grow but respect intrinsic size (= | |
flexNone | Flex | Don't grow and don't shrink (= | |
fontHeading | Font Family | Heading font family (defaults to sans, customizable via --font-heading) — emits font-heading | |
fontMono | Font Family | Monospace font family — emits font-mono | |
fontSans | Font Family | ✓ | Sans-serif font family (default) — emits font-sans |
fontSerif | Font Family | Serif font family — emits font-serif | |
italic | Font Style | Italic font style | |
notItalic | Font Style | Not italic (normal) font style | |
fontBlack | Font Weight | Black font weight (900) — emits font-black | |
fontBold | Font Weight | Bold font weight (700) — emits font-bold | |
fontExtrabold | Font Weight | Extra bold font weight (800) — emits font-extrabold | |
fontExtralight | Font Weight | Extra light font weight (200) — emits font-extralight | |
fontLight | Font Weight | Light font weight (300) — emits font-light | |
fontMedium | Font Weight | Medium font weight (500) — emits font-medium | |
fontNormal | Font Weight | Normal font weight (400) — emits font-normal | |
fontSemibold | Font Weight | Semibold font weight (600) — emits font-semibold | |
fontThin | Font Weight | Thin font weight (100) — emits font-thin | |
noPadding | Padding | Disable internal padding | |
padding | Padding | ✓ | Enable internal padding |
paddingX | Padding | Enable only horizontal padding | |
paddingY | Padding | Enable only vertical padding | |
placeBottom | Placement | ✓ | Position below anchor, centered horizontally |
placeBottomEnd | Placement | Position below anchor, aligned to end (right) | |
placeBottomStart | Placement | Position below anchor, aligned to start (left) | |
placeLeft | Placement | Position to the left of anchor, centered vertically | |
placeLeftEnd | Placement | Position to the left of anchor, aligned to bottom | |
placeLeftStart | Placement | Position to the left of anchor, aligned to top | |
placeRight | Placement | Position to the right of anchor, centered vertically | |
placeRightEnd | Placement | Position to the right of anchor, aligned to bottom | |
placeRightStart | Placement | Position to the right of anchor, aligned to top | |
placeTop | Placement | Position above anchor, centered horizontally (default) | |
placeTopEnd | Placement | Position above anchor, aligned to end (right) | |
placeTopStart | Placement | Position above anchor, aligned to start (left) | |
pill | Shape | Fully rounded corners (circular) | |
rounded | Shape | ✓ | Medium rounded corners (default) |
sharp | Shape | No rounded corners (square) | |
noShrink | Shrink | Prevent the flex item from shrinking below its content size (= | |
lg | Size | Large size | |
md | Size | ✓ | Medium size (default) |
sm | Size | Small size | |
xl | Size | Extra large size | |
xs | Size | Extra small size | |
skeleton | Skeleton | Show the component as a loading placeholder in its own size and shape. On a container, every component inside it becomes a placeholder too | |
textCenter | Text Align | Align text to center | |
textEnd | Text Align | Align text to the reading-direction end (right in LTR, left in RTL) | |
textJustify | Text Align | Justify text | |
textLeft | Text Align | Align text to left (physical side, does not flip under RTL) | |
textRight | Text Align | Align text to right (physical side, does not flip under RTL) | |
textStart | Text Align | Align text to the reading-direction start (left in LTR, right in RTL) | |
lineThrough | Text Decoration | Add strikethrough/line-through decoration across text | |
noUnderline | Text Decoration | Remove ALL text-decoration — underline, line-through, and overline (text-decoration: none) | |
overline | Text Decoration | Add overline decoration above text | |
underline | Text Decoration | Add underline decoration below text | |
capitalize | Text Transform | Capitalize first letter of each word | |
lowercase | Text Transform | Transform text to lowercase | |
normalCase | Text Transform | Normal text case (no transformation) | |
uppercase | Text Transform | Transform text to uppercase | |
lineClamp2 | Truncate | Truncate at 2 lines with ellipsis | |
lineClamp3 | Truncate | Truncate at 3 lines with ellipsis | |
lineClamp4 | Truncate | Truncate at 4 lines with ellipsis | |
lineClamp5 | Truncate | Truncate at 5 lines with ellipsis | |
noTruncate | Truncate | Remove truncation | |
truncate | Truncate | Single line truncation with ellipsis | |
filled | Variant | Filled variant - solid background with contrasting text color | |
ghost | Variant | Ghost variant - transparent background, no border, appearance-colored text, tinted hover background | |
outline | Variant | ✓ | Outline variant - transparent background with border and colored text (default) |
Layout & utility props (gap, padding, hide, items, justify, ...)
Documented on Common Props.
| Prop | Category | Default | Description |
|---|---|---|---|
alignSelfAuto | Align Self | Use the parent's align-items value (align-self: auto) | |
alignSelfBaseline | Align Self | Align this item to its baseline (align-self: baseline) | |
alignSelfCenter | Align Self | Center this item on the cross axis (align-self: center) | |
alignSelfEnd | Align Self | Align this item to the end of the cross axis (align-self: flex-end) | |
alignSelfStart | Align Self | Align this item to the start of the cross axis (align-self: flex-start) | |
alignSelfStretch | Align Self | Stretch this item to fill the cross axis (align-self: stretch) | |
border | Border | ✓ | Enable border on all sides |
borderB | Border | Enable border on bottom | |
borderEnd | Border | Enable border on the inline-end side (right in LTR, left in RTL) | |
borderL | Border | Enable border on left | |
borderR | Border | Enable border on right | |
borderStart | Border | Enable border on the inline-start side (left in LTR, right in RTL) | |
borderT | Border | Enable border on top | |
borderX | Border | Enable border on left and right | |
borderY | Border | Enable border on top and bottom | |
noBorder | Border | Disable all borders | |
clampHeight | Clamp Height | Clamp to a size-dependent maximum height (uses --max-height CSS variable) | |
constrainWidth | Constrain Width | Constrain to a size-dependent minimum width (uses --popup-min-w CSS variable) | |
block | Display | Block display - takes full width, new line | |
contents | Display | Contents display - element's box is removed, children display as if parent didn't exist | |
flex | Display | ✓ | Flex display - flexbox container |
grid | Display | Grid display - CSS grid container | |
hidden | Display | Hidden display - element is not visible | |
inline | Display | Inline display - flows with text | |
inlineBlock | Display | Inline-block display - inline but with block properties | |
inlineFlex | Display | Inline-flex display - inline flexbox container | |
inlineGrid | Display | Inline-grid display - inline grid container | |
table | Display | Table display - behaves like table element | |
tableCell | Display | Table-cell display - behaves like td element | |
column | Flex Direction | ✓ | Flex direction column (vertical) |
columnReverse | Flex Direction | Flex direction column-reverse | |
row | Flex Direction | Flex direction row (horizontal) | |
rowReverse | Flex Direction | Flex direction row-reverse | |
gap | Gap | ✓ | Enable gap spacing between children, at the component's size |
gapLg | Gap | Large gap, whatever the component's size | |
gapMd | Gap | Medium gap, whatever the component's size | |
gapSm | Gap | Small gap, whatever the component's size | |
gapXl | Gap | Extra-large gap, whatever the component's size | |
gapXs | Gap | Extra-small gap, whatever the component's size | |
noGap | Gap | Disable gap spacing | |
hAuto | Height | Set height to auto | |
hFit | Height | Set height to fit-content | |
hFull | Height | Set height to 100% | |
hScreen | Height | Set height to 100vh (viewport height), removes max-height constraint | |
desktopHide | Hide | Hide element on desktop devices and below (max-desktop: 80rem) | |
mobileHide | Hide | Hide element on mobile devices and below (max-mobile: 48rem) | |
tabletHide | Hide | Hide element on tablet devices and below (max-tablet: 64rem) | |
itemsBaseline | Items | Align items to baseline | |
itemsCenter | Items | Align items to center | |
itemsEnd | Items | Align items to end (bottom/right) | |
itemsStart | Items | Align items to start (top/left) | |
itemsStretch | Items | Stretch items to fill container | |
justifyAround | Justify | Distribute items with space around them | |
justifyBaseline | Justify | Align items along their baseline on main axis | |
justifyBetween | Justify | Distribute items with space between them | |
justifyCenter | Justify | Center items along the main axis | |
justifyEnd | Justify | Pack items toward the end of the main axis | |
justifyEvenly | Justify | Distribute items with equal space around them | |
justifyStart | Justify | Pack items toward the start of the main axis | |
justifyStretch | Justify | Stretch items to fill the main axis | |
justifySelfAuto | Justify Self | Use the parent's justify-items value (justify-self: auto) | |
justifySelfCenter | Justify Self | Center this item on the inline axis (justify-self: center) | |
justifySelfEnd | Justify Self | Align this item to the end of the inline axis (justify-self: end) | |
justifySelfStart | Justify Self | Align this item to the start of the inline axis (justify-self: start) | |
justifySelfStretch | Justify Self | Stretch this item to fill the inline axis (justify-self: stretch) | |
overflowAuto | Overflow | Auto overflow - show scrollbars if needed | |
overflowClip | Overflow | Clip overflow - hard clip without scrollbars | |
overflowHidden | Overflow | Hidden overflow - clip content without scrollbars | |
overflowScroll | Overflow | Scroll overflow - always show scrollbars | |
overflowVisible | Overflow | Visible overflow - content extends beyond bounds | |
overflowXAuto | Overflow | Auto overflow on X-axis only | |
overflowXClip | Overflow | Clip overflow on X-axis only | |
overflowXHidden | Overflow | Hidden overflow on X-axis only | |
overflowXScroll | Overflow | Scroll overflow on X-axis only | |
overflowXVisible | Overflow | Visible overflow on X-axis only | |
overflowYAuto | Overflow | Auto overflow on Y-axis only | |
overflowYClip | Overflow | Clip overflow on Y-axis only | |
overflowYHidden | Overflow | Hidden overflow on Y-axis only | |
overflowYScroll | Overflow | Scroll overflow on Y-axis only | |
overflowYVisible | Overflow | Visible overflow on Y-axis only | |
pointerEventsAuto | Pointer Events | Enable pointer events (default browser behavior) | |
pointerEventsNone | Pointer Events | Disable pointer events - clicks pass through the element | |
absolute | Position | Absolute positioning | |
fixed | Position | ✓ | Fixed positioning |
relative | Position | Relative positioning | |
static | Position | Static positioning | |
sticky | Position | Sticky positioning at the top edge; set --sticky-top to stick below a fixed header | |
responsiveSizing | Responsive Sizing | ✓ | Enable responsive sizing - uses breakpoint-specific classes for font size, padding, and gap |
desktopWFull | Responsive Width | Set width to 100% on desktop and below, below 1280px (max-desktop: 80rem) | |
mobileWFull | Responsive Width | Set width to 100% on mobile, below 768px (max-mobile: 48rem) | |
tabletWFull | Responsive Width | Set width to 100% on tablet and below, below 1024px (max-tablet: 64rem) | |
insetRing | Ring | Enable the inset ring — emits ring-inset | |
noInsetRing | Ring | Disable the inset ring | |
noShadow | Shadow | Disable drop shadow | |
shadow | Shadow | ✓ | Enable drop shadow at the component's size |
shadowLg | Shadow | Large drop shadow, whatever the component's size | |
shadowMd | Shadow | Medium drop shadow, whatever the component's size | |
shadowSm | Shadow | Small drop shadow, whatever the component's size | |
shadowXl | Shadow | Extra-large drop shadow, whatever the component's size | |
shadowXs | Shadow | Extra-small drop shadow, whatever the component's size | |
desktopShow | Show | Show element only on desktop and below, below 1280px (hidden from 80rem up) | |
mobileShow | Show | Show element only on mobile, below 768px (hidden from 48rem up) | |
tabletShow | Show | Show element only on tablet and below, below 1024px (hidden from 64rem up) | |
noTransition | Transition | Disable transitions for instant state changes | |
transition | Transition | Enable smooth transitions between states | |
transparent | Transparent | Disable background color - makes component background transparent | |
wAuto | Width | Set width to auto | |
wFit | Width | ✓ | Set width to fit-content |
wFull | Width | Set width to 100% | |
wScreen | Width | Set width to 100vw (viewport width), removes max-width constraint | |
flexNoWrap | Wrap | Force flex items to stay on single line (may overflow) | |
flexWrap | Wrap | Allow flex items to wrap to new lines when container is too narrow | |
flexWrapReverse | Wrap | Wrap flex items in reverse order (last items wrap first) |