ef-tree / ef-tree-item

Generic data-driven tree component. The building block used by ef-hierarchy.

ef-tree is a general-purpose tree view driven by a .items array. ef-hierarchy is built on top of it. Use ef-tree directly when you need a collapsible tree for non-composition data.

<ef-tree show-header header="Files"></ef-tree>

<script>
  const tree = document.querySelector('ef-tree');
  tree.items = [
    {
      id: 'src',
      label: 'src',
      children: [
        { id: 'index', label: 'index.ts' },
        { id: 'app', label: 'app.ts' },
      ],
    },
    { id: 'package', label: 'package.json' },
  ];

  tree.addEventListener('tree-select', (e) => {
    console.log('selected:', e.detail.id);
  });
</script>

TreeItem shape:

interface TreeItem {
  id: string;
  label: string;
  icon?: string;       // optional icon HTML/text
  children?: TreeItem[];
}

Attributes

AttributeReact propTypeDefaultDescription
expand-allexpandAllbooleantrueExpands all items by default.
headerheaderstring""Header text shown above the tree (when `show-header`).
selected-idselectedIdstring | nullID of the currently selected item.
show-headershowHeaderbooleanfalseWhether to show the header row.

CSS Parts

PartDescription
containerThis part is the outer tree wrapper.
emptyThis part is the empty-state message.
headerThis part is the optional header. It appears when `show-header` is true.

CSS Custom Properties

PropertyDefaultDescription
--tree-bgvar(--ef-color-bg)Background color of the tree container.
--tree-bordervar(--ef-color-border)Border color.
--tree-hover-bgvar(--ef-color-border-subtle)Row background color on hover.
--tree-selected-bgvar(--ef-color-primary-subtle, rgba(110,168,254,0.18))Row background color when selected.
--tree-textvar(--ef-color-text)Text color.

Events

EventDetailDescription
tree-select{ id: string | null; item: TreeItem | null }This event fires when the user clicks a row.

CSS Parts

PartDescription
childrenThis part is the wrapper around the nested child items. It receives the `data-collapsed` attribute.
expand-iconThis part is the expand and collapse chevron.
iconThis part is the optional item icon.
labelThis part is the item label text.
rowThis part is the item row. It receives the `data-selected` attribute.

CSS Custom Properties

PropertyDefaultDescription
--tree-expand-icon-size1remSize of the expand/collapse chevron icon.
--tree-icon-gap0.25remGap between the icon and label.
--tree-indent1remIndent width per nesting level.
--tree-item-font-size0.75remRow label font size.
--tree-item-height1.5remRow height.
--tree-item-padding-left0.5remRow left padding.
--tree-item-padding-right0.5remRow right padding.