Skip to content

Accordion

Collapsible sections with optional anchor copy-link.

Accordions collapse/expand client-side. Giving an item an id adds a copy-link button that copies #<id> to the clipboard.

accordions()

No React, no runtime dependencies — builders return HTML strings and one small vanilla runtime wires the hooks.

Everything is namespaced: cpd- classes, --cpd-* variables and data-cpd-* hooks.

accordions([
{ title: 'Why pure TypeScript?', content: '<p>No React, no runtime dependencies.</p>' },
{ title: 'How do styles stay isolated?', content: '<p>Everything is namespaced.</p>' },
]);
defaultOpen + id

This one starts expanded and exposes a copy-link anchor.

accordion(
{ title: 'Single accordion, open', content: '<p>This one starts expanded.</p>', id: 'open-acc', defaultOpen: true },
);
OptionTypeDefaultDescription
titlestringAccordion header (required).
contentstring''Collapsible body (HTML allowed).
idstringAnchor id; also enables the copy-link button.
defaultOpenbooleanfalseStart expanded.
  • accordions(items) wraps a list of AccordionOptions in a data-cpd-accordions container; accordion(options) builds a single item.
  • The aria-expanded attribute is set server-side from defaultOpen, then maintained by the runtime.