Overlay anchored to a trigger
import {Popover} from "@peakui/react" ;
import {Button, Popover} from "@peakui/react" ;
export default () => (
< Popover >
< Button >Open popover</ Button >
< Popover.Content >
< Popover.Dialog >
< Popover.Arrow />
< Popover.Heading >Popover heading</ Popover.Heading >
< p >Popover content</ p >
</ Popover.Dialog >
</ Popover.Content >
</ Popover >
);
@layer components {
.popover {
@apply rounded-lg border border-border/80 shadow-lg;
}
.popover__heading {
@apply text-xs uppercase tracking-wide;
}
}
PeakUI follows the BEM methodology, so variants and states are plain class names you can target.
The Popover component uses these CSS classes (view source styles ):
.popover - Base popover styles with animations
.popover__dialog - Dialog element styles
.popover__heading - Heading element styles
.popover__trigger - Trigger element styles
[data-slot="popover"] - The popover content element
[data-slot="popover-trigger"] - The Popover.Trigger element
[data-slot="popover-dialog"] - The Popover.Dialog element
[data-slot="popover-heading"] - The Popover.Heading element
[data-slot="popover-overlay-arrow"] - The default arrow SVG
[data-slot="popover-overlay-arrow-group"] - The arrow wrapper
The popover content carries RAC animation and positioning states:
Entering : [data-entering="true"]
Exiting : [data-exiting="true"]
Placement : [data-placement="top | bottom | left | right"]
The trigger supports both pseudo-classes and data attributes:
Focus : :focus-visible or [data-focus-visible="true"]
Disabled : :disabled or [aria-disabled="true"]
Prop Type Default Description childrenReact.ReactNode- The trigger element followed by Popover.Content isOpenboolean- Controlled open state defaultOpenbooleanfalseInitially open, without controlling onOpenChange(isOpen: boolean) => void- Called when the popover opens or closes ...restDialogTriggerProps- React Aria DialogTrigger attributes
Prop Type Default Description childrenReact.ReactNode- Content of the popover placementPlacement'bottom'Placement relative to the trigger: 'top', 'bottom', 'left', 'right' with start/end/top/bottom variants offsetnumber8Distance from the trigger element crossOffsetnumber0Cross-axis offset from the trigger shouldFlipbooleantrueWhether the popover flips when it does not fit containerPaddingnumber12Distance the popover keeps from the viewport edge arrowBoundaryOffsetnumber0Boundary offset for the arrow positioning classNamestring | ((renderProps) => string)- Additional classes, or a function of the popover state renderDOMRenderFunction<'div', PopoverRenderProps>- Replaces the rendered <div> with your own element ...restPopoverProps- React Aria Popover attributes
Prop Type Default Description childrenReact.ReactNode | (({close}) => React.ReactNode)- Dialog content; a function receives a close callback aria-labelstring- Accessible name when no Popover.Heading is present classNamestring- Additional classes ...restDialogProps- React Aria Dialog attributes
Prop Type Default Description childrenReact.ReactNode- Non-interactive element to make pressable classNamestring- Additional classes renderDOMRenderFunction<E, undefined>- Replaces the rendered <div> with your own element; E defaults to 'div' ...restHTMLAttributes- The attributes of the rendered element
Prop Type Default Description childrenReact.ReactNode- Custom arrow element; defaults to a 12x12 SVG classNamestring- Additional classes ...restOverlayArrowProps- React Aria OverlayArrow attributes
Prop Type Default Description childrenReact.ReactNode- Heading text; labels the dialog via aria-labelledby classNamestring- Additional classes ...restHeadingProps- React Aria Heading attributes
Prop Type Description Popover.Content className(renderProps: PopoverRenderProps) => stringComputes classes from placement, isEntering, isExiting, trigger and state Popover.Dialog children(opts: {close: () => void}) => React.ReactNodeRenders content with a callback that closes the popover