Interactive
Tree with checkboxes
With data-m-tree-checkbox every item gets a tristate checkbox: checking a branch checks everything below it, and a branch with some checked children shows as mixed. Space or Enter toggles. Needs monsoon.js.
Needs monsoon.js. The styles work on their own, and the behavior comes from the optional interactive layer: add <script src="https://cdn.jsdelivr.net/npm/monsooncss/dist/monsoon.js" defer></script> or import 'monsooncss/js'. See the interactive layer.
Example
<ul class="tree max-w-xs" data-m-tree data-m-tree-checkbox aria-label="Notifications">
<li data-open>Email
<ul>
<li data-checked data-value="email-mentions">Mentions</li>
<li data-checked data-value="email-replies">Replies</li>
<li data-value="email-digest">Weekly digest</li>
</ul>
</li>
<li data-open>Push
<ul>
<li data-checked data-value="push-mentions">Mentions</li>
<li data-checked data-value="push-reminders">Reminders</li>
</ul>
</li>
<li data-value="sms">Text messages</li>
</ul>JavaScript API
Attribute
data-m-tree data-m-tree-checkbox
Options
| Option | Description |
|---|---|
data-checked on a leaf starts it checked |
Methods
| Method | Description |
|---|---|
Monsoon.tree(el).checked (values of the checked leaves) |
Events
| Event | Description |
|---|---|
monsoon:tree-check { item, checked } |
Classes
2 classes. Click a name to copy it. Utilities on the same element always win over component defaults, so any of them can be adjusted with plain utility classes.
| Class | Type | What it does |
|---|---|---|
| Base | Base class of the tree with checkboxes. On an <ul> in the example. Sets margin, padding, text size, border, hidden by default and font weight, and --tone and --tone-fg.CSS |
|
| Modifier | Modifier, combined with the tree class. Not used in the example above. Sets grid display, alignment, width, height, text color and background.CSS |
Usage
The styles ship inside the same stylesheet as the utilities, and the behavior comes from the optional monsoon.js script, which enhances any element with a matching data-m attribute, including markup added later.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/monsooncss">
<script src="https://cdn.jsdelivr.net/npm/monsooncss/dist/monsoon.js" defer></script>
<!-- Tree with checkboxes: start from the base class, then add modifiers -->
<ul class="tree max-w-xs" data-m-tree data-m-tree-checkbox aria-label="Notifications">
<li data-open>Email
<ul>
<li data-checked data-value="email-mentions">Mentions</li>
<li data-checked data-value="email-replies">Replies</li>
<li data-value="email-digest">Weekly digest</li>
</ul>
</li>
<li data-open>Push
<ul>
<li data-checked data-value="push-mentions">Mentions</li>
<li data-checked data-value="push-reminders">Reminders</li>
</ul>
</li>
<!-- the full example is in the Code tab above -->Theme it with --seed on any ancestor, for example style="--seed: #0d9488", and force a scheme with class="dark" or class="light" on a wrapper.
Accessibility
- Every interactive part shows a visible focus ring with
:focus-visible, and tone colors pair with-foregroundtokens that keep text at 4.5:1 or better in light and dark mode.