<!-- index: /slotted/llms.txt -->
# popover

`data-ui="popover"` · Floating panel anchored to a trigger.

## Import

```tsx
import {
  Popover,
  PopoverAnchor,
  PopoverArrow,
  PopoverBody,
  PopoverClose,
  PopoverContent,
  PopoverDefaultsProvider,
  PopoverDescription,
  PopoverFooter,
  PopoverHeader,
  PopoverLayer,
  PopoverTitle,
  PopoverTrigger,
} from '@slotted/react';
```

## Minimal example

Example

```tsx
import { Button } from '@slotted/react/button';
import {
  DescriptionList,
  DescriptionListDescription,
  DescriptionListItem,
  DescriptionListTerm,
} from '@slotted/react/description-list';
import {
  Popover,
  PopoverArrow,
  PopoverBody,
  PopoverClose,
  PopoverContent,
  PopoverDescription,
  PopoverHeader,
  PopoverLayer,
  PopoverTitle,
  PopoverTrigger,
} from '@slotted/react/popover';

const stock = [
  { term: 'On hand', value: '39 units' },
  { term: 'Reserved', value: '12 units' },
  { term: 'Reorder point', value: '25 units' },
  { term: 'Next delivery', value: 'Oct 14, Exotic Liquids' },
];

export default function PopoverBasic() {
  return (
    <Popover>
      <PopoverTrigger
        render={(props) => (
          <Button {...props} tone="secondary" variant="outline">
            Chai stock
          </Button>
        )}
      />
      <PopoverLayer>
        <PopoverContent>
          <PopoverHeader>
            <PopoverTitle>Chai</PopoverTitle>
            <PopoverDescription>SKU NW-1001, Seattle warehouse</PopoverDescription>
            <PopoverClose />
          </PopoverHeader>
          <PopoverBody>
            <DescriptionList>
              {stock.map((row) => (
                <DescriptionListItem key={row.term}>
                  <DescriptionListTerm>{row.term}</DescriptionListTerm>
                  <DescriptionListDescription>{row.value}</DescriptionListDescription>
                </DescriptionListItem>
              ))}
            </DescriptionList>
          </PopoverBody>
        </PopoverContent>
        <PopoverArrow />
      </PopoverLayer>
    </Popover>
  );
}
```

## Anatomy

| Part | Element | Required |
| --- | --- | --- |
| `root` | div, rendered by PopoverLayer | yes |
| `content` | div | yes |
| `header` | div | no |
| `title` | div, or the element render returns | no |
| `description` | p | no |
| `body` | div | no |
| `footer` | div | no |
| `close` | button | no |
| `arrow` | div | no |
| `backdrop` | div | no |
| `grip` | span | no |
| `focus-guard` | span (two of them) | yes |

## Props

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `open` | `boolean` | — | Popover | Whether the panel is open. Passing it makes the popover controlled for the life of the component; update it from onOpenChange. |
| `defaultOpen` | `boolean` | false | Popover | The open state an uncontrolled popover starts with. It is read once. |
| `size` | `'sm' \| 'md' \| 'lg'` | md | Popover | The maximum width of the layer, which holds the panel and the gap around it: 16rem, 20rem or 24rem, with the inset and the title size to match. |
| `width` | `'auto' \| 'anchor'` | auto | Popover | auto sizes the panel to its content, up to the width size sets. anchor makes it exactly as wide as the anchor. |
| `side` | `'top' \| 'bottom' \| 'inline-start' \| 'inline-end' \| 'left' \| 'right'` | bottom | Popover | The edge of the anchor the panel opens against. inline-start and inline-end follow the writing direction of the layer. |
| `align` | `'start' \| 'center' \| 'end'` | center | Popover | Where the panel sits along the side it opened on. |
| `mount` | `'active' \| 'lazy' \| 'eager'` | active | Popover | When the layer exists. active builds it on open and removes it after the exit animation. lazy builds it on the first open and keeps it, for a panel whose content is expensive to build. eager builds it from the start. |
| `strategy` | `'absolute' \| 'fixed'` | absolute | Popover | The CSS position of the layer. Use fixed for a layer inside an overflow: hidden container, and absolute for one inside a transformed container. |
| `arrow` | `boolean` | true | Popover | Whether PopoverArrow is drawn. |
| `autoFocus` | `boolean` | true | Popover | Whether focus moves into the popover on open. Focus goes to the panel itself rather than to its first control, so a screen reader announces the panel’s name first and a destructive first control is not focused by default. |
| `closeOnEscape` | `boolean` | true | Popover | Whether Escape closes the popover. Escape reaches only the topmost layer. |
| `closeOnOutsidePress` | `boolean \| (target, event) => boolean` | true | Popover | Whether a press outside the panel closes the popover. A function decides per press, for a panel that has to stay open when the reader presses a toast beside it. |
| `flip` | `boolean` | true | Popover | Whether the panel moves to the opposite side when it does not fit. |
| `shift` | `boolean` | true | Popover | Whether the panel slides along its side to stay inside the boundary. |
| `hideWhenDetached` | `boolean` | false | Popover | Whether the panel hides when its anchor scrolls out of view. It is off, unlike Tooltip’s, so a task the reader is halfway through does not disappear when the row behind it scrolls. |
| `portal` | `boolean` | true | Popover | Whether the layer is rendered into the shared portal root at the end of the document. The portalled layer keeps the theme, color scheme, density and direction of the region it was opened from. |
| `presentation` | `'popover' \| 'auto'` | popover | Popover | auto presents the panel as a bottom sheet under (max-width: 480px) and (pointer: coarse): modal, with a scrim, a grip and focus held in it, headed by PopoverTitle or by the panel’s aria-label. It reads the drawer’s surface, radius, scrim and motion tokens. |
| `disabled` | `boolean` | false | Popover | Whether the popover never opens. It does not disable the trigger; set disabled on the trigger element for that. |
| `messages` | `Partial<PopoverMessages>` | — | Popover | Text that replaces the language’s messages for this popover, key by key. close is the close button’s accessible name; an aria-label on PopoverClose takes precedence. |
| `sideOffset` | `number` | 0 | Popover | Extra distance from the anchor in pixels, added to the standard gap. |
| `alignOffset` | `number` | 0 | Popover | Distance in pixels along the alignment axis. |
| `collisionPadding` | `number` | 8 | Popover | The minimum distance in pixels between the panel and the edge of the boundary. |
| `arrowPadding` | `number` | 12 | Popover | The minimum distance in pixels between the arrow and the panel’s corners, so the arrow stays off the rounded corner. |
| `initialFocus` | `Element \| RefObject \| string` | — | Popover | What takes focus on open instead of the panel, such as a search field. A string is a selector read inside the panel. |
| `finalFocus` | `Element \| RefObject \| string` | — | Popover | What takes focus on close instead of the trigger, for a popover whose trigger is gone by then, such as one that deleted its own row. |
| `render` | `(props) => ReactNode` | — | every part | Renders the part as the element it returns, with the props it receives spread on it. The trigger uses it to render a Button, and the title uses it to render a heading. |
| `ref` | `Ref<PopoverHandle>` | — | Popover | A handle with open(), close() and reposition(), for code that has to open, close or re-measure the popover outside a render. |
| `PopoverAnchor` | `component` | — | composition | The element the panel is positioned against, when it is not the trigger, such as a table row. It writes no attributes. A press on it counts as a press inside the popover. |
| `PopoverDefaultsProvider` | `component` | — | application | Sets any option for every popover inside it. An option set on a popover takes precedence. |
| `container` | `Element \| null` | document.body | PopoverDefaultsProvider | Where every layer inside the provider is rendered, for an application shell with its own stacking context. It calls setPortalContainer. |
| `native props` | `ComponentPropsWithRef` | — | every part | Each part takes the props of its element. An onClick on the trigger runs before the popover’s own handler, and event.preventDefault() stops the popover’s handler. |

## Events

| Name | Payload | When |
| --- | --- | --- |
| `onOpenChange` | `(open: boolean, request: PopoverChangeRequest)` | Before the panel opens or closes, once per change. request.reason is pointer, keyboard, escape, outsidePress, dismiss or programmatic. request.cancel() refuses the change: an uncontrolled popover stays as it is. |

## Axes and defaults

| Axis | Values | Default |
| --- | --- | --- |
| `size` | `sm`, `md`, `lg` | `md` |
| `width` | `auto`, `anchor` | `auto` |
| `side` | `top`, `bottom`, `inline-start`, `inline-end`, `left`, `right` | `bottom` |
| `align` | `start`, `center`, `end` | `center` |
| `mount` | `active`, `lazy`, `eager` | `active` |
| `strategy` | `absolute`, `fixed` | `absolute` |
| `arrow` | `true`, `false` | `true` |
| `autoFocus` | `true`, `false` | `true` |
| `closeOnEscape` | `true`, `false` | `true` |
| `closeOnOutsidePress` | `true`, `false` | `true` |
| `flip` | `true`, `false` | `true` |
| `shift` | `true`, `false` | `true` |
| `hideWhenDetached` | `true`, `false` | `false` |
| `portal` | `true`, `false` | `true` |
| `disabled` | `true`, `false` | `false` |

## Rules

- The panel is a non-modal dialog: aria-modal is not written, nothing behind it becomes inert, and the page keeps scrolling. The sheet of presentation="auto" is the exception: it covers a phone’s screen, so it is modal, holds focus and returns it to the trigger. Use Dialog for content that has to block the page.
- The trigger carries aria-expanded, aria-haspopup="dialog", and aria-controls while the panel is in the document. The panel is named by its title through aria-labelledby and described by its description through aria-describedby. A popover without a title has no accessible name until you write aria-label on PopoverContent.
- Focus moves to the panel on open, so a screen reader announces its name before its contents, and returns to the trigger on close. If the reader has moved focus elsewhere on the page, focus stays there. initialFocus and finalFocus name other targets.
- Tab past the last control in the panel, or Shift+Tab before the first, closes the popover and returns focus to the trigger; the next Tab continues down the page. Focus is never trapped in the panel.

## Tokens

`--slotted-border-strong`, `--slotted-border-subtle`, `--slotted-border-width-thin`, `--slotted-control-gap-md`, `--slotted-control-height-sm`, `--slotted-control-radius`, `--slotted-control-transition-duration`, `--slotted-control-transition-easing`, `--slotted-drawer-border-color`, `--slotted-drawer-radius`, `--slotted-drawer-resizer-line-color`, `--slotted-drawer-scrim`, `--slotted-drawer-scrim-backdrop-filter`, `--slotted-drawer-slide-duration`, `--slotted-drawer-slide-easing`, `--slotted-drawer-slide-exit-duration`, `--slotted-drawer-slide-exit-easing`, `--slotted-drawer-surface`, `--slotted-duration-long`, `--slotted-duration-medium`, `--slotted-duration-short`, `--slotted-easing-enter`, `--slotted-easing-exit`, `--slotted-easing-standard`, `--slotted-focus-ring-color`, `--slotted-focus-ring-offset`, `--slotted-focus-ring-width`, `--slotted-font-family-heading`, `--slotted-font-family-sans`, `--slotted-font-size-lg`, `--slotted-font-size-md`, `--slotted-font-size-sm`, `--slotted-font-size-xl`, `--slotted-font-weight-semibold`, `--slotted-line-height-lg`, `--slotted-line-height-md`, `--slotted-line-height-sm`, `--slotted-overlay-max-block-size`, `--slotted-popover-arrow-size`, `--slotted-popover-arrow-tip-radius`, `--slotted-popover-backdrop-filter`, `--slotted-popover-border-color`, `--slotted-popover-gap`, `--slotted-popover-measure`, `--slotted-popover-measure-lg`, `--slotted-popover-measure-sm`, `--slotted-popover-padding-block`, `--slotted-popover-padding-block-lg`, `--slotted-popover-padding-block-sm`, `--slotted-popover-padding-inline`, `--slotted-popover-padding-inline-lg`, `--slotted-popover-padding-inline-sm`, `--slotted-popover-radius`, `--slotted-popover-shadow`, `--slotted-popover-surface`, `--slotted-popover-text`, `--slotted-radius-lg`, `--slotted-radius-sm`, `--slotted-radius-xs`, `--slotted-scrim`, `--slotted-shadow-lg`, `--slotted-shadow-md`, `--slotted-space-11`, `--slotted-space-2`, `--slotted-space-3`, `--slotted-space-4`, `--slotted-space-5`, `--slotted-space-6`, `--slotted-space-7`, `--slotted-surface-raised`, `--slotted-target-min`, `--slotted-text`, `--slotted-text-muted`, `--slotted-tone-secondary-subtle-active`, `--slotted-tone-secondary-subtle-hover`, `--slotted-z-index-popover`

## Examples

See [popover.examples.md](./popover.examples.md).
