Tree view
Folders and files, categories, permissions. Plain nested lists: folders are native <details>, so they open and close even without JavaScript.
Files
A row is a <button>, a link, or a checkbox label. Folders are <details> with a <summary>. .tree-meta puts a note on the right.
src
components
public
<ul class="tree w-80" id="tree-files" aria-label="Files">
<li><details open><summary><i class="mi mi-folder"></i><span class="tree-label">src</span></summary><ul>
<li><details open><summary><i class="mi mi-folder"></i><span class="tree-label">components</span><span class="tree-meta">3</span></summary><ul>
<li><button type="button"><i class="mi mi-file-code"></i><span class="tree-label">button.css</span></button></li>
<li><button type="button"><i class="mi mi-file-code"></i><span class="tree-label">card.css</span></button></li>
<li><button type="button"><i class="mi mi-file-code"></i><span class="tree-label">menu.css</span></button></li>
</ul></details></li>
<li><button type="button"><i class="mi mi-file-code"></i><span class="tree-label">index.html</span></button></li>
<li><button type="button"><i class="mi mi-file-code"></i><span class="tree-label">app.js</span></button></li>
</ul></details></li>
<li><details><summary><i class="mi mi-folder"></i><span class="tree-label">public</span></summary><ul>
<li><button type="button"><i class="mi mi-image"></i><span class="tree-label">logo.svg</span></button></li>
<li><button type="button"><i class="mi mi-image"></i><span class="tree-label">favicon.ico</span></button></li>
</ul></details></li>
<li><button type="button"><i class="mi mi-file-text"></i><span class="tree-label">package.json</span></button></li>
<li><button type="button"><i class="mi mi-file-text"></i><span class="tree-label">README.md</span></button></li>
</ul>- Keyboard: Tab into the tree once, then ↑ ↓ to move, → to open a folder or step inside, ← to close it or step out, Home / End, * opens every folder at that level, and typing a name jumps to it.
- Selection: a click or Space selects a row (
aria-selected,momo:select).data-momo-select="multiple"adds Ctrl / ⌘ and Shift clicks;"none"turns it off. mi-foldericons turn intomi-folder-openby themselves. Screen readers hear a real tree: levels, open or closed, selected.
Navigation
Rows can be links: mark the current page with aria-current="page". .tree-lines draws guide lines, .tree-sm makes the rows tighter.
Getting started
Settings
<ul class="tree tree-lines tree-sm w-64" data-momo-select="none" aria-label="Guide">
<li><details open><summary>Getting started</summary><ul>
<li><a href="#tree-install">Installation</a></li>
<li><a href="#tree-start" aria-current="page">Quick start</a></li>
</ul></details></li>
<li><details open><summary>Components</summary><ul>
<li><details><summary>Forms</summary><ul>
<li><a href="#tree-input">Input</a></li>
<li><a href="#tree-select">Select</a></li>
</ul></details></li>
<li><a href="#tree-buttons">Buttons</a></li>
<li><a href="#tree-dialogs">Dialogs</a></li>
</ul></details></li>
<li><details><summary>Settings</summary><ul>
<li><a href="#tree-profile">Profile</a></li>
</ul></details></li>
</ul>Checkboxes
Rows can be checkbox labels. Checking a folder checks everything inside; a folder with only some boxes checked shows a dash. The boxes are real inputs, so the form sends what is checked.
<form class="w-80" id="tree-perm" onsubmit="event.preventDefault();Momo.toast({ title: 'Saved', text: new FormData(this).getAll('perm').length + ' permissions', color: 'green' })">
<p class="fw-bold mb-2">Role: Support</p>
<ul class="tree" aria-label="Permissions" data-momo-select="none">
<li><details open><summary><label class="check"><input type="checkbox"> Orders</label></summary><ul>
<li><label class="check"><input type="checkbox" name="perm" value="orders.view" checked> View orders</label></li>
<li><label class="check"><input type="checkbox" name="perm" value="orders.edit"> Edit orders</label></li>
<li><label class="check"><input type="checkbox" name="perm" value="orders.refund"> Refund orders</label></li>
</ul></details></li>
<li><details><summary><label class="check"><input type="checkbox"> Products</label></summary><ul>
<li><label class="check"><input type="checkbox" name="perm" value="products.view" checked> View products</label></li>
<li><label class="check"><input type="checkbox" name="perm" value="products.edit" checked> Edit products</label></li>
</ul></details></li>
<li><details><summary><label class="check"><input type="checkbox"> Settings</label></summary><ul>
<li><label class="check"><input type="checkbox" name="perm" value="settings.billing"> Billing</label></li>
<li><label class="check"><input type="checkbox" name="perm" value="settings.team"> Team</label></li>
</ul></details></li>
</ul>
<button class="btn btn-brand mt-3" type="submit">Save</button>
</form>Filter
Point any input at the tree with data-momo-filter="#id". Matches stay, with the folders around them opened; clear it and everything is back as it was. ↓ in the field jumps into the tree.
src
components
pages
docs
<div class="stack gap-3 w-80">
<input class="form-control" type="search" placeholder="Filter files" aria-label="Filter files" data-momo-filter="#tree-filter">
<ul class="tree" id="tree-filter" aria-label="Project">
<li><details open><summary><i class="mi mi-folder"></i><span class="tree-label">src</span></summary><ul>
<li><details><summary><i class="mi mi-folder"></i><span class="tree-label">components</span></summary><ul>
<li><button type="button"><i class="mi mi-file-code"></i><span class="tree-label">button.css</span></button></li>
<li><button type="button"><i class="mi mi-file-code"></i><span class="tree-label">card.css</span></button></li>
<li><button type="button"><i class="mi mi-file-code"></i><span class="tree-label">badge.css</span></button></li>
</ul></details></li>
<li><details><summary><i class="mi mi-folder"></i><span class="tree-label">pages</span></summary><ul>
<li><button type="button"><i class="mi mi-file-code"></i><span class="tree-label">home.html</span></button></li>
<li><button type="button"><i class="mi mi-file-code"></i><span class="tree-label">about.html</span></button></li>
</ul></details></li>
<li><button type="button"><i class="mi mi-file-code"></i><span class="tree-label">app.js</span></button></li>
</ul></details></li>
<li><details><summary><i class="mi mi-folder"></i><span class="tree-label">docs</span></summary><ul>
<li><button type="button"><i class="mi mi-file-text"></i><span class="tree-label">guide.md</span></button></li>
<li><button type="button"><i class="mi mi-file-text"></i><span class="tree-label">changelog.md</span></button></li>
</ul></details></li>
<li><button type="button"><i class="mi mi-file-text"></i><span class="tree-label">package.json</span></button></li>
</ul>
</div>Loading a folder when it opens
Big trees can load a folder's rows only when it is opened: listen for momo:toggle, add the rows, and Momo sets them up. .is-loading on the <details> shows a spinner meanwhile.
Portugal
Japan
<ul class="tree w-80" id="tree-lazy" aria-label="Offices">
<li><details data-id="pt"><summary><i class="mi mi-folder"></i><span class="tree-label">Portugal</span></summary><ul></ul></details></li>
<li><details data-id="jp"><summary><i class="mi mi-folder"></i><span class="tree-label">Japan</span></summary><ul></ul></details></li>
</ul>
<script>
document.getElementById('tree-lazy').addEventListener('momo:toggle', async (e) => {
const folder = e.detail.item.parentElement; // the <details>
if (!e.detail.open || folder.dataset.loaded) return;
folder.classList.add('is-loading');
await new Promise((r) => setTimeout(r, 600)); // your fetch() here
const cities = { pt: ['Lisbon', 'Porto'], jp: ['Tokyo', 'Osaka', 'Kyoto'] }[folder.dataset.id];
folder.querySelector('ul').innerHTML = cities.map((c) => `<li><button type="button"><i class="mi mi-map-pin"></i><span class="tree-label">${c}</span></button></li>`).join('');
folder.dataset.loaded = '1';
folder.classList.remove('is-loading');
});
</script>JavaScript
tree.addEventListener('momo:select', (e) => open(e.detail.item)); // e.detail.items: everything selected
tree.addEventListener('momo:toggle', (e) => console.log(e.detail.open));
Momo.tree('#files'); // set up again (rarely needed)