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

x-popover

A popup whose panel renders in the browser's top layer while open, escaping clipped ancestors, with a focus trap built in.

A popup whose panel renders in the browser's top layer while open, escaping clipped ancestors, with a focus trap built in.

Directive / magic
What it does

x-popover

The root. Modifiers and expression pass to x-popup

x-popover:button

The button that toggles the panel

x-popover:panel

The floating panel. Modifiers are x-float positioning modifiers (default absolute.bottom.offset.5px.flip.update.shift.fit-x.pad.5px)

x-popover:panel.notrap

Disables the focus trap

x-popover:panel.nofloat

Disables floating; position the panel yourself

x-popover:arrow

The arrow element, inside the panel

$popover

isOpen (get/set), open(), close()

While open, the panel gets popover="manual" and uses the native Popover API. This puts it in the top layer above overflow: hidden ancestors, z-index stacks, and transformed parents. Focus stays in the panel until it closes. .notrap skips the focus trap and doesn't return focus to the button. Escape and outside clicks close the panel. x-popup supplies aria-expanded and aria-controls.

A .nofloat panel shows in the same task as the click that opens it, so the Popover API focuses the panel's autofocus field while the browser still treats the click as the user's. A reopen during the close focuses that field the same way. On an iPhone or iPad the field keeps inputmode="none" until the enter animation ends, since iOS stops the page's frames while the keyboard slides in, so the keyboard follows the animation. A floating panel waits for its position, and the focus trap focuses it after its animation.

Examples

A basic popover

Use x-popover:button and x-popover:panel to toggle a top-layer panel:

<div x-popover>
  <button x-popover:button>Search</button>
  <div x-popover:panel x-cloak class="bg-canvas text-content shadow">
    …
  </div>
</div>

The header search flyout uses this structure to escape the header's overflow clipping.

Positioning the panel

Pass x-float modifiers on x-popover:panel to pick the side and offset:

Passing any modifier replaces the whole default string, so bring back flip, shift, and friends when you still want them. The full modifier list lives on the x-float page.

A full-width flyout

Use the nofloat modifier to position the panel yourself:

Predictive search uses nofloat because the panel spans the viewport and is pinned to the top of the screen. It still uses the top layer and focus trap. Its input carries autofocus, so the field takes focus on the tap that opens the panel.

An arrow

Use x-popover:arrow inside the panel to point at the button:

Options

The expression passes through to x-popup, so an isOpen get/set pair can bind the panel to outside state. See x-popup for the pattern and auto-close modifiers. Use x-popup directly when top-layer stacking and the focus trap are not needed: a hover tooltip like core-popover stays a plain popup so focus never moves into it.

Last updated

Was this helpful?