Skip to main content

rc-disclosure

Disclosure wrapper for a native <details>/<summary> pair with controlled open state, following the WAI-ARIA Disclosure pattern.

Package
@rcarls/rc-disclosure
Element
<rc-disclosure>
Native dependency
Requires a native details child
State model
Controlled or uncontrolled open state
Main events
rc-disclosure-toggle

Installation​

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

Usage​

Wrap a native <details> with a <summary> as its first child.

<rc-disclosure>
<details id="shipping">
<summary>Shipping details</summary>
<p>Orders ship within two business days.</p>
</details>
</rc-disclosure>

Live demo​

Accessibility​

The browser keeps ownership of the disclosure: the <summary> is the button, Enter and Space toggle it, and its expanded state is exposed natively. The element adds aria-controls from the summary to the <details>, mirrors the open state, and opens when the URL hash matches an id inside it. See the WAI-ARIA Disclosure pattern.

Open state​

Use default-open when the disclosure should manage its own state after initialization. Use the open property or attribute when the host owns the state; user interaction then emits rc-disclosure-toggle with the requested state, and the rendered disclosure continues to follow the controlled value. Assign undefined to the JavaScript open property to release control and return to the current uncontrolled/default state.

The required direct child <details> remains connected and owns the native disclosure interaction, keyboard behavior, and accessibility semantics.

Theming​

The default demo mode shows the component without a package theme. Use the shared preview controls on this page to compare inherited, light, and dark color schemes or to apply the optional Material theme only inside the demo frames.

API​

Properties​

PropertyMarkupTypeDefaultDescription
openJS property onlybooleanNot specifiedCurrent open state. Host writes are silent; assign `undefined` to release control.
defaultOpenJS property onlybooleanNot specifiedInitial open state for uncontrolled usage.

Events​

EventDetail typeDescription
rc-disclosure-toggleCustomEventFires when the child `<details>` toggles.

CSS Custom Properties​

PropertyDefaultDescription
--rc-disclosure-border0Panel border.
--rc-disclosure-radius0Panel corner radius.
--rc-disclosure-backgroundtransparentPanel background while closed.
--rc-disclosure-colorinheritPanel foreground.
--rc-disclosure-open-backgroundNot specifiedPanel background while open. Defers to `--rc-disclosure-background` when unset.
--rc-disclosure-open-shadownonePanel shadow while open.
--rc-disclosure-summary-min-block-size0Summary minimum block size. Set this to at least `3rem` for a comfortable touch target.
--rc-disclosure-summary-padding-block0Summary block padding.
--rc-disclosure-summary-padding-inline0Summary inline padding.
--rc-disclosure-summary-gap0Summary gap, for a theme that lays the summary out as a grid or flex container.
--rc-disclosure-summary-colorinheritSummary foreground.
--rc-disclosure-summary-fontinheritSummary font shorthand.
--rc-disclosure-summary-marker-colorcurrentColorNative disclosure marker color. A theme that replaces the marker with its own affordance should hide `::marker` itself.
--rc-disclosure-summary-hover-backgroundtransparentSummary hover background.
--rc-disclosure-focus-ringvar(--rc-focus-ring, 2px solid Highlight)Summary focus-visible outline.
--rc-disclosure-focus-ring-offset0Summary focus-visible outline offset.
--rc-disclosure-content-padding-block0Content block padding.
--rc-disclosure-content-padding-inline0Content inline padding.
--rc-disclosure-content-colorinheritContent foreground.
--rc-disclosure-content-fontinheritContent font shorthand.
--rc-disclosure-duration0msOpen and close transition duration. Zero by default, so the panel snaps the way the platform does until a theme opts into motion. The animation runs on `::details-content` where that is supported and is skipped entirely where it is not.
--rc-disclosure-easingeaseOpen and close transition easing.