Popover

A non-modal floating panel anchored to its trigger. Escape or an outside press closes it.

Import

tsx
import { Popover } from "@merid/react";

Anatomy

tsx
<Popover.Root>
  <Popover.Trigger />
  <Popover.Content>
    <Popover.Close />
  </Popover.Content>
</Popover.Root>
  • Root holds the open state.
  • Trigger is the <button> the panel is anchored to. Pass asChild to anchor to your own element, such as a Button.
  • Content is the floating panel, portalled and positioned with collision handling.
  • Close is an unstyled button that closes the popover and returns focus to the trigger. Pass asChild to render your own Button.

Examples

Placement

placement accepts any Floating UI placement (top, bottom-start, left-end…). It flips and shifts to stay on screen.

Controlled

Closed

API reference

Popover.Root

PropTypeDefaultDescription
openboolean–Controlled open state.
defaultOpenbooleanfalseInitial open state when uncontrolled.
onOpenChange(open: boolean) => void–Called when the open state should change.
childrenReactNode–Trigger and Content.

Popover.Trigger

Accepts every <button> attribute. type defaults to "button" (not set when asChild is used).

PropTypeDefaultDescription
asChildbooleanfalseRender the single child element (e.g. your own `Button`) instead of a `<button>`, merging props, ref and handlers.
refRef<HTMLButtonElement>–Forwarded ref to the button.

Popover.Content

Accepts every <div> attribute.

PropTypeDefaultDescription
placementPlacement"bottom-start"Preferred placement relative to the trigger.
sideOffsetnumber8Distance from the trigger in px.
aria-labelstring–Accessible name when the content has no visible heading.
containerElement | nulldocument.bodyPortal target. `undefined` uses `document.body`; `null` renders nothing until the target exists.
refRef<HTMLDivElement>–Forwarded ref to the content element.

Popover.Close

Accepts every <button> attribute.

PropTypeDefaultDescription
asChildbooleanfalseRender the single child element (e.g. your own `Button`) instead of a `<button>`, merging props, ref and handlers.
refRef<HTMLButtonElement>–Forwarded ref to the button.

Styling

.mrd-popover is the panel: --mrd-surface, 1px --mrd-line border, --mrd-radius-xl, --mrd-shadow-lg, max width min(360px, 100vw - 16px). It carries data-state="open"; the trigger carries data-state="open" | "closed". Trigger and Close are unstyled buttons; pass asChild with a Button to style them.

Accessibility

Content has role="dialog" (non-modal); the trigger has aria-haspopup="dialog", aria-expanded and aria-controls. Focus moves into the panel on open but is not trapped. See the WAI-ARIA Dialog pattern for the modal counterpart. Give Content an aria-label or a visible heading with aria-labelledby.

KeyAction
SpaceEnterOn the trigger, toggles the popover.
TabMoves through the popover's content, then out of it.
EscCloses the popover and returns focus to the trigger.

Guidelines

Do

Use a popover for small, optional content tied to one control: sharing, quick settings, details.

Avoid

Put a primary task or long form in a popover; use a Dialog.