Skip to main content
PimentCSS v1.0.1, what's new
Home

Tree

Expandable tree groups with toggle buttons and nested items.

Styles live in scss/components/_tree.scss. A tree is a nested <ul class="tree"> with role="tree", expandable folders, and file rows. The component is narrow by default (150px); widen it in your layout when labels are longer.

Expand/collapse toggle

.tree__toggle is a 24px round control with a 16px chevron. Add .tree__toggle--open to rotate the arrow. Use aria-expanded and aria-controls on the button, and toggle the hidden attribute on the matching .tree__group.

Closed
Open
Hover / closed
Hover / open

Level 1 row states

Each row is a flex line: toggle + .tree__content (16px icon in a 20px slot + label). Selected rows use .tree__row--selected and aria-current="true" on the label button.

Default
Hover
Focus
Unselected
Selected

Levels 2 and 3 (live)

.tree__row--level-2 indents folders. Files at level 3 use .tree__row--level-3 and a .tree__toggle-spacer so the label aligns with folder rows. This mini tree is interactive (data-tree-live).

Click the chevrons to expand/collapse, and a row label to select it.

File type icons

PimentCSS does not ship icons. In this doc we use Phosphor (ph-image, ph-file-pdf, etc.): pick one glyph per media type and reuse it for every matching extension.

Extensions (examples)Library iconUsage
.png, .jpg, .webpph-image Raster image
.mp4, .movph-video Video
.pdfph-file-pdf PDF / document
.txt, .mdph-file-text Plain text
.zip, archivesph-file-zip Bundle
Foldersph-folder Directory

File tree (interactive)

Example with folders and mixed files. Chevrons expand branches; clicking a name selects that row. Production apps should add keyboard support per the ARIA treeview pattern.

JavaScript

Class reference

ClassDescription
.treeRoot list (column, max-width 150px by default)
.tree__groupNested ul for children
.tree__rowHorizontal row (toggle + content)
.tree__row--level-216px left inset for nested folders
.tree__row--level-316px inset + .tree__toggle-spacer (aligns with folder row)
.tree__toggle-spacerEmpty slot when a row has no toggle (files)
.tree__row--selectedSelected row
.tree__toggle24px expand/collapse control
.tree__toggle--openChevron rotated 90°
.tree__contentLabel button (icon + text)
.tree__icon20px slot, 16px icon
.tree__labelTruncated label text

Customize (Sass)

  1. Tree spacing

    Adjust indentation and icon sizes. Override max-width on .tree in your app if filenames are long.
    @use "pimentcss-design-system" with (
      $tree-level-2-pl: 1rem,
      $tree-level-3-pl: 1rem,
      $tree-icon-size: 1.25rem
    );
  2. Rebuild CSS

    Run after editing _tree.scss.
    npm run build:css

Accessibility (RGAA / WCAG)

Tree widget

  • Roles, root role="tree", items role="treeitem", child lists role="group".
  • Expand, set aria-expanded on the toggle and matching treeitem; hide collapsed groups with the hidden attribute.
  • Controls, link toggle to its group with aria-controls + stable id on .tree__group.
  • Selection, expose the current node with aria-current="true" on .tree__content (single-select side nav).
  • Keyboard, for production apps follow the ARIA treeview pattern (arrows, Home/End); the doc demo uses pointer interaction only.

Next steps