Tree

Material Design 3-styled hierarchical tree web components (lit-material-tree, lit-material-tree-item).

  • 3.4 KB gzipped
  • @lit-material/tree 0.1.1
  • Renders on the server

Example

Install

npm install @lit-material/tree @lit-material/tokens
import "@lit-material/tree";

Link @lit-material/tokens/css/index.css once per page for the colour, type and shape tokens. Install guide

API

<lit-material-tree-item>

A single node in a lit-material-tree — a row (chevron if it has children, optional leading icon, label) plus a role="group" container for nested lit-material-tree-item children, following the WAI-ARIA [Tree View](https://www.w3.org/WAI/ARIA/apg/patterns/treeview/) pattern.

Properties

PropertyAttributeTypeDefaultDescription
expandedexpandedbooleanfalse
selectedselectedbooleanfalseManaged by the parent tree — never set by this element on itself.
disableddisabledbooleanfalse
depthproperty onlynumbernoneHow many lit-material-tree-item ancestors this node has — 0 for a top-level node.
hasChildrenproperty onlybooleannoneWhether this node has at least one direct lit-material-tree-item child.
parentTreeItemproperty onlyLitMaterialTreeItem | nullnoneThis node's parent node, if any — used by the tree for ArrowLeft "move to parent".

Events

EventDescription
toggleFires when expanded changes via user interaction, with detail: { expanded }.

Slots

SlotDescription
labelThe node's label.
leadingAn optional icon before the label.
defaultNested lit-material-tree-item children.

CSS parts

PartDescription
rowThe node's own row (background/padding).
rippleThe state-layer element the hover/press feedback is drawn on.
focus-ringThe focus indicator element.
chevronThe expand/collapse button.
groupThe container for nested children.

<lit-material-tree>

Groups lit-material-tree-item elements into a hierarchical tree, per the WAI-ARIA [Tree View](https://www.w3.org/WAI/ARIA/apg/patterns/treeview/) pattern — arrow-key navigation across every *visible* node (skipping the contents of collapsed branches), and single- or multi-select coordination.

Properties

PropertyAttributeTypeDefaultDescription
multiplemultiplebooleanfalseAllows more than one node to be selected at once (each click toggles that node). Default: single-select.

Events

EventDescription
changeFires when the selection changes via user interaction.

Slots

SlotDescription
defaultTop-level lit-material-tree-item elements.

CSS parts

PartDescription
treeThe container.

Source on GitHub npm