Popover
Floating panel anchored to a trigger, for small forms and details.
Example
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 { PopoverContent } from "@porcelana/ui";
import "@porcelana/ui/styles.css"; // once, at your app rootProps
Generated from the TypeScript types. Standard HTML attributes are passed through and not listed.
PopoverContent
| Prop | Type | Default | Description |
|---|---|---|---|
align | "center" | "start" | "end" | – | Alignment against the trigger. |
alignOffset | number | – | Offset from the alignment edge in px. |
aria-label | string | – | Defines a string value that labels the current element. @see aria-labelledby. |
arrowPadding | number | – | Padding between the arrow and the content edges in px. |
asChild | boolean | – | Render the single child element instead, merging props and behaviour onto it. |
avoidCollisions | boolean | – | Flip or shift to stay on screen. |
collisionBoundary | Boundary | Boundary[] | – | Element(s) used as the collision boundary instead of the viewport. |
collisionPadding | number | Partial<Record<"top" | "right" | "bottom" | "left", number>> | 8 | Space to keep from the viewport edges in px. |
deferPointerDownOutside | boolean | – | 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. |
forceMount | true | – | Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries. |
hideWhenDetached | boolean | – | Hide when the trigger scrolls out of view. |
id | string | – | 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. |
sideOffset | number | 8 | Distance from the trigger in px. |
sticky | Sticky | – | Keep the content attached while scrolling. |
updatePositionStrategy | UpdatePositionStrategy | – | "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.