Liking cljdoc? Tell your friends :D

x-popover

A floating overlay panel anchored to an inline slotted trigger element. The trigger is any element placed in the trigger slot. The panel has a structured header (optional heading + close button), a default body slot, and an optional footer slot with an arrow indicator pointing toward the trigger.

Tag name

<x-popover>…</x-popover>

Observed attributes

AttributeTypeDefaultDescription
openbooleanfalseVisible state of the panel
placementenumbottom-startPanel position relative to trigger
headingstring""Visible heading text in the panel header
close-labelstring"Close"Accessible label for the close button
no-closebooleanfalseHide the close button
disabledbooleanfalsePrevent opening/closing

Placement values

bottom-start · bottom-end · top-start · top-end

Properties (camelCase, reflect attributes)

PropertyTypeReflected attribute
openbooleanopen
placementstringplacement
headingstringheading
closeLabelstringclose-label
noClosebooleanno-close
disabledbooleandisabled

Public methods

MethodDescription
show()Open the panel (source: "programmatic"); no-op if already open
hide()Close the panel (source: "programmatic"); no-op if already closed
toggle()Toggle open/close (source: "programmatic")

Events

x-popover-toggle

Fired before the open state changes. Cancelable — call event.preventDefault() to abort.

PropertyTypeDescription
detail.openbooleanThe state the panel is about to transition to
detail.sourcestringWhat triggered the change

Source values: "pointer" · "programmatic" · "outside-click" · "escape" · "focusout" · "close-button"

x-popover-change

Fired after the open state has changed. Not cancelable.

PropertyTypeDescription
detail.openbooleanThe new open state

Slots

SlotDescription
triggerThe trigger element. Click toggles the panel. Any focusable element is valid.
(default)Main body content of the panel.
footerOptional footer content. The footer is hidden via CSS when empty.

Shadow parts

PartElement
trigger<span> wrapping the trigger slot
panelThe floating panel <div>
arrowThe directional arrow indicator
headerThe panel header row
headingThe heading <span>
close-buttonThe close <button>
bodyThe body <div> wrapping the default slot
footerThe footer <div> wrapping the footer slot

CSS custom properties

Panel

PropertyDefaultDescription
--x-popover-panel-bg#ffffffPanel background
--x-popover-panel-border1px solid #e2e8f0Panel border
--x-popover-panel-radius8pxPanel border radius
--x-popover-panel-shadow0 4px 16px rgba(0,0,0,0.12)Panel box shadow
--x-popover-panel-min-width12remMinimum panel width
--x-popover-panel-max-width24remMaximum panel width
--x-popover-panel-max-height24remMaximum panel height (scrollable)
--x-popover-panel-offset4pxGap between trigger and arrow
--x-popover-panel-z1000z-index

Header

PropertyDefaultDescription
--x-popover-header-padding0.625rem 0.75rem 0.625rem 0.875remHeader padding
--x-popover-header-border1px solid #e2e8f0Header bottom border

Heading

PropertyDefaultDescription
--x-popover-heading-color#0f172aHeading text color
--x-popover-heading-font-size0.9375remHeading font size
--x-popover-heading-font-weight600Heading font weight

Close button

PropertyDefaultDescription
--x-popover-close-bgtransparentClose button background
--x-popover-close-bg-hover#f1f5f9Close button background on hover
--x-popover-close-color#64748bClose button icon color
--x-popover-close-color-hover#0f172aClose button icon color on hover
--x-popover-close-radius4pxClose button border radius
--x-popover-close-size1.5remClose button width and height
--x-popover-focus-ring#60a5faFocus ring color

Body

PropertyDefaultDescription
--x-popover-body-padding0.875remBody padding
--x-popover-body-color#334155Body text color
--x-popover-body-font-size0.9375remBody font size

Footer

PropertyDefaultDescription
--x-popover-footer-padding0.625rem 0.875remFooter padding
--x-popover-footer-border1px solid #e2e8f0Footer top border

Arrow

PropertyDefaultDescription
--x-popover-arrow-size8pxArrow square size
--x-popover-arrow-bg#ffffffArrow background (should match panel bg)
--x-popover-arrow-border#e2e8f0Arrow border color (should match panel border)

Animation

PropertyDefaultDescription
--x-popover-transition-duration150msOpen/close transition duration
--x-popover-transition-easingeaseOpen/close transition easing

Accessibility

  • The panel has role="dialog" and aria-hidden toggled between "true" (closed) and "false" (open).
  • When heading is non-empty, aria-labelledby="popover-heading" is set on the panel.
  • The close button has aria-label set to the close-label attribute value (default "Close").
  • Escape closes the panel when it is open.
  • Focus leaving the host (focusout) closes the panel.
  • The arrow is aria-hidden="true".

Dark mode

All color custom properties respond to @media (prefers-color-scheme: dark) via default values defined in :host. Override these defaults to customize dark theme.

Reduced motion

When @media (prefers-reduced-motion: reduce) is active, panel and close button transitions are disabled (transition: none !important).

Usage examples

Basic usage

<x-popover heading="Details">
  <button slot="trigger">Open</button>
  <p>This is the popover body content.</p>
</x-popover>

With footer slot

<x-popover heading="Confirm action">
  <button slot="trigger">Delete item</button>
  <p>This action cannot be undone.</p>
  <div slot="footer">
    <button>Cancel</button>
    <button>Confirm</button>
  </div>
</x-popover>

Without close button

<x-popover heading="Info" no-close>
  <button slot="trigger">?</button>
  <p>Some informational content.</p>
</x-popover>

Custom close label

<x-popover heading="Settings" close-label="Dismiss settings">
  <button slot="trigger">⚙</button>
  <p>Settings content here.</p>
</x-popover>

Placement variants

<x-popover placement="top-start">…</x-popover>
<x-popover placement="top-end">…</x-popover>
<x-popover placement="bottom-start">…</x-popover>
<x-popover placement="bottom-end">…</x-popover>

Programmatic control

const el = document.querySelector('x-popover');
el.show();
el.hide();
el.toggle();

Preventing toggle

el.addEventListener('x-popover-toggle', e => {
  if (!confirmed) e.preventDefault();
});

Custom theme

<x-popover
  style="
    --x-popover-panel-bg: #1e1b4b;
    --x-popover-panel-border: 1px solid #4338ca;
    --x-popover-heading-color: #e0e7ff;
    --x-popover-body-color: #c7d2fe;
    --x-popover-arrow-bg: #1e1b4b;
    --x-popover-arrow-border: #4338ca;
    --x-popover-close-color: #818cf8;
    --x-popover-close-bg-hover: rgba(255,255,255,0.08);
  "
  heading="Custom theme"
>
  <button slot="trigger">Open</button>
  <p>Themed popover content.</p>
</x-popover>

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close