For the complete documentation index, see llms.txt. This page is also available as Markdown.

x-popup

Directives and a magic for small overlays that open next to a target element.

Directives and a magic for small overlays that open next to a target element.

Directive / magic
What it does

x-popup

The root. Uses x-disclosure for its open state

x-popup.open

Starts the popup open. Same as isOpen: true

x-popup.noanimate

Skips waiting for CSS animations on open and close

x-popup.noreturn

Leaves focus where it is when Escape closes the popup

x-popup.noclose

Disables auto-close: Escape, click outside, focus outside

x-popup="{ isOpen: false }"

Options object, or a bare boolean. isOpen accepts a get/set pair

x-popup:popup

The panel. Modifiers are x-float positioning modifiers (default bottom.auto)

x-popup:popup.nofloat

Disables floating; position the panel yourself

x-popup:target

The element the panel floats next to (aria-expanded, aria-controls)

x-popup:button

Toggles the popup on click; also acts as the target (aria-haspopup)

x-popup:float-reference

Optional: float next to this element instead of the target

x-popup:arrow

The arrow element

$popup

isOpen (get/set), open(), close(), targetEl, popupEl, floatReferenceEl, plus everything on $float

While the popup is open, Escape closes it and returns focus to the target (.noreturn skips the return), and a click or focus that lands outside the popup and its target closes it (.noclose disables all three). The target announces its expanded state and what it controls, and the panel is labelled by the button.

Examples

A basic popup

Use x-popup:button and x-popup:popup to toggle a floating panel:

The share block uses this shape as its fallback when the device has no native share sheet. Give the panel x-cloak so it stays hidden until Alpine starts.

Positioning the panel

Pass x-float modifiers on x-popup:popup to pick the side, offset, and overflow behavior:

The core-popover snippet builds its modifier string this way from its position and offset parameters. The full modifier list lives on the x-float page.

An arrow

Use x-popup:arrow inside the panel to point at the target:

The float system positions the arrow on the side facing the target. core-popover uses a rotated square clipped to a triangle.

Floating next to a different element

Use x-popup:float-reference to position against an element other than the trigger:

The share block does this to size its panel to the block's full width while the trigger stays a small button. The target keeps the ARIA wiring; only the geometry moves.

Driving the popup from outside

Use a get/set pair for isOpen to bind the popup to your own state:

Hotspot tooltips use this binding because hovering or tapping the dot changes the state directly. Anything inside the root can also call $popup.open() and $popup.close().

Options

Option
What it does

isOpen

Whether the popup is open (default false). Accepts a get/set pair for two-way binding

Positioning modifiers on x-popup:popup pass to x-float. The open state is an x-disclosure. Use x-popover for the browser's top layer and focus trap. Use x-menu or x-select for menus and form controls.

Last updated

Was this helpful?