Skip to main content

rc-popover

Anchored non-modal surface around a native trigger and consumer-owned content. It supplies placement, open-state control, and a Popover API fallback; content semantics and interaction remain the author's responsibility.

Package
@rcarls/rc-popover
Element
<rc-popover>
Native dependency
Consumer-owned trigger and content
State model
Controlled or uncontrolled open state
Main events
rc-popover-toggle

Installation​

npm install @rcarls/rc-webcomponents@next
import '@rcarls/rc-webcomponents/rc-popover/define';

Usage​

Keep the trigger and surface as direct children. Native popovertarget and popover make the panel operable before upgrade. Give interactive content an appropriate role and accessible name; rc-popover does not assign one.

<rc-popover placement="block-end-start">
<button slot="trigger" type="button" popovertarget="settings-panel" aria-haspopup="dialog">
Settings
</button>
<section
slot="content"
id="settings-panel"
popover
role="dialog"
aria-labelledby="settings-title"
>
<h2 id="settings-title">Display settings</h2>
<label><input type="checkbox" /> Show details</label>
</section>
</rc-popover>

A button trigger toggles by default. Set trigger-action="none" for a panel controlled by application state or by optional open-on-hover and open-on-focus. Escape closes an open panel; a click outside also closes it. Focus inside the panel stays usable, and Escape returns focus to the trigger when focus was in the panel. open is a silent controlled host property; default-open initializes uncontrolled state. User requests dispatch rc-popover-toggle with {open}.

Material rich tooltip recipe​

The Material theme styles this optional composition. Use a named non-modal dialog when the content has a link or button; a role="tooltip" must not contain focusable controls. The data-rc-material-rich-tooltip marker is a public theme opt-in. Direct h2, p, and optional footer children receive title, body, and action spacing. The author controls the action's behavior.

<rc-popover data-rc-material-rich-tooltip open-on-hover open-on-focus>
<button slot="trigger" type="button" popovertarget="feature-tip" aria-haspopup="dialog">
Feature info
</button>
<section
slot="content"
id="feature-tip"
popover
role="dialog"
aria-labelledby="feature-tip-title"
>
<h2 id="feature-tip-title">Export presets</h2>
<p>Save your export settings for next time.</p>
<footer><a href="/help/presets">Learn more</a></footer>
</section>
</rc-popover>

Keep essential instructions visible without hover. For concise, non-interactive descriptions, use rc-tooltip instead.

Live demo​

Accessibility​

The element keeps the trigger's aria-expanded and aria-controls in step with open, and restores the author's own values when it lets go of the trigger. Escape closes an open popover and returns focus to the trigger. Give the popover content its own semantics, such as a heading or a labeled dialog, when it is more than a hint.

API​

Properties​

PropertyMarkupTypeDefaultDescription
placementplacementRCPopoverPlacement'block-end-start'Preferred logical placement.
triggerActiontrigger-actionRCPopoverTriggerAction'toggle'Whether trigger activation toggles the surface.
openOnHoveropen-on-hoverbooleanfalseOpen while the pointer is over trigger or content.
openOnFocusopen-on-focusbooleanfalseOpen while focus is within trigger or content.
openopenbooleanNot specifiedControlled open state. A host write never emits `rc-popover-toggle`.
defaultOpendefault-openbooleanNot specifiedInitial open state used until the host or user changes the state.

Events​

EventDetail typeDescription
rc-popover-toggleCustomEventUser requested open-state change; detail: `{open: boolean}`.

Slots​

NameDescription
triggerDirect child native trigger, usually a `<button>`.
contentDirect child popover surface with author-owned semantics.

CSS Custom Properties​

PropertyDefaultDescription
--rc-popover-max-inline-sizemin(20rem, 100dvi - 1rem)Maximum inline size.
--rc-popover-max-block-sizecalc(100dvb - 1rem)Maximum block size.
--rc-popover-padding-block0.75remBlock padding.
--rc-popover-padding-inline0.75remInline padding.
--rc-popover-bordervar(--rc-popup-border)Surface border.
--rc-popover-radiusvar(--rc-popup-radius)Corner radius.
--rc-popover-backgroundvar(--rc-popup-background)Surface background.
--rc-popover-colorvar(--rc-popup-color)Surface text color.
--rc-popover-shadowvar(--rc-popup-shadow)Surface shadow.
--rc-popover-z-index1Fallback stacking order.

CSS Parts​

PartDescription
rootShadow wrapper for the two slots.