A popover is an overlay element positioned relative to a trigger.
Vanilla CSS theme
--tint CSS variable used by the Vanilla CSS examples.Custom trigger
DialogTrigger works with any pressable React Aria component (e.g. Button, Link, etc.). Use the <Pressable> component or usePress hook to wrap a custom trigger element such as a third party component or DOM element.
import {Pressable, DialogTrigger} from 'react-aria-components';
import {Popover} from './Popover';
<DialogTrigger>
<Pressable>
<span role="button">Custom trigger</span>
</Pressable>
<Popover style={{padding: 16}}>
This popover was triggered by a custom button.
</Popover>
</DialogTrigger>
Accessibility
<Pressable> child must have an interactive ARIA role or use an appropriate semantic HTML element so that screen readers can announce the trigger. Trigger components must forward their ref and spread all props to a DOM element.const CustomTrigger = React.forwardRef((props, ref) => (
<button {...props} ref={ref} />
));
Custom anchor
To position a popover relative to a different element than its trigger, use the triggerRef and isOpen props instead of <DialogTrigger>. onOpenChange will be called when the user closes the popover.
import {useState, useRef} from 'react';
import {Popover} from './Popover';
import {Button} from './Button';
function Example() {
let [isOpen, setOpen] = useState(false);
let triggerRef = useRef(null);
return (
<div>
<Button onPress={() => setOpen(true)}>Trigger</Button>
<span ref={triggerRef} style={{paddingLeft: 12}}>Popover will be positioned relative to me</span>
<Popover
style={{padding: 16}}
triggerRef={triggerRef}
isOpen={isOpen}
onOpenChange={setOpen}>
I'm over here!
</Popover>
</div>
);
}
Examples
API
<DialogTrigger>
<Button />
<Popover>
<OverlayArrow />
</Popover>
</DialogTrigger>
DialogTrigger
A DialogTrigger opens a dialog when a trigger element is pressed.
| Name | Type | |
|---|---|---|
children | ReactNode | |
Popover
A popover is an overlay element positioned relative to a trigger.
| Name | Type | Default |
|---|---|---|
trigger | string | Default: — |
The name of the component that triggered the popover. This is reflected on the element
as the data-trigger attribute, and can be used to provide specific
styles for the popover depending on which element triggered it. | ||
triggerRef | RefObject | Default: — |
| The ref for the element which the popover positions itself with respect to. When used within a trigger component such as DialogTrigger, MenuTrigger, Select, etc., this is set automatically. It is only required when used standalone. | ||
isEntering | boolean | Default: — |
| Whether the popover is currently performing an entry animation. | ||
isExiting | boolean | Default: — |
| Whether the popover is currently performing an exit animation. | ||
placement | Placement | Default: 'bottom'
|
| The placement of the element with respect to its anchor element. | ||
arrowRef | RefObject | Default: — |
| A ref for the popover arrow element. | ||
isNonModal | boolean | Default: — |
| Whether the popover is non-modal, i.e. elements outside the popover may be interacted with by assistive technologies. Most popovers should not use this option as it may negatively impact the screen reader experience. Only use with components such as combobox, which are designed to handle this situation carefully. | ||
isKeyboardDismissDisabled | boolean | Default: false
|
| Whether pressing the escape key to close the popover should be disabled. Most popovers should not use this option. When set to true, an alternative way to close the popover with a keyboard must be provided. | ||
shouldCloseOnInteractOutside | | Default: — |
| When user interacts with the argument element outside of the popover ref, return true if onClose should be called. This gives you a chance to filter out interaction with elements that should not dismiss the popover. By default, onClose will always be called on interaction outside the popover ref. | ||
boundaryElement | Element | Default: document.body
|
| Element that that serves as the positioning boundary. | ||
scrollRef | RefObject | Default: overlayRef
|
| A ref for the scrollable region within the overlay. | ||
shouldUpdatePosition | boolean | Default: true
|
| Whether the overlay should update its position automatically. | ||
maxHeight | number | Default: — |
| The maxHeight specified for the overlay element. By default, it will take all space up to the current viewport height. | ||
arrowBoundaryOffset | number | Default: 0
|
| The minimum distance the arrow's edge should be from the edge of the overlay element. | ||
children | ChildrenOrFunction | Default: — |
| The children of the component. A function may be provided to alter the children based on component state. | ||
Default className: react-aria-Popover
| Render Prop | CSS Selector |
|---|---|
trigger | CSS Selector: [data-trigger="..."]
|
| The name of the component that triggered the popover, e.g. "DialogTrigger" or "ComboBox". | |
placement | CSS Selector: [data-placement="left | right | top | bottom"]
|
| The placement of the popover relative to the trigger. | |
isEntering | CSS Selector: [data-entering]
|
| Whether the popover is currently entering. Use this to apply animations. | |
isExiting | CSS Selector: [data-exiting]
|
| Whether the popover is currently exiting. Use this to apply animations. | |
| CSS Variable |
|---|
--trigger-width |
| The width of the popover trigger element. |
--trigger-anchor-point |
The position of the trigger relative to the popover. Use with transform-origin when applying scale transitions. |
OverlayArrow
An OverlayArrow renders a custom arrow element relative to an overlay element such as a popover or tooltip such that it aligns with a trigger element.
| Name | Type | |
|---|---|---|
children | ChildrenOrFunction | |
| The children of the component. A function may be provided to alter the children based on component state. | ||
Default className: react-aria-OverlayArrow
| Render Prop | CSS Selector |
|---|---|
placement | CSS Selector: [data-placement="left | right | top | bottom"]
|
| The placement of the overlay relative to the trigger. | |