Skip to content
v0.9.1
Components

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
    • components3
  • 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>

Navigation

Rows can be links: mark the current page with aria-current="page". .tree-lines draws guide lines, .tree-sm makes the rows tighter.

<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.

Role: Support

<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)

      Start

      OverviewStart Getting startedStart CustomizeStart

      Guides

      AccessibilityGuides BreakpointsGuides ChangelogGuides Customize componentsGuides JavaScriptGuides MotionGuides OptimizeGuides PhonesGuides RebootGuides Right-to-left (RTL)Guides Stacking orderGuides Using Momo with AIGuides

      Foundations

      ColorsFoundations TypographyFoundations ProseFoundations Images & figuresFoundations CodeFoundations Lines & shadowsFoundations Dark modeFoundations

      Forms

      Checkbox & switchForms ComboboxForms Date pickerForms Date rangeForms Fields & labelsForms File uploadForms Floating labelsForms Number stepperForms PasswordForms PIN codeForms RatingForms SelectForms SliderForms Tag inputForms Time pickerForms ValidationForms

      Components

      AccordionComponents Alert & bannerComponents AvatarComponents BadgeComponents BreadcrumbComponents ButtonComponents Button groupComponents CalendarComponents CardComponents CarouselComponents ChartsComponents ChipsComponents CollapseComponents Command paletteComponents CommentsComponents Confirm dialogsComponents Cookie bannerComponents Data tableComponents Description listComponents Dialog & toastComponents DividerComponents DrawerComponents Dropdown menuComponents Empty stateComponents File managerComponents Filter & sortComponents Gallery & lightboxComponents Inbox & chatComponents Infinite scrollComponents KanbanComponents Keyboard shortcutsComponents List groupComponents MarqueeComponents Media objectComponents Nav overflowComponents Notification centerComponents PaginationComponents ProgressComponents Pull to refreshComponents SkeletonComponents SortableComponents SpinnerComponents Split viewComponents Stat cardComponents Steps & wizardComponents Swipe actionsComponents TableComponents TabsComponents TimelineComponents TogglerComponents Tooltip & popoverComponents TourComponents Tree viewComponents VideoComponents WhiteboardComponents

      Layout

      Announcement barLayout App shellLayout Back to topLayout Container & sectionLayout ExamplesLayout FooterLayout HeroLayout JumbotronLayout Mega menuLayout NavbarLayout Site sidebarLayout

      Sections

      Bento gridSections Blog cardsSections Call to actionSections Contact & newsletterSections FAQSections FeaturesSections Logo cloudSections PricingSections TeamSections TestimonialsSections

      Utilities

      OverviewUtilities State variantsUtilities Display & flexUtilities Grid & gapUtilities SpacingUtilities SizingUtilities TextUtilities Links & color strengthUtilities Position & overflowUtilities BackgroundsUtilities Borders & effectsUtilities Transforms & filtersUtilities InteractionsUtilities

      Helpers

      Fixed, sticky & frostedHelpers Hover & focusHelpers Hover revealHelpers Icon linkHelpers PrintHelpers Relative timeHelpers Screen reader textHelpers Scroll inHelpers ScrollspyHelpers Share buttonHelpers Skip linkHelpers StacksHelpers Stretched linkHelpers Theme toggleHelpers Truncated textHelpers

      Page patterns

      404 pagePage patterns Coming soonPage patterns Login & registerPage patterns SettingsPage patterns ProfilePage patterns CRM contactsPage patterns ProjectsPage patterns File manager pagePage patterns Billing & plansPage patterns Help centerPage patterns Mobile app screensPage patterns
      ↑ ↓ moveEnter openEsc close