The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
---
title: Popover
description: Display contextual content anchored to a trigger.
---
import { PageBanner } from "/snippets/page-banner.mdx"
import { StoryEmbed } from '/snippets/ui/StoryEmbed.mdx';
import PopoverReference from '/snippets/ui/generated/surfaces/popover.mdx';
## Overview
Use `Popover` for contextual information or lightweight controls. Compose its portal, positioning wrapper and popup separately. Use [Dropdown](/ui/components/navigation/dropdown) for menus, pickers and panels with higher-level navigation.
<StoryEmbed
storyId="ui-surfaces-popover--display"
title="Popover example"
height={280}
/>
## Usage
### Uncontrolled state
Use `defaultOpen` to set the initial visibility. The popover owns subsequent changes from its trigger, close controls, and dismissal interactions.
```tsx
import { Button } from 'twenty-ui/primitives/input';
import { Popover } from 'twenty-ui/primitives/surfaces';
export const ContactDetailsPopover = () => (
<Popover.Root defaultOpen={false}>
<Popover.Trigger render={<Button>Show details</Button>} />
<Popover.Portal>
<Popover.Positioner align="start">
<Popover.Popup
style={{ boxSizing: 'border-box', width: 260, padding: 16, gap: 12 }}
>
<Popover.Title>Contact details</Popover.Title>
<Popover.Description>
Reach Alex at [email protected].
</Popover.Description>
<Popover.Close
style={{ alignSelf: 'flex-end' }}
render={<Button size="sm">Close</Button>}
/>
</Popover.Popup>
</Popover.Positioner>
</Popover.Portal>
</Popover.Root>
);
```
`defaultOpen` defaults to `false`, so it can be omitted. Use `Title` and `Description` to identify the popup. The trigger renders a button by default; `render` lets you supply a compatible element.
## Placement comparison
Compare the supported sides with and without an arrow. These open examples keep each popup beside its trigger for inspection; use the Display example to try opening and dismissing a popover.
<StoryEmbed
storyId="ui-surfaces-popover--catalog"
title="Placement comparison for popover"
height={640}
/>
## Anatomy
Keep the trigger and popup inside `Popover.Root`. The popup can contain text, form controls, and actions.
```text
Popover.Root
├── Popover.Trigger
└── Popover.Portal
├── Popover.Backdrop (optional)
└── Popover.Positioner
└── Popover.Popup
├── Popover.Arrow (optional)
└── Popover.Viewport (optional)
├── Popover.Title
├── Popover.Description
└── Popover.Close
```
| Part | Purpose and native target |
| ------------- | --------------------------------------------------------------------------------- |
| `Root` | Owns state, triggers and interactions. Renders no DOM element. |
| `Trigger` | Opens the popup and supplies its default anchor. Targets a button. |
| `Portal` | Chooses the destination. Native props, handlers, `render` and ref target its div. |
| `Positioner` | Owns anchors, alignment, offsets and collision handling. Targets its div. |
| `Popup` | Renders content and manages focus. Targets its div. |
| `Arrow` | Optional styled arrow inside Popup. Targets its div. |
| `Backdrop` | Optional upstream backdrop inside Portal. Targets its div. |
| `Viewport` | Optional transition container for changing content. Targets its div. |
| `Title` | Supplies a visible accessible name. Targets an h2. |
| `Description` | Associates explanatory text. Targets a paragraph. |
| `Close` | Requests closing. Targets a button. |
All rendered parts support the installed Base UI native attributes, handlers, refs and element/function `render` composition. Custom components must forward the supplied props and ref. Every part has a public `Popover<Part>Props` and `Popover<Part>State` type. `PopoverRootProps` and `PopoverTriggerProps` preserve payload generics. `PopoverHandle`, `PopoverRootActions`, `PopoverRootChangeEventDetails` and `PopoverRootChangeEventReason` are also exported from `twenty-ui/primitives/surfaces`.
## Controlled state
Pass `open` and update it with `onOpenChange` to own the same popover's visibility in React state.
```tsx
import { useState } from 'react';
import { Button } from 'twenty-ui/primitives/input';
import { Popover } from 'twenty-ui/primitives/surfaces';
export const ContactDetailsPopover = () => {
const [open, setOpen] = useState(false);
return (
<Popover.Root open={open} onOpenChange={setOpen}>
<Popover.Trigger render={<Button>Show details</Button>} />
<Popover.Portal>
<Popover.Positioner align="start">
<Popover.Popup
style={{
boxSizing: 'border-box',
width: 260,
padding: 16,
gap: 12,
}}
>
<Popover.Title>Contact details</Popover.Title>
<Popover.Description>
Reach Alex at [email protected].
</Popover.Description>
<Popover.Close
style={{ alignSelf: 'flex-end' }}
render={<Button size="sm">Close</Button>}
/>
</Popover.Popup>
</Popover.Positioner>
</Popover.Portal>
</Popover.Root>
);
};
```
`onOpenChange` receives the next boolean and event details, including changes requested by the trigger, close controls, Escape, and outside interaction.
## Compose with buttons
Pass a Twenty UI `Button` through `render` to use it as the trigger or close control. The popover keeps its open state, keyboard behavior, and focus handling.
```tsx
import { Button } from 'twenty-ui/primitives/input';
import { Popover } from 'twenty-ui/primitives/surfaces';
export const ImportHelp = () => (
<Popover.Root>
<Popover.Trigger render={<Button variant="outline">Import help</Button>} />
<Popover.Portal>
<Popover.Positioner align="start">
<Popover.Popup
style={{ boxSizing: 'border-box', width: 260, padding: 16, gap: 12 }}
>
<Popover.Arrow />
<Popover.Title>Import a CSV file</Popover.Title>
<Popover.Description>
Use a header row to identify your columns.
</Popover.Description>
<Popover.Close
style={{ alignSelf: 'flex-end' }}
render={<Button size="sm">Got it</Button>}
/>
</Popover.Popup>
</Popover.Positioner>
</Popover.Portal>
</Popover.Root>
);
```
`render` composes behavior onto the supplied button. Custom wrapper components must [forward the supplied props and ref](/ui/primitives/overview#custom-components) to preserve that behavior.
## Placement and focus
`Positioner` defaults to `side="bottom"`, `align="center"` and `sideOffset={8}`. It accepts the full installed Base UI contract, including element/ref/function/virtual anchors, functional offsets, `positionMethod`, `collisionBoundary`, `collisionPadding`, `collisionAvoidance`, `arrowPadding`, `sticky` and `disableAnchorTracking`. DirectionProvider controls logical positioning and supplies the DOM direction. An explicit `dir` can override the native attribute; use the provider to change logical side placement.
```tsx
import { useRef } from 'react';
import { Popover } from 'twenty-ui/primitives/surfaces';
export const AnchoredHelp = () => {
const anchor = useRef<HTMLDivElement>(null);
return (
<div ref={anchor}>
<Popover.Root>
<Popover.Trigger>Help</Popover.Trigger>
<Popover.Portal>
<Popover.Positioner
anchor={anchor}
side="inline-end"
align="start"
sideOffset={({ anchor }) => anchor.width / 2}
collisionBoundary="clipping-ancestors"
collisionAvoidance={{ side: 'flip', align: 'shift' }}
collisionPadding={8}
positionMethod="fixed"
>
<Popover.Popup aria-label="Help">
<Popover.Arrow />
Contextual help
</Popover.Popup>
</Popover.Positioner>
</Popover.Portal>
</Popover.Root>
</div>
);
};
```
Escape closes the popup and restores focus to its trigger. Outside interaction dismisses it by default. `Popup.initialFocus` and `Popup.finalFocus` accept the upstream focus targets and callbacks. `Root.modal` retains Base UI's nonmodal default, modal and trap-focus modes for standalone usage.
## Portal destinations and theme
Set `container` and `keepMounted` on `Portal`:
| Container | Resolution |
| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Omitted or `undefined` | Uses the nearest scoped ThemeProvider container. Without one, Base UI uses its parent portal or document body. |
| `null` | Waits without rendering portal content until the container changes. It does not fall back to the theme or body. |
| Element, ShadowRoot or ref | Passes the supplied target unchanged to Base UI. An unresolved ref retains Base UI's parent-portal/body fallback; use explicit null when waiting is required. |
The default scoped destination preserves its CSS tokens and color scheme. An explicit destination inherits CSS from its actual DOM scope. Put it inside the intended theme scope, or supply the theme styles there. ShadowRoot targets need the library's CSS and theme styles in that shadow tree. React theme context and provided text direction remain available across portals. This API does not expand the renderer's permitted portal destinations.
## Detached triggers and payloads
`Popover.createHandle<TPayload>()` connects detached triggers to a root and exposes `open(triggerId)`, `close()` and `isOpen`. `Popover.Handle` is the installed upstream handle constructor. Root's render function receives the active payload. Call imperative actions from event handlers or effects.
```tsx
import { useState } from 'react';
import { Popover } from 'twenty-ui/primitives/surfaces';
export const OwnerHelp = () => {
const [handle] = useState(() => Popover.createHandle<{ name: string }>());
return (
<>
<Popover.Trigger handle={handle} id="owner" payload={{ name: 'Alice' }}>
Owner
</Popover.Trigger>
<Popover.Root handle={handle}>
{({ payload }) => (
<Popover.Portal>
<Popover.Positioner align="start">
<Popover.Popup aria-label="Account owner">
{payload?.name}
<Popover.Close>Close</Popover.Close>
</Popover.Popup>
</Popover.Positioner>
</Popover.Portal>
)}
</Popover.Root>
</>
);
};
```
`onOpenChange` preserves `reason`, `event`, `trigger`, `cancel()` and `preventUnmountOnClose()`. Controlled roots retain `triggerId`; uncontrolled roots retain `defaultTriggerId`. `actionsRef` exposes the upstream close/unmount actions.
## Migration
Move `container` and `keepMounted` from Popup to Portal. Move placement, anchor and collision props to Positioner. Replace `Popup.arrow` with an explicit `Popover.Arrow` child. Popup's native props, handlers, focus props and ref continue to target the content element. Dropdown.Content keeps its existing convenient assembly.
Inside front components, use nonmodal composition within the existing scoped portal policy. Native browser popovers/dialogs and direct app-owned modality are prohibited; use the SDK host dialog API for dialogs. Renderer portal, geometry, scrolling and dismissal capability work remains separate from this primitive API.
## Props
The reference is generated from the public component types. Native attributes, including accessible names and event handlers, are also accepted on parts that render elements.
<PopoverReference />
<PageBanner illustration="card-page-messaging-channels" />