Tree
xxxxxxxxxx
<ef-tree></ef-tree>
xxxxxxxxxx
const tree = document.querySelector('ef-tree');
tree.data = [{
label: 'Group 1',
expanded: true,
items: [{
label: 'Item 1.1',
value: '1.1'
},
{
label: 'Item 1.2',
value: '1.2'
},
{
label: 'Item 1.3',
value: '1.3',
selected: true
}
]
},
{
label: 'Group 2',
items: [{
label: 'Item 2.1',
value: '2.1'
},
{
label: 'Item 2.2',
value: '2.2'
},
{
label: 'Item 2.3',
value: '2.3'
}
]
}
]
1
Displays a nested data structure as a tree menu. Useful for navigating grouped/categorized data.
Basic usage
The data of ef-tree
can be set by passing an array of objects to the element's data
property.
<ef-tree></ef-tree>
const tree = document.querySelector('ef-tree');
tree.data = [{
label: 'Group 1',
expanded: true,
items: [{
label: 'Item 1.1',
value: '1.1'
},
{
label: 'Item 1.2',
value: '1.2'
},
{
label: 'Item 1.3',
value: '1.3',
selected: true
}]
},
{
label: 'Group 2',
items: [{
label: 'Item 2.1',
value: '2.1'
},
{
label: 'Item 2.2',
value: '2.2'
},
{
label: 'Item 2.3',
value: '2.3'
}]
}]
Tree item with icon
Icon can be set to show on each node in tree by using icon key in item object. You can pass icon name, url of icon svg file or empty string.
<ef-tree></ef-tree>
const tree = document.querySelector('ef-tree');
tree.data = [{
label: 'Request 5 Rank 1: custom leage table',
icon: 'list',
selected: true,
expanded: true,
items: [{
label: 'Req. 5 Rnk. 1 Dr.Req. 1: Goldman Sachs & Co',
value: '1.1',
icon: 'https://cdn.refinitiv.com/public/libs/elf/assets/elf-theme-halo/resources/icons/grid.svg'
},
{
label: 'Req. 5 Rnk. 1 Dr.Req. 2: Allen & Co Inc',
value: '1.2',
icon: 'https://cdn.refinitiv.com/public/libs/elf/assets/elf-theme-halo/resources/icons/grid.svg'
}]
},
{
label: 'Session Details',
icon: 'sendfeed',
}]
xxxxxxxxxx
<div class="container">
<ef-tree id="basic"></ef-tree>
<ef-tree multiple id="multiple"></ef-tree>
</div>
xxxxxxxxxx
var basicTree = document.getElementById('basic');
var multipleTree = document.getElementById('multiple');
basicTree.data = [{
label: 'Request 5 Rank 1: custom leage table',
icon: 'list',
selected: true,
expanded: true,
items: [{
label: 'Req. 5 Rnk. 1 Dr.Req. 1: Goldman Sachs & Co',
value: '1.1',
icon: 'https://cdn.refinitiv.com/public/libs/elf/assets/elf-theme-halo/resources/icons/grid.svg'
},
{
label: 'Req. 5 Rnk. 1 Dr.Req. 2: Allen & Co Inc',
value: '1.2',
icon: 'https://cdn.refinitiv.com/public/libs/elf/assets/elf-theme-halo/resources/icons/grid.svg'
}
]
},
{
label: 'Session Details',
icon: 'sendfeed',
}
]
multipleTree.data = [{
label: 'Request 5 Rank 1: custom leage table',
icon: 'list',
selected: true,
expanded: true,
items: [{
label: 'Req. 5 Rnk. 1 Dr.Req. 1: Goldman Sachs & Co',
value: '1.1',
icon: 'https://cdn.refinitiv.com/public/libs/elf/assets/elf-theme-halo/resources/icons/grid.svg'
},
{
label: 'Req. 5 Rnk. 1 Dr.Req. 2: Allen & Co Inc',
value: '1.2',
icon: 'https://cdn.refinitiv.com/public/libs/elf/assets/elf-theme-halo/resources/icons/grid.svg'
}
]
},
{
label: 'Session Details',
icon: 'sendfeed',
}
]
xxxxxxxxxx
.container {
display: flex;
}
ef-tree {
margin-right: 20px;
}
Data property interface
The data
property that passes through the ef-tree
uses the TreeData
interface for its data items which is described below.
Name | Type | Description |
---|---|---|
label | string | Item's label |
value | string | Value of an item |
icon | string | Icon of an item |
selected | boolean | Selection state of the item |
expanded | boolean | Expanded state of child items |
items | array | Child items collection |
readonly | boolean | Sets the item to be readonly |
disabled | boolean | Sets the item to be disabled |
Multiple selection
Tree uses single selection mode by default. Use the multiple
attribute if you need multiple selections.
<ef-tree multiple></ef-tree>
xxxxxxxxxx
<ef-tree multiple></ef-tree>
xxxxxxxxxx
const tree = document.querySelector('ef-tree');
tree.data = [{
label: 'Group 1',
items: [{
label: 'Item 1.1',
value: '1.1'
},
{
label: 'Item 1.2',
value: '1.2'
},
{
label: 'Item 1.3',
value: '1.3',
selected: true
}
]
},
{
label: 'Group 2',
items: [{
label: 'Item 2.1',
value: '2.1'
},
{
label: 'Item 2.2',
value: '2.2'
},
{
label: 'Item 2.3',
value: '2.3'
}
]
}
]
1
Turn off parent/child relationship
For multiple selection mode, Tree manages the relationship between parent and child items. Use the no-relation
attribute to turn this feature off.
<ef-tree multiple no-relation></ef-tree>
xxxxxxxxxx
<ef-tree multiple no-relation></ef-tree>
xxxxxxxxxx
const tree = document.querySelector('ef-tree');
tree.data = [{
label: 'Group 1',
items: [{
label: 'Item 1.1',
value: '1.1'
},
{
label: 'Item 1.2',
value: '1.2'
},
{
label: 'Item 1.3',
value: '1.3',
selected: true
}
]
},
{
label: 'Group 2',
items: [{
label: 'Item 2.1',
value: '2.1'
},
{
label: 'Item 2.2',
value: '2.2'
},
{
label: 'Item 2.3',
value: '2.3'
}
]
}
]
1
Tree value(s) and events
Use the value-changed
event to know when the user has changed any selection in Tree. Tree provides value
and values
properties for accessing selected item(s).
Typically, you can just use the values
property, as it will work for both multiple and single selection mode. With single selection mode, value
represents a single value, whereas in multiple selection mode, it will store the first value of the values
array.
const tree = document.querySelector('ef-tree');
tree.addEventListener('value-changed', (e) => {
console.log(e.detail); // value that users changed
console.log(tree.values); // access selected items
});