Skip to content
Focsd homeFocsd homeFocsd
Forms

Tree view

A hierarchical list that expands and collapses, like a file browser.

  • Tag: focsd-tree
  • Pattern: Tree
  • Category: Data

Example

HTML
<focsd-tree label="Project files">
<focsd-tree-item label="src" value="src" expanded>
<focsd-tree-item label="index.js" value="src/index.js"></focsd-tree-item>
<focsd-tree-item label="components" value="src/components">
<focsd-tree-item
label="button.js"
value="src/components/button.js"></focsd-tree-item>
</focsd-tree-item>
</focsd-tree-item>
<focsd-tree-item label="package.json" value="package.json"></focsd-tree-item>
<focsd-tree-item label="README.md" value="README.md"></focsd-tree-item>
</focsd-tree>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/components/focsd-tree.js';
</script>
<focsd-tree label="Project files">…</focsd-tree>

API

Attributes

AttributePropertyTypeDefault
labellabelstring—
valuevaluestring—

Events

EventDescription
changeFired when the user commits a change to the value or state.

Slots

SlotDescription
(default)Default content.

Accessibility

  • APG tree view: role="tree", items are role="treeitem" with aria-level, aria-expanded (parents only) and aria-selected.
  • One tab stop. If the focused item is hidden because a parent collapses (for example from code), focus moves to the nearest visible parent, so it is never lost.

Keyboard

KeyAction
Arrow Up / DownPrevious / next visible item
Arrow RightExpand, or move to the first child
Arrow LeftCollapse, or move to the parent
Home / EndFirst / last item
Enter / SpaceSelect
Type a letterJump to an item