Skip to content
Porcelana

Popover

Floating panel anchored to a trigger, for small forms and details.

Example

Example.tsx
import { Button, Field, Input, Popover, PopoverContent, PopoverTrigger } from "@porcelana/ui";

export default function Example() {
  return (
    <Popover>
      <PopoverTrigger asChild>
        <Button variant="soft">Rename</Button>
      </PopoverTrigger>
      <PopoverContent aria-label="Rename alarm">
        <Field label="Alarm label">
          <Input defaultValue="Gym" />
        </Field>
      </PopoverContent>
    </Popover>
  );
}

Import

Import
import { PopoverContent } from "@porcelana/ui";
import "@porcelana/ui/styles.css"; // once, at your app root

Props

Generated from the TypeScript types. Standard HTML attributes are passed through and not listed.

PopoverContent

PropTypeDefaultDescription
align"center" | "start" | "end"–Alignment against the trigger.
alignOffsetnumber–Offset from the alignment edge in px.
aria-labelstring–Defines a string value that labels the current element. @see aria-labelledby.
arrowPaddingnumber–Padding between the arrow and the content edges in px.
asChildboolean–Render the single child element instead, merging props and behaviour onto it.
avoidCollisionsboolean–Flip or shift to stay on screen.
collisionBoundaryBoundary | Boundary[]–Element(s) used as the collision boundary instead of the viewport.
collisionPaddingnumber | Partial<Record<"top" | "right" | "bottom" | "left", number>>8Space to keep from the viewport edges in px.
deferPointerDownOutsideboolean–When `true`, a `'pointerdown'` event outside of the layered element will wait for the interaction's click event before dispatching, allowing third-party code to stop propagation of later events and cancel dismissal.
forceMounttrue–Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries.
hideWhenDetachedboolean–Hide when the trigger scrolls out of view.
idstring–Element id. Generated automatically when omitted.
onCloseAutoFocus((event: Event) => void)–Event handler called when auto-focusing on close. Can be prevented.
onEscapeKeyDown((event: KeyboardEvent) => void)–Event handler called when the escape key is down. Can be prevented.
onFocusOutside((event: FocusOutsideEvent) => void)–Event handler called when the focus moves outside of the `DismissableLayer`. Can be prevented.
onInteractOutside((event: PointerDownOutsideEvent | FocusOutsideEvent) => void)–Event handler called when an interaction happens outside the `DismissableLayer`. Specifically, when a `pointerdown` event happens outside or focus moves outside of it. Can be prevented.
onOpenAutoFocus((event: Event) => void)–Event handler called when auto-focusing on open. Can be prevented.
onPointerDownOutside((event: PointerDownOutsideEvent) => void)–Event handler called when the a `pointerdown` event happens outside of the `DismissableLayer`. Can be prevented.
side"top" | "right" | "bottom" | "left"–Preferred side of the trigger to render on.
sideOffsetnumber8Distance from the trigger in px.
stickySticky–Keep the content attached while scrolling.
updatePositionStrategyUpdatePositionStrategy–"optimized" or "always" recompute the position on every frame.

Accessibility

  • The trigger exposes aria-expanded; Escape closes and focus returns.
  • Give the content an aria-label when it has no heading.

Mobile

  • Stays inside the screen with 8px of padding and flips sides when there's no room.