Popover
Popover is a non-modal dialog that floats around its disclosure. It's commonly used for displaying additional rich content on top of something.
Installation
The above command is for individual installation only. You may skip this step if @nextui-org/react
is already installed globally.
Import
NextUI exports 3 popover-related components:
- Popover: The main component to display a popover.
- PopoverTrigger: The component that triggers the popover.
- PopoverContent: The component that contains the popover content.
Usage
With Arrow
Colors
Placements
Offset
Controlled
Title Props
To be sure that the popover exposes the correct title to assistive technologies, you should use the
titleProps
prop on the PopoverContent
component. To use this prop, you must pass a function as a child.
With Form
The Popover
handles the focus within the popover content. It means that you can use the popover with
form elements without any problem. the focus returns to the trigger when the popover closes.
Note: You can add the
autoFocus
prop to the firstInput
component to focus it when the popover opens.
Backdrop
The Popover
component has a backdrop
prop to show a backdrop behind the popover. The backdrop can be
either transparent
, opaque
or blur
. The default value is transparent
.
Custom Motion
Popover offers a motionProps
property to customize the enter
/ exit
animation.
Learn more about Framer motion variants here.
Custom Trigger
Slots
- base: The main popover slot, it wraps the popover content and contains the arrow as a pseudo-element (::before).
- trigger: The popover trigger slot, it has small styles to ensure the trigger works correctly.
- backdrop: The backdrop slot, it contains the backdrop styles.
- content: The content slot, it contains the popover content.
Custom Styles
You can customize the Popover
component by passing custom Tailwind CSS classes to the component slots.
Data Attributes
Popover
has the following attributes on the PopoverContent
element:
- data-open: When the popover is open. Based on popover state.
- data-placement:
The placement of the popover. Based on
placement
prop. The arrow element is positioned based on this attribute. - data-focus: When the popover is being focused. Based on useFocusRing.
- data-focus-visible: When the popover is being focused with the keyboard. Based on useFocusRing.
Accessibility
- The trigger and popover are automatically associated semantically via ARIA.
- Content outside the popover is hidden from assistive technologies while it is open.
- The popover closes when interacting outside, or pressing the Escape key.
- Focus is moved into the popover on mount, and restored to the trigger element on unmount.
- The popover is positioned relative to the trigger element, and automatically flips and adjusts to avoid overlapping with the edge of the browser window.
- Scrolling is prevented outside the popover to avoid unintentionally repositioning or closing it.
API
Popover Props
Prop | Type | Default |
children* |
| |
size |
| "md" |
color |
| "default" |
radius |
| "lg" |
shadow |
| "lg" |
backdrop |
| "transparent" |
placement |
| "bottom" |
state |
| |
isOpen |
| |
defaultOpen |
| |
offset |
| "7" |
containerPadding |
| "12" |
crossOffset |
| "0" |
triggerType |
| "dialog" |
showArrow |
| false |
shouldFlip |
| true |
triggerScaleOnOpen |
| true |
shouldBlockScroll |
| true |
shouldCloseOnScroll |
| false |
isKeyboardDismissDisabled |
| false |
shouldCloseOnBlur |
| false |
motionProps |
| |
portalContainer |
| "document.body" |
disableAnimation |
| false |
classNames |
|
Popover Events
Prop | Type | Default |
onOpenChange |
| |
shouldCloseOnInteractOutside |
| |
onClose |
|
PopoverTrigger Props
Prop | Type | Default |
children* |
|
PopoverContent Props
Prop | Type | Default |
children |
|