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.
| Attribute | React prop | Type | Default | Description |
|---|
expand-all | expandAll | boolean | true | Expands all items by default. |
header | header | string | "" | Header text shown above the tree (when `show-header`). |
selected-id | selectedId | string | null | — | ID of the currently selected item. |
show-header | showHeader | boolean | false | Whether to show the header row. |
<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[];
}
Events:
| Event | Detail | Description |
|---|
tree-select | { id: string | null; item: TreeItem | null } | Fires when the user clicks a row. |
| Property | Default | Description |
|---|
--tree-bg | — | Background color of the tree container. |
--tree-border | — | Border color. |
--tree-hover-bg | — | Row background color on hover. |
--tree-selected-bg | — | Row background color when selected. |
--tree-text | — | Text color. |
Each row is rendered by an internal ef-tree-item:
| Property | Default | Description |
|---|
--tree-expand-icon-size | 1rem | Size of the expand/collapse chevron icon. |
--tree-icon-gap | 0.25rem | Gap between the icon and label. |
--tree-indent | 1rem | Indent width per nesting level. |
--tree-item-font-size | 0.75rem | Row label font size. |
--tree-item-height | 1.5rem | Row height. |
--tree-item-padding-left | 0.5rem | Row left padding. |
--tree-item-padding-right | 0.5rem | Row right padding. |
| Part | Description |
|---|
container | Outer tree wrapper. |
empty | Empty-state message. |
header | Optional header (when `show-header`). |
| Part | Description |
|---|
children | Wrapper around nested child items (receives `data-collapsed`). |
expand-icon | Expand/collapse chevron. |
icon | Optional item icon. |
label | Item label text. |
row | Item row (receives `data-selected`). |