Displays rich content in a portal, triggered by a button.
import React from "react";import * as Popover from "@radix-ui/react-popover";import { MixerHorizontalIcon, Cross2Icon } from "@radix-ui/react-icons";import "./styles.css";const PopoverDemo = () => (<Popover.Root><Popover.Trigger asChild><button className="IconButton" aria-label="Update dimensions"><MixerHorizontalIcon /></button></Popover.Trigger><Popover.Portal><Popover.Content className="PopoverContent" sideOffset={5}><div style={{ display: "flex", flexDirection: "column", gap: 10 }}><p className="Text" style={{ marginBottom: 10 }}>Dimensions</p><fieldset className="Fieldset"><label className="Label" htmlFor="width">Width</label><input className="Input" id="width" defaultValue="100%" /></fieldset><fieldset className="Fieldset"><label className="Label" htmlFor="maxWidth">Max. width</label><input className="Input" id="maxWidth" defaultValue="300px" /></fieldset><fieldset className="Fieldset"><label className="Label" htmlFor="height">Height</label><input className="Input" id="height" defaultValue="25px" /></fieldset><fieldset className="Fieldset"><label className="Label" htmlFor="maxHeight">Max. height</label><input className="Input" id="maxHeight" defaultValue="none" /></fieldset></div><Popover.Close className="PopoverClose" aria-label="Close"><Cross2Icon /></Popover.Close><Popover.Arrow className="PopoverArrow" /></Popover.Content></Popover.Portal></Popover.Root>);export default PopoverDemo;
Can be controlled or uncontrolled.
Customize side, alignment, offsets, collision handling.
Optionally render a pointing arrow.
Focus is fully managed and customizable.
Supports modal and non-modal modes.
Dismissing and layering behavior is highly customizable.
Install the component from your command line.
Import all parts and piece them together.
Contains all the parts of a popover.
The button that toggles the popover. By default, the Popover.Content
will position itself against the trigger.
An optional element to position the Popover.Content
against. If this part is not used, the content will position alongside the Popover.Trigger
.
When used, portals the content part into the body
.
The component that pops out when the popover is open.
An optional arrow element to render alongside the popover. This can be used to help visually link the anchor with the Popover.Content
. Must be rendered inside Popover.Content
.
The button that closes an open popover.
You may want to constrain the width of the content so that it matches the trigger width. You may also want to constrain its height to not exceed the viewport.
We expose several CSS custom properties such as --radix-popover-trigger-width
and --radix-popover-content-available-height
to support this. Use them to constrain the content dimensions.
We expose a CSS custom property --radix-popover-content-transform-origin
. Use it to animate the content from its computed origin based on side
, sideOffset
, align
, alignOffset
and any collisions.
We expose data-side
and data-align
attributes. Their values will change at runtime to reflect collisions. Use them to create collision and direction-aware animations.
You can anchor the content to another element if you do not want to use the trigger as the anchor.
Adheres to the Dialog WAI-ARIA design pattern.
Create your own API by abstracting the primitive parts into your own component.
This example abstracts the Popover.Arrow
part and sets a default sideOffset
configuration.