A disclosure widget that toggles visibility of a content panel. It animates open and close transitions using --collapsible-panel-height and --collapsible-panel-width CSS custom properties, supports hidden="until-found" for browser find-in-page, and exposes open state via events and a controller.
import { Collapsible } from "@areia/slots";document.querySelector("#root")!.innerHTML = ` <div data-slot="collapsible" class="w-72"> <button data-slot="collapsible-trigger" class="win95-button"> Toggle </button> <div data-slot="collapsible-content" class="win95-inset mt-2 p-3"> Content revealed when the trigger is activated. </div> </div>`;const root = document.querySelector( '[data-slot="collapsible"]',)!;const controller = Collapsible.createCollapsible(root, { defaultOpen: false,});
Import
import { Collapsible } from "@areia/slots";
Usage
import { Collapsible } from "@areia/slots";// Auto-bind a single rootconst root = document.querySelector( '[data-slot="collapsible"]',)!;const controller = Collapsible.createCollapsible(root, { defaultOpen: false, onOpenChange: (open) => console.log("open changed:", open),});// Auto-bind all unbound roots in scopeconst controllers = Collapsible.create();
Expected Markup
The collapsible expects a trigger button and a content panel inside the root.
<div data-slot="collapsible"> <button data-slot="collapsible-trigger">Toggle</button> <div data-slot="collapsible-content"> Content revealed when the trigger is activated. </div></div>
Data Slots
Slot
Required
Description
collapsible
Yes
Root container.
collapsible-trigger
Yes
Button that toggles the content panel.
collapsible-content
Yes
Panel whose visibility is controlled.
CSS Custom Properties
The controller sets the following CSS custom properties on the content element to enable smooth open/close animations. During transitions the values are set to the content’s pixel dimensions, and reset to auto once the transition settles.
Property
Description
--collapsible-panel-height
Pixels during open/close transition, auto when settled.
--collapsible-panel-width
Pixels during open/close transition, auto when settled.
Use these variables to animate height, width, block-size, or inline-size via CSS transitions: