Component

<dom-popover>

custom element

Floating panel anchored to a trigger. Built on the native HTML Popover API — top layer, light-dismiss and Esc are handled by the browser.

Demo

Floating panel

Built on the native Popover API — top layer, light-dismiss, and Esc to close.

basic.htmlhtml
<dom-popover>
	<button
		slot="trigger"
		type="button"
		class="inline-flex h-10 items-center rounded-full bg-secondary px-4 text-sm font-medium text-fg ring-1 ring-border hover:bg-accent"
	>
		More
	</button>
	<div slot="panel" class="max-w-xs rounded-2xl border border-border bg-background p-4 text-sm text-muted-fg shadow-lg">
		<p class="font-semibold text-fg">Quick facts</p>
		<p class="mt-2">Anything you like — text, buttons, even forms.</p>
	</div>
</dom-popover>

<script type="module">
	import '@getdom/studio/headless/popover.js';
</script>

Usage

Plain HTML

<dom-popover>
  <button slot="trigger">More</button>
  <div slot="panel">
    <p>Anything you like — text, buttons, even forms.</p>
  </div>
</dom-popover>

Register every <dom-*> in one import: import '@getdom/studio/headless'.

Slots

NameScopeDescription
#triggerElement that toggles the panel when clicked.
#panelPanel content. Gets popover="auto" applied automatically.

Attributes

NameTypeDescription
openbooleanReflects open state.
placement'top' | 'right' | 'bottom' | 'left' | '<side>-<align>'Preferred placement before collision handling (default bottom).
align'left' | 'right' | 'center'Horizontal alignment under the trigger (default left).
offsetnumberGap in pixels between trigger and panel (default 8).
collision-paddingnumberViewport padding used when flipping or shifting the panel (default 8).
floating-mode'viewport' | 'anchor'viewport keeps the panel inside the browser; anchor keeps it attached to the trigger while scrolling.
flipbooleanAllow the panel to flip to the opposite side when it would collide with the viewport.
lock-scrollbooleanLock document scrolling while the panel is open.
trigger'click' | 'hover' | 'hover-click'How the trigger opens the panel. hover-click opens on hover and pins open on click.
hover-close-delaynumberDelay before closing a hover-triggered panel after pointer/focus leaves.
data-trigger-idstringId of an external trigger element.
data-panel-idstringId of an external (teleported) panel element.

From dom-popover.__doc.attributes.

Events

NamePayloadDescription
dom:openFired when the panel opens.
dom:closeFired when the panel closes.

Names auto-detected from defineEmits and source emit() calls; payload and description from __doc.events when present.

Keyboard

  • Click triggerToggles the panel.
  • Click outsideLight-dismiss via the native popover API.
  • EscCloses the panel.

Related

See also

← Headless overview