Installation
Add Component
Copy the code snippet below into you components folder.
Integrate Recipe
Integrate this recipe in to your Panda config.
Usage
Shortcuts
The Popover provides a shortcuts for common use cases.
Arrow
The Popover.Arrow renders the Popover.ArrowTip component within in by
default.
This works:
This might be more concise, if you don't need to customize the arrow tip.
Examples
Controlled
Use the open and onOpenChange to control the visibility of the popover.
Lazy Mount
Use the lazyMounted and/or unmountOnExit prop to defer the mounting of the popover content until it's opened.
Placement
Use the positioning.placement prop to change the position of the popover.
Offset
Use the positioning.offset prop to adjust the position of the popover content.
Same Width
Use the positioning.sameWidth prop to make the popover content the same width
as the trigger.
Nested
To use the Popover within a Popover, you need to avoid portalling the nested Popover.Positioner to the document's body.
Form
Here's an example of a popover with a form inside.
Initial Focus
Use the initialFocusEl prop to set the initial focus of the popover content.
Custom Background
Use the --popover-bg CSS variable to change the background color of the
popover content and its arrow.
Within Dialog
To use the Popover within a Dialog, you need to avoid portalling the Popover.Positioner to the document's body.
If you have set scrollBehavior="inside" on the Dialog, you need to:
- Set the popover positioning to fixedto avoid the popover from being clipped by the dialog.
- Set hideWhenDetachedtotrueto hide the popover when the trigger is scrolled out of view.
Props
Root
| Prop | Default | Type | 
|---|---|---|
| autoFocus | true | booleanWhether to automatically set focus on the first focusable content within the popover when opened. | 
| closeOnEscape | true | booleanWhether to close the popover when the escape key is pressed. | 
| closeOnInteractOutside | true | booleanWhether to close the popover when the user clicks outside of the popover. | 
| lazyMount | false | booleanWhether to enable lazy mounting | 
| modal | false | booleanWhether the popover should be modal. When set to `true`: - interaction with outside elements will be disabled - only popover content will be visible to screen readers - scrolling is blocked - focus is trapped within the popover | 
| portalled | true | booleanWhether the popover is portalled. This will proxy the tabbing behavior regardless of the DOM position of the popover content. | 
| skipAnimationOnMount | false | booleanWhether to allow the initial presence animation. | 
| unmountOnExit | false | booleanWhether to unmount on exit. | 
| defaultOpen | booleanThe initial open state of the popover when rendered. Use when you don't need to control the open state of the popover. | |
| id | stringThe unique identifier of the machine. | |
| ids | Partial<{
  anchor: string
  trigger: string
  content: string
  title: string
  description: string
  closeTrigger: string
  positioner: string
  arrow: string
}>The ids of the elements in the popover. Useful for composition. | |
| immediate | booleanWhether to synchronize the present change immediately or defer it to the next frame | |
| initialFocusEl | () => HTMLElement | nullThe element to focus on when the popover is opened. | |
| onEscapeKeyDown | (event: KeyboardEvent) => voidFunction called when the escape key is pressed | |
| onExitComplete | VoidFunctionFunction called when the animation ends in the closed state | |
| onFocusOutside | (event: FocusOutsideEvent) => voidFunction called when the focus is moved outside the component | |
| onInteractOutside | (event: InteractOutsideEvent) => voidFunction called when an interaction happens outside the component | |
| onOpenChange | (details: OpenChangeDetails) => voidFunction invoked when the popover opens or closes | |
| onPointerDownOutside | (event: PointerDownOutsideEvent) => voidFunction called when the pointer is pressed down outside the component | |
| onRequestDismiss | (event: LayerDismissEvent) => voidFunction called when this layer is closed due to a parent layer being closed | |
| open | booleanThe controlled open state of the popover | |
| persistentElements | (() => Element | null)[]Returns the persistent elements that: - should not have pointer-events disabled - should not trigger the dismiss event | |
| positioning | PositioningOptionsThe user provided options used to position the popover content | |
| present | booleanWhether the node is present (controlled by the user) |