Skip to content

Popover

Popover

A non-modal popup anchored to a trigger: Popover.Trigger (merges its props onto the child button) and Popover.Content (portaled, positioned role="dialog" surface). Use it for custom popups such as filters or details; for a menu button use Menu.Trigger and Menu.Popover, which add menu semantics and keyboard support.

Controlled (open/onOpenChange) or uncontrolled (defaultOpen); side/align place the content, and ignoreOutsideRefs lists external elements (such as a toggle button) whose presses do not dismiss it.

- **Hover cards:** openOnHover opens it when a mouse pointer rests on the trigger (openDelay) and closes it once the pointer has left the trigger and the content (closeDelay), unless focus is inside; a click on the trigger pins it.
- **Context popovers:** openOnContext makes the trigger a context-menu region: a right click opens it at the pointer, Shift+F10 or the ContextMenu key at the focused row (with focus moving into the content). Name the content with title or aria-label.
- **Custom anchors:** target places it at another element or at a VirtualElement (a point, a text selection); with a controlled open it needs no trigger.
- **Motion:** the content fades and slides in from its trigger and back out as it closes; Popover.Content's motion turns it off or replaces it.

Examples

Default

export const Default: Story = {};

Labelled By Trigger

export const LabelledByTrigger: Story = {
  args: {
    children: (
      <>
        <Popover.Trigger>
          <Button>Filters</Button>
        </Popover.Trigger>
        <Popover.Content>
          <p style={{ margin: 0 }}>Choose which items to show.</p>
        </Popover.Content>
      </>
    ),
  },
};

Icon Only Trigger

export const IconOnlyTrigger: Story = {
  args: {
    children: (
      <>
        <Popover.Trigger>
          <Tooltip content="Filters" relationship="label">
            <Button icon={<FilterIcon />} />
          </Tooltip>
        </Popover.Trigger>
        <Popover.Content>
          <p style={{ margin: 0 }}>Choose which items to show.</p>
        </Popover.Content>
      </>
    ),
  },
};

Placement

export const Placement: Story = {
  args: {
    side: 'top',
    align: 'center',
  },
};

Controlled

export const Controlled: Story = {
  render: ({ onOpenChange, ...args }) => {
    const [open, setOpen] = React.useState(false);
    const toggleRef = React.useRef<HTMLButtonElement>(null);
    const change = (next: boolean) => {
      setOpen(next);
      onOpenChange?.(next);
    };
    return (
      <div style={{ display: 'flex', gap: 8, alignItems: 'start' }}>
        <Popover open={open} onOpenChange={change} ignoreOutsideRefs={[toggleRef]} {...args}>
          <Popover.Trigger>
            <Button appearance="primary">Toggle Popover</Button>
          </Popover.Trigger>
          <Popover.Content title="Controlled popover">
            <p style={{ margin: 0 }}>This popover is controlled via state.</p>
            <Button
              appearance="subtle"
              size="small"
              onClick={() => change(false)}
              style={{ marginTop: 8 }}
            >
              Close
            </Button>
          </Popover.Content>
        </Popover>
        <Button ref={toggleRef} appearance="subtle" onClick={() => change(!open)}>
          External Toggle
        </Button>
      </div>
    );
  },
};

Hover Card

export const HoverCard: Story = {
  args: {
    openOnHover: true,
    children: (
      <>
        <Popover.Trigger>
          <Button appearance="transparent">Maria Lopez</Button>
        </Popover.Trigger>
        <Popover.Content title="Maria Lopez">
          <div className="flex items-center gap-3">
            <Avatar name="Maria Lopez" size="large" />
            <span className="text-wave-muted-foreground">Product designer, Oslo</span>
          </div>
          <Button appearance="primary" size="small" className="mt-3">
            Follow
          </Button>
        </Popover.Content>
      </>
    ),
  },
};

Context Popover

export const ContextPopover: Story = {
  args: {
    openOnContext: true,
    children: (
      <>
        <Popover.Trigger>
          <div
            role="group"
            aria-label="Files"
            aria-keyshortcuts="Shift+F10"
            className="flex w-64 flex-col items-stretch gap-1"
          >
            {['Report.docx', 'Budget.xlsx', 'Slides.pptx'].map((file) => (
              <Button key={file} appearance="subtle" className="justify-start">
                {file}
              </Button>
            ))}
            <Input aria-label="Filter files" placeholder="Filter" />
          </div>
        </Popover.Trigger>
        <Popover.Content title="File details">
          <p style={{ margin: 0 }}>Shared with 3 people, edited today.</p>
          <Button size="small" className="mt-3">
            Share
          </Button>
        </Popover.Content>
      </>
    ),
  },
};

Anchored To Target

export const AnchoredToTarget: Story = {
  render: function AnchoredToTargetStory({ onOpenChange, ...args }) {
    const [open, setOpen] = React.useState(false);
    const [target, setTarget] = React.useState<HTMLButtonElement | null>(null);
    const contentId = React.useId();
    const change = (next: boolean) => {
      setOpen(next);
      onOpenChange?.(next);
    };
    return (
      <>
        <Button
          ref={setTarget}
          aria-haspopup="dialog"
          aria-expanded={open}
          aria-controls={open ? contentId : undefined}
          onClick={() => change(!open)}
        >
          Details
        </Button>
        <Popover {...args} open={open} onOpenChange={change} target={target}>
          <Popover.Content id={contentId} title="Details">
            <p style={{ margin: 0 }}>Anchored to the Details button.</p>
            <Button size="small" className="mt-3" onClick={() => change(false)}>
              Close
            </Button>
          </Popover.Content>
        </Popover>
      </>
    );
  },
};

Motion

export const Motion: Story = {
  render: function MotionPopovers({ children: _children, ...args }) {
    return (
      <div className="flex flex-wrap gap-2">
        {motionCases(fadeAndZoom).map(({ label, motion }) => (
          // The story renders one popover per case; every other arg is forwarded.
          <Popover key={label} {...args}>
            <Popover.Trigger>
              <Button>{label}</Button>
            </Popover.Trigger>
            <Popover.Content title={label} motion={motion}>
              <p style={{ margin: 0 }}>Press Escape or click outside to see the exit.</p>
            </Popover.Content>
          </Popover>
        ))}
      </div>
    );
  },
};

Appearances And Sizes

export const AppearancesAndSizes: Story = {
  render: function AppearancesAndSizesPopovers({ children: _children, ...args }) {
    return (
      <div className="flex flex-wrap gap-2">
        {(['neutral', 'brand', 'inverted'] as const).map((appearance) => (
          <Popover key={appearance} {...args} appearance={appearance}>
            <Popover.Trigger>
              <Button>{appearance}</Button>
            </Popover.Trigger>
            <Popover.Content title={`A ${appearance} popover`}>
              <p style={{ margin: 0 }}>Content that reads on the {appearance} surface.</p>
            </Popover.Content>
          </Popover>
        ))}
        {(['small', 'large'] as const).map((size) => (
          <Popover key={size} {...args} size={size} withArrow={false}>
            <Popover.Trigger>
              <Button>{size}, no arrow</Button>
            </Popover.Trigger>
            <Popover.Content title={`A ${size} popover`}>
              <p style={{ margin: 0 }}>Padded {size}.</p>
            </Popover.Content>
          </Popover>
        ))}
      </div>
    );
  },
};

Focus Trap And Role

export const FocusTrapAndRole: Story = {
  render: function FocusTrapPopovers({ children: _children, ...args }) {
    return (
      <div className="flex flex-wrap gap-2">
        <Popover {...args} trapFocus>
          <Popover.Trigger>
            <Button>Rename (focus trapped)</Button>
          </Popover.Trigger>
          <Popover.Content title="Rename">
            <Input aria-label="New name" />
            <Button size="small" className="mt-3">
              Save
            </Button>
          </Popover.Content>
        </Popover>
        <Popover {...args}>
          <Popover.Trigger>
            <Button>Details (group)</Button>
          </Popover.Trigger>
          <Popover.Content title="Details" role="group">
            <p style={{ margin: 0 }}>Created yesterday by Ada.</p>
          </Popover.Content>
        </Popover>
      </div>
    );
  },
};

Inline And Close On Scroll

export const InlineAndCloseOnScroll: Story = {
  render: function InlinePopovers({ children: _children, ...args }) {
    return (
      <div className="flex flex-wrap items-start gap-4">
        <div
          className="relative rounded-md border border-wave-border p-4"
          style={{ minHeight: 160 }}
        >
          <Popover {...args} inline>
            <Popover.Trigger>
              <Button>Inline popover</Button>
            </Popover.Trigger>
            <Popover.Content title="In place">
              <p style={{ margin: 0 }}>Rendered inside the box.</p>
            </Popover.Content>
          </Popover>
        </div>
        <div className="h-24 w-64 overflow-auto rounded-md border border-wave-border p-2">
          <Popover {...args} closeOnScroll>
            <Popover.Trigger>
              <Button>Closes on scroll</Button>
            </Popover.Trigger>
            <Popover.Content title="Scroll away">
              <p style={{ margin: 0 }}>Scroll this box to close me.</p>
            </Popover.Content>
          </Popover>
          <div style={{ height: 200 }} aria-hidden="true" />
        </div>
      </div>
    );
  },
};

Props

NameTypeRequiredDefaultDescription
openbooleanNo

Controlled open state of the popover. The content renders only in the browser: an open popover is closed in the server HTML and opens once it has hydrated.

defaultOpenbooleanNofalse

Default open state for uncontrolled usage. The content renders only in the browser: a popover open by default is closed in the server HTML and opens once it has hydrated.

onOpenChange(open: boolean, details?: PopoverOpenChangeDetails) => voidNo

Called with the requested open state when it differs from the current one: a trigger click, Escape and an outside press; the hover opening and closing of openOnHover; a scroll with closeOnScroll; the close of the Dialog, Drawer or popup it was opened from; and, with openOnContext, a context gesture (a right click, a macOS Ctrl+click, Shift+F10 or the ContextMenu key), a right click outside, and a scroll that moves the row it opened at.

The second argument says why (details.reason: trigger, hover, context, escape, outside-press, scroll or parent-closed) and passes the DOM event behind the request (details.event), so a controlled popover can refuse only some ways of closing. WaveUI always passes it; it is typed optional so that a handler written before it keeps compiling (a next major makes it required, as Dialog's is).

side'top' | 'bottom' | 'start' | 'end' | 'left' | 'right'No'bottom'

Side of the trigger the content opens on. start/end follow the writing direction. The content flips to the opposite side when there is not enough room.

align'start' | 'center' | 'end'No'start'

Alignment of the content along the trigger's edge.

ignoreOutsideRefsReadonlyArray<React.RefObject<HTMLElement | null>>No

Elements outside the popover whose presses must not dismiss it, e.g. an external toggle button that opens and closes the popover itself.

openOnHoverbooleanNofalse

Open the popover when a mouse pointer rests on its trigger (a hover card), and close it once the pointer has been off the trigger and the content for closeDelay while focus is not inside the content. A popover opened by hover does not take focus, and its hover close leaves focus where it is; a click on its trigger keeps it open and keeps focus where it is (a second click closes it, as without hover). After Escape or an outside press it does not reopen until the pointer has left the trigger. Touch and pen never open it by hover, and an aria-disabled trigger never opens. A triangle between the trigger and the content keeps it open while the pointer moves diagonally into it. Ignored with openOnContext (development warning).

openDelaynumberNo250

Milliseconds a hovering mouse pointer rests on the trigger before the popover opens (mouse hover only).

closeDelaynumberNo500

Milliseconds before a hover-opened popover closes once the mouse pointer has left it and its trigger (Fluent's mouseLeaveDelay; mouse hover only).

openOnContextbooleanNofalse

Make Popover.Trigger a context-menu region (a list, a row, a canvas): a right click (a Ctrl+click on macOS, a long press where the browser reports one) opens the popover at the pointer and leaves focus where it is (Tab from that element enters the content), and Shift+F10 or the ContextMenu key opens it at the focused element inside the region and moves focus into the content, instead of a click. Focus returns to the element that had it. The browser's context menu is suppressed there and inside the content, except in text fields inside the region, which keep it. A press elsewhere, a right click outside or a scroll that moves the row it opened at (the one under the pointer, or the focused one), as a scroll of the region's own content does, closes it. The trigger gets no aria-haspopup/aria-expanded (it is not a popover button; with a render-prop child, do not spread them): name the content with title, aria-label or aria-labelledby, and consider aria-keyshortcuts="Shift+F10" on the region. iOS Safari reports no long press. openOnHover is ignored with it.

targetPopupTargetInputNo

Where to place the content instead of next to Popover.Trigger: an element or a VirtualElement (a rectangle, such as a point; an inline object is fine). With a controlled open, a popover with a target needs no trigger; name it with title, aria-label or aria-labelledby, and give a toggle button you use as the target aria-haspopup="dialog", aria-expanded and aria-controls yourself. A press on a target element does not close the popover, and Tab from it enters the content when there is no trigger. Hold the element in state, or pass a ref object (read after each render of the popover, so an element that attaches without it rendering is noticed on its next render). A popover opened by openOnContext is placed at the gesture instead.

positioningPopupPositioningNo`{ offset: 8 }`

Advanced positioning (Fluent's positioning): offset (px from the anchor), fitViewport (limit the content to the space the viewport leaves; Fluent's autoSize), matchReferenceWidth, fallbackPlacements (tried in order when the requested side has no room) and target (used when the target prop is not set). side and align stay separate props.

withArrowbooleanNotrue

Draws the beak, the small triangle that points at the trigger (or target). Pass false for a surface without it; the beak slot (slotProps.beak) then renders nothing. Fluent's withArrow, whose default is no arrow: WaveUI keeps drawing it by default.

trapFocusbooleanNofalse

Traps focus in the content while it is open, like a dialog that leaves the page usable: focus moves into the content when it opens (its first focusable element, else the content itself) and Tab and Shift+Tab cycle inside it, toasts and popups opened from it included; Escape and a press outside still close it. A hover-opened popover (openOnHover) takes no trap until a click pins it. The page is not made inert and does not stop scrolling. Without it, focus stays on the trigger when the popover opens and Tab enters the content from there (WaveUI's design, popoversurface-3). Fluent's trapFocus.

inlinebooleanNofalse

Renders the content in place, as the next sibling of the element that renders Popover.Content (position it where the trigger is: it is placed with the absolute strategy against its nearest positioned ancestor), instead of in a portal at the end of the document. Use it where the content must stay inside its container: a shadow root, a region that is rotated or scaled, a tab order that must follow the DOM. The content still moves in and out with its dismiss layer. Fluent's inline.

closeOnScrollbooleanNofalse

Closes the popover when anything outside it scrolls (the page, or any scrollable container; a scroll inside the content or inside a popup opened from it does not), reporting the reason scroll. Fluent's closeOnScroll.

appearance'neutral' | 'brand' | 'inverted'No'neutral'

The look of the content: neutral (the page background with a border), brand (the brand fill) or inverted (a dark surface in the light theme). Rendered as data-appearance. Fluent's appearance, which has brand and inverted and a neutral default.

size'small' | 'medium' | 'large'No'medium'

The padding of the content: small (12px), medium (16px) or large (20px). Rendered as data-size. The width is 16rem; put a width in className for another. Fluent's size.

childrenReact.ReactNodeYes

Popover.Trigger and Popover.Content.

Parts

  • Popover.Trigger
  • Popover.Content