Collapse
Show and hide any block with a button, with a smooth slide: a filter panel, extra details, "Read more" on a long text. For a list of questions, the accordion is simpler.
Collapse
A button with data-momo-collapse="#id" opens and closes .collapse#id. It keeps aria-expanded up to date, and the button's words can change with .when-closed / .when-open.
<button class="btn" type="button" data-momo-collapse="#filters-demo"><i class="mi mi-filter" aria-hidden="true"></i> <span class="when-closed">Show filters</span><span class="when-open">Hide filters</span> <i class="mi mi-chevron-down collapse-caret" aria-hidden="true"></i></button>
<div class="collapse" id="filters-demo">
<div class="box p-4 mt-3 grid sm:grid-cols-3 gap-4">
<label class="check"><input type="checkbox" checked> In stock</label>
<label class="check"><input type="checkbox"> On sale</label>
<label class="check"><input type="checkbox"> Free delivery</label>
</div>
</div>Read more
.collapse-peek shows the first lines, fading out, until opened (--collapse-min, 96px).
Momo started as a weekend experiment: what if a design kit looked like a printed poster, with thick black lines and flat colors, instead of soft shadows and gradients?
The first version had six components. People liked how readable it was on a phone in the sun, so it grew: tables, a calendar, a kanban board, then everything a website needs.
Every piece is tested with a real keyboard, a screen reader and a phone before it ships, and none of it needs a build step.
<div class="collapse collapse-peek prose" id="story-demo">
<p>Momo started as a weekend experiment: what if a design kit looked like a printed poster, with thick black lines and flat colors, instead of soft shadows and gradients?</p>
<p>The first version had six components. People liked how readable it was on a phone in the sun, so it grew: tables, a calendar, a kanban board, then everything a website needs.</p>
<p>Every piece is tested with a real keyboard, a screen reader and a phone before it ships, and none of it needs a build step.</p>
</div>
<button class="btn btn-sm btn-ghost mt-2" type="button" data-momo-collapse="#story-demo"><span class="when-closed">Read more</span><span class="when-open">Read less</span> <i class="mi mi-chevron-down collapse-caret" aria-hidden="true"></i></button>Sideways
.collapse-x opens to the side: a filter column, a side note. --collapse-width sets how wide it opens (18rem).
The list makes room when the filters open, and takes it back when they close.
<button class="btn btn-sm mb-3" type="button" data-momo-collapse="#cl-side" id="cl-side-btn"><i class="mi mi-sliders-horizontal"></i> Filters</button>
<div class="flex items-stretch">
<div class="collapse collapse-x" id="cl-side" style="--collapse-width: 14rem">
<div class="card" style="height: 100%; margin-inline-end: 1rem"><div class="card-body"><div class="check-group">
<b>Status</b>
<label class="check"><input type="checkbox" checked> Paid</label>
<label class="check"><input type="checkbox"> Unpaid</label>
<label class="check"><input type="checkbox"> Refunded</label>
</div></div></div>
</div>
<div class="card flex-1 min-w-0"><div class="card-body"><b>48 orders</b><p class="text-muted mb-0">The list makes room when the filters open, and takes it back when they close.</p></div></div>
</div>Classes and attributes
| Class / attribute | Does |
|---|---|
.collapse | The block that opens and closes (closed at start; add .is-open to start open) |
data-momo-collapse="#id" | On a button: opens / closes that block |
.collapse-peek | Closed means "only the first lines", not hidden |
.when-closed / .when-open | Inside the button: words for each state |
.collapse-caret | An icon that turns over when open |
From script: Momo.collapse.open('#id'), .close(), .toggle(); a momo:collapse event fires with detail.open.
Accessibility
- The button says whether the block is open (
aria-expanded) and which block it controls. - A closed block is hidden from screen readers and the keyboard; a "peek" block stays readable.
- Without JavaScript the block is simply open, so nothing is ever lost.