@akhatmirzo/ui

Popover

A floating panel for interactive content — filters, small forms and settings.

Filtr qo'llanmagan

Import

import { Popover } from '@akhatmirzo/ui';

When to use

  • Small interactive content — a price filter, a color picker, a couple of settings. The page stays usable and the panel opens next to its trigger.
  • Text-only hints are a job for Tooltip. A Popover opens on click and can hold buttons and fields.
  • A list of commands ("Edit", "Delete") belongs in a DropdownMenu, which comes with menu roles and keyboard navigation.
  • Large forms or tasks that need full attention — use a Dialog.

Anatomy

PartWhat it does
PopoverState: open, defaultOpen, onOpenChange
Popover.TriggerOpens the panel (use with asChild)
Popover.ContentThe panel: portal, positioning, animation, optional arrow
Popover.CloseCloses the panel when clicked (use with asChild)
Popover.AnchorPositions the panel against another element than the trigger
<Popover>
  <Popover.Trigger asChild>
    <Button>Price</Button>
  </Popover.Trigger>
  <Popover.Content align="start" aria-label="Price filter">
    {/* form */}
  </Popover.Content>
</Popover>

The panel is 288px wide by default (w-72). Pass a className such as w-56 or w-auto to change it.

Placement and arrow

side is top, right, bottom (default) or left; align is start, center (default) or end. The panel sits 6px from the trigger and flips to the opposite side when it hits the edge of the screen. arrow draws an arrow pointing at the trigger.

Settings panel

An icon button with a few Switch controls — a typical small settings panel. When it opens, focus moves to the first element inside.

Close on pick

Anything wrapped in Popover.Close asChild closes the panel when clicked — handy for color or option pickers. In controlled mode (open + onOpenChange) you can also close it from code, which is how the form in the first example works.

Inside a dialog

A Popover inside a Dialog or Drawer moves to the modal layer and opens above it — no extra setup.

Props

Popover

Accepts the props of the Radix Popover Root.

PropTypeDefaultDescription
openboolean—Whether it is open (controlled)
defaultOpenboolean—Open on first render
onOpenChange(open: boolean) => void—Called when it opens or closes
modalbooleanfalsetrue — blocks interaction with the rest of the page

Popover.Content

Also accepts the rest of the Radix Popover.Content props (onOpenAutoFocus, onEscapeKeyDown, alignOffset, avoidCollisions ...), <div> attributes and ref.

PropTypeDefaultDescription
side'top' | 'right' | 'bottom' | 'left''bottom'Preferred side
align'start' | 'center' | 'end''center'Alignment along the trigger
sideOffsetnumber6Gap to the trigger, px
collisionPaddingnumber8Minimum distance from the screen edge, px
arrowbooleanfalseArrow pointing at the trigger
containerHTMLElement | null—Portal container (defaults to document.body)

Popover.Trigger, Popover.Close, Popover.Anchor

All three accept asChild. With a Popover.Anchor, the panel is positioned against that element instead of the trigger (a whole table row, for example).

Data attributes

AttributeOnValue
data-statetrigger, panelopen · closed
data-sidepaneltop · right · bottom · left
data-alignpanelstart · center · end

Keyboard

KeyAction
Enter / SpaceOpens or closes the panel from the trigger
TabMoves between elements inside the panel
EscCloses the panel; focus returns to the trigger

The panel also closes when focus leaves it or the user clicks outside.

Accessibility

  • Wiring. The trigger gets aria-haspopup="dialog", aria-expanded and aria-controls; the panel is role="dialog". Give the panel an aria-label (for example "Price filter") so screen readers announce it by name.
  • Focus. On open, focus moves to the first element inside the panel; on close, it returns to the trigger.
  • Icon-only triggers need an aria-label on the IconButton.
  • The arrow is purely decorative.

On this page