gnome-ui
Components

Popover

An accessible popup anchored to a trigger element. Supports title, description, close button, and rich content.

Popover component
    import { Popover } from "gnome-ui/popover";
    import { Button } from "@/components/ui/button";

    export function PopoverBasic() {
      return (
        <Popover.Root>
          <Popover.Trigger
            render={<Button variant="outline"><Icons.Bell /> Notifications</Button>}
          />
          <Popover.Portal>
            <Popover.Positioner sideOffset={8}>
              <Popover.Popup>
                <Popover.Title>Notifications</Popover.Title>
                <Popover.Description>
                  You're all caught up. No new notifications right now.
                </Popover.Description>
              </Popover.Popup>
            </Popover.Positioner>
          </Popover.Portal>
        </Popover.Root>
      );
    }

Rich Content

The popup can contain any content. This example shows a user profile with metadata and actions.

PopoverArrow

Displays an element positioned against the popover anchor. Renders a &lt;div&gt; element.

Documentation: Base UI Popover

API reference

Root

Groups all parts of the popover. Doesn’t render its own HTML element.

Root Props:

PropTypeDefaultDescription
defaultOpenbooleanfalseWhether the popover is initially open.To render a controlled popover, use the open prop instead.
openboolean-Whether the popover is currently open.
onOpenChange((open: boolean, eventDetails: Popover.Root.ChangeEventDetails) => void)-Event handler called when the popover is opened or closed.
actionsRefRefObject<Popover.Root.Actions | null>-A ref to imperative actions.* unmount: When specified, the popover will not be unmounted when closed. Instead, the unmount function must be called to unmount the popover manually. Useful when the popover's animation is controlled by an external library.
* close: Closes the dialog imperatively when called.
defaultTriggerIdstring | null-ID of the trigger that the popover is associated with. This is useful in conjunction with the defaultOpen prop to create an initially open popover.
handlePopover.Handle<Payload>-A handle to associate the popover with a trigger. If specified, allows external triggers to control the popover's open state.
modalboolean | 'trap-focus'falseDetermines 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. | | onOpenChangeComplete | ((open: boolean) => void) | - | Event handler called after any animations complete when the popover is opened or closed. | | triggerId | string \| null | - | ID of the trigger that the popover is associated with. This is useful in conjunction with the open prop to create a controlled popover. There's no need to specify this prop when the popover is uncontrolled (i.e. when the open prop is not set). | | children | ReactNode \| PayloadChildRenderFunction<Payload> | - | The content of the popover. This can be a regular React node or a render function that receives the payload of the active trigger. |

Trigger

A button that opens the popover. Renders a <button> element.

Trigger Props:

PropTypeDefaultDescription
handlePopover.Handle<Payload>-A handle to associate the trigger with a popover.
nativeButtonbooleantrueWhether the component renders a native <button> element when replacing it via the render prop. Set to false if the rendered element is not a button (e.g. <div>).
payloadPayload-A payload to pass to the popover when it is opened.
openOnHoverbooleanfalseWhether the popover should also open when the trigger is hovered.
delaynumber300How long to wait before the popover may be opened on hover. Specified in milliseconds.Requires the openOnHover prop.
closeDelaynumber0How long to wait before closing the popover that was opened on hover. Specified in milliseconds.Requires the openOnHover prop.
idstring-ID of the trigger. In addition to being forwarded to the rendered element, it is also used to specify the active trigger for the popover in controlled mode (with the Popover.Root triggerId prop).
classNamestring | ((state: Popover.Trigger.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component’s state.
styleCSSProperties | ((state: Popover.Trigger.State) => CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component’s state.
renderReactElement | ((props: HTMLProps, state: Popover.Trigger.State) => ReactElement)-Allows you to replace the component’s HTML element with a different tag, or compose it with another component.Accepts a ReactElement or a function that returns the element to render.

Trigger Data Attributes:

AttributeTypeDescription
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.

Backdrop Props:

PropTypeDefaultDescription
classNamestring | ((state: Popover.Backdrop.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component’s state.
styleCSSProperties | ((state: Popover.Backdrop.State) => CSSProperties | undefined)--
renderReactElement | ((props: HTMLProps, state: Popover.Backdrop.State) => ReactElement)-Allows you to replace the component’s HTML element with a different tag, or compose it with another component.Accepts a ReactElement or a function that returns the element to render.

Backdrop Data Attributes:

AttributeTypeDescription
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>. Renders a <div> element.

Portal Props:

PropTypeDefaultDescription
containerHTMLElement | ShadowRoot | RefObject<HTMLElement | ShadowRoot | null> | null-A parent element to render the portal element into.
classNamestring | ((state: Popover.Portal.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component’s state.
styleCSSProperties | ((state: Popover.Portal.State) => CSSProperties | undefined)--
keepMountedbooleanfalseWhether to keep the portal mounted in the DOM while the popup is hidden.
renderReactElement | ((props: HTMLProps, state: Popover.Portal.State) => ReactElement)-Allows you to replace the component’s HTML element with a different tag, or compose it with another component.Accepts a ReactElement or a function that returns the element to render.

Positioner

Positions the popover against the trigger. Renders a <div> element.

Positioner Props:

PropTypeDefaultDescription
disableAnchorTrackingbooleanfalseWhether to disable the popup from tracking any layout shift of its positioning anchor.
alignAlign'center'How to align the popup relative to the specified side.
alignOffsetnumber | OffsetFunction0Additional 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 data object parameter with the following properties:* data.anchor: the dimensions of the anchor element with properties width and height.
  • data.positioner: the dimensions of the positioner element with properties width and 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. | | side | Side | 'bottom' | Which side of the anchor element to align the popup against. May automatically change to avoid collisions. | | sideOffset | number \| OffsetFunction | 0 | 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 data object parameter with the following properties:* data.anchor: the dimensions of the anchor element with properties width and height.
  • data.positioner: the dimensions of the positioner element with properties width and 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. | | arrowPadding | number | 5 | 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. | | anchor | Element \| VirtualElement \| RefObject<Element \| null> \| (() => Element \| VirtualElement \| null) \| null | - | An element to position the popup against. By default, the popup will be positioned against the trigger. | | collisionAvoidance | CollisionAvoidance | - | Determines how to handle collisions when positioning the popup. | | collisionBoundary | Boundary | 'clipping-ancestors' | An element or a rectangle that delimits the area that the popup is confined to. | | collisionPadding | Padding | 5 | Additional space to maintain from the edge of the collision boundary. | | sticky | boolean | false | Whether to maintain the popup in the viewport after the anchor element was scrolled out of view. | | positionMethod | 'absolute' \| 'fixed' | 'absolute' | Determines which CSS position property to use. | | className | string \| ((state: Popover.Positioner.State) => string \| undefined) | - | CSS class applied to the element, or a function that returns a class based on the component’s state. | | style | CSSProperties \| ((state: Popover.Positioner.State) => CSSProperties \| undefined) | - | - | | render | ReactElement \| ((props: HTMLProps, state: Popover.Positioner.State) => ReactElement) | - | Allows you to replace the component’s HTML element with a different tag, or compose it with another component.Accepts a ReactElement or a function that returns the element to render. |

Positioner Data Attributes:

AttributeTypeDescription
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'start' | 'center' | 'end'Indicates how the popup is aligned relative to specified side.
data-side'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'Indicates which side the popup is positioned relative to the trigger.

Positioner CSS Variables:

VariableTypeDefaultDescription
--anchor-heightnumber-The anchor's height.
--anchor-widthnumber-The anchor's width.
--available-heightnumber-The available height between the trigger and the edge of the viewport.
--available-widthnumber-The available width between the trigger and the edge of the viewport.
--positioner-height--The height of the popover's positioner. It is important to set height to this value when using CSS to animate size changes.
--positioner-width--The width of the popover's positioner. It is important to set width to this value when using CSS to animate size changes.
--transform-originstring-The coordinates that this element is anchored to. Used for animations and transitions.

A container for the popover contents. Renders a <div> element.

Popup Props:

PropTypeDefaultDescription
initialFocusboolean | RefObject<HTMLElement | null> | ((openType: InteractionType) => boolean | void | HTMLElement | null)-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, true to use the default behavior, or false/undefined to do nothing. | | finalFocus | boolean \| RefObject<HTMLElement \| null> \| ((closeType: InteractionType) => boolean \| void \| HTMLElement \| null) | - | 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, true to use the default behavior, or false/undefined to do nothing. | | className | string \| ((state: Popover.Popup.State) => string \| undefined) | - | CSS class applied to the element, or a function that returns a class based on the component’s state. | | style | CSSProperties \| ((state: Popover.Popup.State) => CSSProperties \| undefined) | - | - | | render | ReactElement \| ((props: HTMLProps, state: Popover.Popup.State) => ReactElement) | - | Allows you to replace the component’s HTML element with a different tag, or compose it with another component.Accepts a ReactElement or a function that returns the element to render. |

Popup Data Attributes:

AttributeTypeDescription
data-open-Present when the popup is open.
data-closed-Present when the popup is closed.
data-align'start' | 'center' | 'end'Indicates how the popup is aligned relative to specified side.
data-instant'click' | 'dismiss'Present if animations should be instant.
data-side'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'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.

Popup CSS Variables:

VariableTypeDefaultDescription
--popup-height--The height of the popup.
--popup-width--The width of the popup.

Arrow

Displays an element positioned against the popover anchor. Renders a <div> element.

Arrow Props:

PropTypeDefaultDescription
classNamestring | ((state: Popover.Arrow.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component’s state.
styleCSSProperties | ((state: Popover.Arrow.State) => CSSProperties | undefined)--
renderReactElement | ((props: HTMLProps, state: Popover.Arrow.State) => ReactElement)-Allows you to replace the component’s HTML element with a different tag, or compose it with another component.Accepts a ReactElement or a function that returns the element to render.

Arrow Data Attributes:

AttributeTypeDescription
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-align'start' | 'center' | 'end'Indicates how the popup is aligned relative to specified side.
data-side'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'Indicates which side the popup is positioned relative to the trigger.

Title

A heading that labels the popover. Renders an <h2> element.

Title Props:

PropTypeDefaultDescription
classNamestring | ((state: Popover.Title.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component’s state.
styleCSSProperties | ((state: Popover.Title.State) => CSSProperties | undefined)--
renderReactElement | ((props: HTMLProps, state: Popover.Title.State) => ReactElement)-Allows you to replace the component’s HTML element with a different tag, or compose it with another component.Accepts a ReactElement or a function that returns the element to render.

Description

A paragraph with additional information about the popover. Renders a <p> element.

Description Props:

PropTypeDefaultDescription
classNamestring | ((state: Popover.Description.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component’s state.
styleCSSProperties | ((state: Popover.Description.State) => CSSProperties | undefined)--
renderReactElement | ((props: HTMLProps, state: Popover.Description.State) => ReactElement)-Allows you to replace the component’s HTML element with a different tag, or compose it with another component.Accepts a ReactElement or a function that returns the element to render.

Close

A button that closes the popover. Renders a <button> element.

Close Props:

PropTypeDefaultDescription
nativeButtonbooleantrueWhether the component renders a native <button> element when replacing it via the render prop. Set to false if the rendered element is not a button (e.g. <div>).
classNamestring | ((state: Popover.Close.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component’s state.
styleCSSProperties | ((state: Popover.Close.State) => CSSProperties | undefined)--
renderReactElement | ((props: HTMLProps, state: Popover.Close.State) => ReactElement)-Allows you to replace the component’s HTML element with a different tag, or compose it with another component.Accepts a ReactElement or a function that returns the element to render.

Viewport

A viewport for displaying content transitions. This component is only required if one popup can be opened by multiple triggers, its content change based on the trigger and switching between them is animated. Renders a <div> element.

Viewport Props:

PropTypeDefaultDescription
childrenReactNode-The content to render inside the transition container.
classNamestring | ((state: Popover.Viewport.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component’s state.
styleCSSProperties | ((state: Popover.Viewport.State) => CSSProperties | undefined)--
renderReactElement | ((props: HTMLProps, state: Popover.Viewport.State) => ReactElement)-Allows you to replace the component’s HTML element with a different tag, or compose it with another component.Accepts a ReactElement or a function that returns the element to render.

Viewport Data Attributes:

AttributeTypeDescription
data-activation-direction`${'left' | 'right'} {'top' | 'bottom'}`Indicates the direction from which the popup was activated. This can be used to create directional animations based on how the popup was triggered. Contains space-separated values for both horizontal and vertical axes.
data-current-Applied to the direct child of the viewport when no transitions are present or the new content when it's entering.
data-instant'dismiss' | 'click'Present if animations should be instant.
data-previous-Applied to the direct child of the viewport that contains the exiting content when transitions are present.
data-transitioning-Indicates that the viewport is currently transitioning between old and new content.

Viewport CSS Variables:

VariableTypeDefaultDescription
--popup-height--The height of the parent popup. This variable is placed on the 'previous' container and stores the height of the popup when the previous content was rendered. It can be used to freeze the dimensions of the popup when animating between different content.
--popup-width--The width of the parent popup. This variable is placed on the 'previous' container and stores the width of the popup when the previous content was rendered. It can be used to freeze the dimensions of the popup when animating between different content.

On this page