Skip to main content

Popper

Floating element positioning engine used by Popover, Tooltip, and Menu.

import * as Popper from '@gentleduck/primitives/popper'
import * as Popper from '@gentleduck/primitives/popper'

Anatomy

<Popper.Root>
  <Popper.Anchor />
  <Popper.Content side="bottom" sideOffset={5} align="center">
    <Popper.Arrow />
  </Popper.Content>
</Popper.Root>
<Popper.Root>
  <Popper.Anchor />
  <Popper.Content side="bottom" sideOffset={5} align="center">
    <Popper.Arrow />
  </Popper.Content>
</Popper.Root>

API

Popper.Root

Context provider that connects anchor and content.

Popper.Anchor

The reference element that content is positioned relative to.

PropTypeDefaultDescription
virtualRefReact.RefObject<Measurable>--Position relative to a virtual element instead of a DOM node

Popper.Content

The floating content. Positioned relative to the anchor.

PropTypeDefaultDescription
side'top' | 'right' | 'bottom' | 'left''bottom'Preferred side relative to anchor
sideOffsetnumber0Gap between content and anchor (px)
align'start' | 'center' | 'end''center'Alignment along the side
alignOffsetnumber0Alignment offset (px)
arrowPaddingnumber0Minimum padding between arrow and content edges (px)
avoidCollisionsbooleantrueFlip to avoid viewport edges
collisionBoundaryElement | Element[]--Custom collision boundary
collisionPaddingnumber | Padding0Padding from collision boundary
sticky'partial' | 'always''partial'Keep content in view when anchor is partially hidden
hideWhenDetachedbooleanfalseHide content when anchor is fully occluded
updatePositionStrategy'optimized' | 'always''optimized'Strategy for position recalculation
onPlaced() => void--Called when content has been positioned

Popper.Arrow

Visual arrow pointing toward the anchor. Rendered as an SVG.

How it works