Popover
An accessible popup anchored to a button.
View as MarkdownAnatomy
Import the component and assemble its parts:
import { Popover } from '@base-ui-components/react/popover';
<Popover.Root>
  <Popover.Trigger />
  <Popover.Portal>
    <Popover.Backdrop />
    <Popover.Positioner>
      <Popover.Popup>
        <Popover.Arrow />
        <Popover.Title />
        <Popover.Description />
        <Popover.Close />
      </Popover.Popup>
    </Popover.Positioner>
  </Popover.Portal>
</Popover.Root>API reference
Root
Groups all parts of the popover. Doesn’t render its own HTML element.
defaultOpenboolean
(default: false
)
booleanfalse- Name
- Description
- Whether the popover is initially open. - To render a controlled popover, use the - openprop instead.
- Type
- boolean | undefined
- Default
- false
openboolean
boolean- Name
- Description
- Whether the popover is currently open. 
- Type
- boolean | undefined
onOpenChangefunction
function- Name
- Description
- Event handler called when the popover is opened or closed. 
- Type
- | (( open: boolean, eventDetails: Popover.Root.ChangeEventDetails, ) => void) | undefined
actionsRefRefObject<Popover.Root.Actions>
RefObject<Popover.Root.Actions>- Name
- Description
- A ref to imperative actions. - unmount: When specified, the popover will not be unmounted when closed. Instead, the- unmountfunction must be called to unmount the popover manually. Useful when the popover's animation is controlled by an external library.
 
- Type
- React.RefObject<Popover.Root.Actions> | undefined
modalboolean | 'trap-focus'
(default: false
)
boolean | 'trap-focus'false- Name
- Description
- Determines if the popover enters a modal state when open. - true: user interaction is limited to the popover: document page scroll is locked, and pointer interactions on outside elements are disabled.
- false: user interaction with the rest of the document is allowed.
- 'trap-focus': focus is trapped inside the popover, but document page scroll is not locked and pointer interactions outside of it remain enabled.
 
- Type
- boolean | 'trap-focus' | undefined
- Default
- false
onOpenChangeCompletefunction
function- Description
- Event handler called after any animations complete when the popover is opened or closed. 
- Type
- ((open: boolean) => void) | undefined
openOnHoverboolean
(default: false
)
booleanfalse- Name
- Description
- Whether the popover should also open when the trigger is hovered. 
- Type
- boolean | undefined
- Default
- false
delaynumber
(default: 300
)
number300- Name
- Description
- How long to wait before the popover may be opened on hover. Specified in milliseconds. - Requires the - openOnHoverprop.
- Type
- number | undefined
- Default
- 300
closeDelaynumber
(default: 0
)
number0- Name
- Description
- How long to wait before closing the popover that was opened on hover. Specified in milliseconds. - Requires the - openOnHoverprop.
- Type
- number | undefined
- Default
- 0
childrenReactNode
ReactNode- Name
- Type
- React.ReactNode
Trigger
A button that opens the popover.
Renders a <button> element.
nativeButtonboolean
(default: true
)
booleantrue- Name
- Description
- Whether the component renders a native - <button>element when replacing it via the- renderprop. Set to- falseif the rendered element is not a button (e.g.- <div>).
- Type
- boolean | undefined
- Default
- true
classNamestring | function
string | function- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- string | ((state: Popover.Trigger.State) => string)
renderReactElement | function
ReactElement | function- Name
- Description
- Allows you to replace the component’s HTML element with a different tag, or compose it with another component. - Accepts a - ReactElementor a function that returns the element to render.
- Type
- | ReactElement | (( props: HTMLProps, state: Popover.Trigger.State, ) => ReactElement)
data-popup-open
Present when the corresponding popover is open.
data-pressed
Present when the trigger is pressed.
Backdrop
An overlay displayed beneath the popover.
Renders a <div> element.
classNamestring | function
string | function- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- | string | ((state: Popover.Backdrop.State) => string)
renderReactElement | function
ReactElement | function- Name
- Description
- Allows you to replace the component’s HTML element with a different tag, or compose it with another component. - Accepts a - ReactElementor a function that returns the element to render.
- Type
- | ReactElement | (( props: HTMLProps, state: Popover.Backdrop.State, ) => ReactElement)
data-open
Present when the popup is open.
data-closed
Present when the popup is closed.
data-starting-style
Present when the popup is animating in.
data-ending-style
Present when the popup is animating out.
Portal
A portal element that moves the popup to a different part of the DOM.
By default, the portal element is appended to <body>.
containerUnion
Union- Name
- Description
- A parent element to render the portal element into. 
- Type
- | HTMLElement | ShadowRoot | React.RefObject<HTMLElement | ShadowRoot | null> | null | undefined
childrenReactNode
ReactNode- Name
- Type
- React.ReactNode
keepMountedboolean
(default: false
)
booleanfalse- Name
- Description
- Whether to keep the portal mounted in the DOM while the popup is hidden. 
- Type
- boolean | undefined
- Default
- false
Positioner
Positions the popover against the trigger.
Renders a <div> element.
collisionAvoidanceCollisionAvoidance
CollisionAvoidance- Description
- Determines how to handle collisions when positioning the popup. 
- Type
- | { side?: 'none' | 'flip' align?: 'shift' | 'none' | 'flip' fallbackAxisSide?: 'none' | 'start' | 'end' } | { side?: 'shift' | 'none' align?: 'shift' | 'none' fallbackAxisSide?: 'none' | 'start' | 'end' } | undefined
- Example
- <Positioner collisionAvoidance={{ side: 'shift', align: 'shift', fallbackAxisSide: 'none', }} />
alignAlign
(default: 'center'
)
Align'center'- Name
- Description
- How to align the popup relative to the specified side. 
- Type
- 'center' | 'start' | 'end' | undefined
- Default
- 'center'
alignOffsetnumber | OffsetFunction
(default: 0
)
number | OffsetFunction0- Name
- Description
- Additional offset along the alignment axis in pixels. Also accepts a function that returns the offset to read the dimensions of the anchor and positioner elements, along with its side and alignment. - The function takes a - dataobject parameter with the following properties:- data.anchor: the dimensions of the anchor element with properties- widthand- height.
- data.positioner: the dimensions of the positioner element with properties- widthand- height.
- data.side: which side of the anchor element the positioner is aligned against.
- data.align: how the positioner is aligned relative to the specified side.
 
- Type
- | number | ((data: { side: Side align: Align anchor: { width: number; height: number } positioner: { width: number; height: number } }) => number) | undefined
- Default
- 0
- Example
- <Positioner alignOffset={({ side, align, anchor, positioner }) => { return side === 'top' || side === 'bottom' ? anchor.width : anchor.height; }} />
sideSide
(default: 'bottom'
)
Side'bottom'- Name
- Description
- Which side of the anchor element to align the popup against. May automatically change to avoid collisions. 
- Type
- | 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start' | undefined
- Default
- 'bottom'
sideOffsetnumber | OffsetFunction
(default: 0
)
number | OffsetFunction0- Name
- Description
- Distance between the anchor and the popup in pixels. Also accepts a function that returns the distance to read the dimensions of the anchor and positioner elements, along with its side and alignment. - The function takes a - dataobject parameter with the following properties:- data.anchor: the dimensions of the anchor element with properties- widthand- height.
- data.positioner: the dimensions of the positioner element with properties- widthand- height.
- data.side: which side of the anchor element the positioner is aligned against.
- data.align: how the positioner is aligned relative to the specified side.
 
- Type
- | number | ((data: { side: Side align: Align anchor: { width: number; height: number } positioner: { width: number; height: number } }) => number) | undefined
- Default
- 0
- Example
- <Positioner sideOffset={({ side, align, anchor, positioner }) => { return side === 'top' || side === 'bottom' ? anchor.height : anchor.width; }} />
arrowPaddingnumber
(default: 5
)
number5- Name
- Description
- Minimum distance to maintain between the arrow and the edges of the popup. - Use it to prevent the arrow element from hanging out of the rounded corners of a popup. 
- Type
- number | undefined
- Default
- 5
anchorUnion
Union- Name
- Description
- An element to position the popup against. By default, the popup will be positioned against the trigger. 
- Type
- | Element | React.RefObject<Element | null> | VirtualElement | (() => Element | VirtualElement | null) | null | undefined
collisionBoundaryBoundary
(default: 'clipping-ancestors'
)
Boundary'clipping-ancestors'- Description
- An element or a rectangle that delimits the area that the popup is confined to. 
- Type
- | Element | 'clipping-ancestors' | Element[] | Rect | undefined
- Default
- 'clipping-ancestors'
collisionPaddingPadding
(default: 5
)
Padding5- Name
- Description
- Additional space to maintain from the edge of the collision boundary. 
- Type
- | { top?: number right?: number bottom?: number left?: number } | number | undefined
- Default
- 5
stickyboolean
(default: false
)
booleanfalse- Name
- Description
- Whether to maintain the popup in the viewport after the anchor element was scrolled out of view. 
- Type
- boolean | undefined
- Default
- false
positionMethod'fixed' | 'absolute'
(default: 'absolute'
)
'fixed' | 'absolute''absolute'- Name
- Description
- Determines which CSS - positionproperty to use.
- Type
- 'fixed' | 'absolute' | undefined
- Default
- 'absolute'
trackAnchorboolean
(default: true
)
booleantrue- Name
- Description
- Whether the popup tracks any layout shift of its positioning anchor. 
- Type
- boolean | undefined
- Default
- true
classNamestring | function
string | function- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- | string | ((state: Popover.Positioner.State) => string)
renderReactElement | function
ReactElement | function- Name
- Description
- Allows you to replace the component’s HTML element with a different tag, or compose it with another component. - Accepts a - ReactElementor a function that returns the element to render.
- Type
- | ReactElement | (( props: HTMLProps, state: Popover.Positioner.State, ) => ReactElement)
data-open
Present when the popup is open.
data-closed
Present when the popup is closed.
data-anchor-hidden
Present when the anchor is hidden.
data-align
Indicates how the popup is aligned relative to specified side.
data-side
Indicates which side the popup is positioned relative to the trigger.
--anchor-height
The anchor's height.
--anchor-width
The anchor's width.
--available-height
The available height between the trigger and the edge of the viewport.
--available-width
The available width between the trigger and the edge of the viewport.
--transform-origin
The coordinates that this element is anchored to. Used for animations and transitions.
Popup
A container for the popover contents.
Renders a <div> element.
initialFocusUnion
Union- Name
- Description
- Determines the element to focus when the popover is opened. - false: Do not move focus.
- true: Move focus based on the default behavior (first tabbable element or popup).
- RefObject: Move focus to the ref element.
- function: Called with the interaction type (- mouse,- touch,- pen, or- keyboard). Return an element to focus,- trueto use the default behavior, or- false/- undefinedto do nothing.
 
- Type
- | boolean | React.RefObject<HTMLElement | null> | (( openType: InteractionType, ) => boolean | void | HTMLElement | null) | undefined
finalFocusUnion
Union- Name
- Description
- Determines the element to focus when the popover is closed. - false: Do not move focus.
- true: Move focus based on the default behavior (trigger or previously focused element).
- RefObject: Move focus to the ref element.
- function: Called with the interaction type (- mouse,- touch,- pen, or- keyboard). Return an element to focus,- trueto use the default behavior, or- false/- undefinedto do nothing.
 
- Type
- | boolean | React.RefObject<HTMLElement | null> | (( closeType: InteractionType, ) => boolean | void | HTMLElement | null) | undefined
classNamestring | function
string | function- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- string | ((state: Popover.Popup.State) => string)
renderReactElement | function
ReactElement | function- Name
- Description
- Allows you to replace the component’s HTML element with a different tag, or compose it with another component. - Accepts a - ReactElementor a function that returns the element to render.
- Type
- | ReactElement | (( props: HTMLProps, state: Popover.Popup.State, ) => ReactElement)
data-open
Present when the popup is open.
data-closed
Present when the popup is closed.
data-align
Indicates how the popup is aligned relative to specified side.
data-instant
Present if animations should be instant.
data-side
Indicates which side the popup is positioned relative to the trigger.
data-starting-style
Present when the popup is animating in.
data-ending-style
Present when the popup is animating out.
Arrow
Displays an element positioned against the popover anchor.
Renders a <div> element.
classNamestring | function
string | function- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- string | ((state: Popover.Arrow.State) => string)
renderReactElement | function
ReactElement | function- Name
- Description
- Allows you to replace the component’s HTML element with a different tag, or compose it with another component. - Accepts a - ReactElementor a function that returns the element to render.
- Type
- | ReactElement | (( props: HTMLProps, state: Popover.Arrow.State, ) => ReactElement)
data-open
Present when the popup is open.
data-closed
Present when the popup is closed.
data-uncentered
Present when the popover arrow is uncentered.
data-anchor-hidden
Present when the anchor is hidden.
data-align
Indicates how the popup is aligned relative to specified side.
data-side
Indicates which side the popup is positioned relative to the trigger.
Title
A heading that labels the popover.
Renders an <h2> element.
classNamestring | function
string | function- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- string | ((state: Popover.Title.State) => string)
renderReactElement | function
ReactElement | function- Name
- Description
- Allows you to replace the component’s HTML element with a different tag, or compose it with another component. - Accepts a - ReactElementor a function that returns the element to render.
- Type
- | ReactElement | (( props: HTMLProps, state: Popover.Title.State, ) => ReactElement)
Description
A paragraph with additional information about the popover.
Renders a <p> element.
classNamestring | function
string | function- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- | string | ((state: Popover.Description.State) => string)
renderReactElement | function
ReactElement | function- Name
- Description
- Allows you to replace the component’s HTML element with a different tag, or compose it with another component. - Accepts a - ReactElementor a function that returns the element to render.
- Type
- | ReactElement | (( props: HTMLProps, state: Popover.Description.State, ) => ReactElement)
Close
A button that closes the popover.
Renders a <button> element.
nativeButtonboolean
(default: true
)
booleantrue- Name
- Description
- Whether the component renders a native - <button>element when replacing it via the- renderprop. Set to- falseif the rendered element is not a button (e.g.- <div>).
- Type
- boolean | undefined
- Default
- true
classNamestring | function
string | function- Name
- Description
- CSS class applied to the element, or a function that returns a class based on the component’s state. 
- Type
- string | ((state: Popover.Close.State) => string)
renderReactElement | function
ReactElement | function- Name
- Description
- Allows you to replace the component’s HTML element with a different tag, or compose it with another component. - Accepts a - ReactElementor a function that returns the element to render.
- Type
- | ReactElement | (( props: HTMLProps, state: Popover.Close.State, ) => ReactElement)