<cs-tree>
StableNavigationSince 0.1

Trees allow you to display a hierarchical list of selectable tree items. Items with children can be expanded and collapsed as desired by the user.

Deciduous Birch Maple Field maple Red maple Sugar maple Oak Walnut Coniferous Cedar Pine Eastern white pine Ponderosa pine Scots pine Spruce Fir Tropical Banyan Coconut palm Mahogany Teak

Examples

Selection

Set the selection attribute to change what a tree lets you select.

ValueSelects
single defaultOne item at a time
multipleAny number of items
leafOne leaf node (a node with no children)
leaf-multipleAny number of leaf nodes
Electronics Computers Laptops Desktops Tablets Phones Smartphones Accessories Clothing Shirts Pants Shoes Books Single Multiple Leaf Leaf-multiple

Size

Trees inherit their font size by default. You can change the size of a tree and all of its items by setting font-size on the <cs-tree> element. All internal dimensions, including checkboxes, expand buttons, and labels, scale proportionally.

Small Newsletters Promotions Weekly deals Seasonal sales
Default Newsletters Promotions Weekly deals Seasonal sales
Large Newsletters Promotions Weekly deals Seasonal sales

Indent Guides

Set the --indent-guide-width custom property to draw indent guides. The --indent-guide-color, --indent-guide-style, and --indent-guide-offset custom properties tune their color, style, and offset.

Design Brand Colors Typography Logo Components Buttons Forms Navigation Development Frontend Backend Infrastructure Marketing Social Media Email Campaigns Analytics

Expand & Collapse Icons

Use the expand-icon and collapse-icon slots to change the expand and collapse icons, respectively. To disable the animation, override the rotate property on the expand-button part as shown below.

Recipes Breakfast Pancakes Omelette Granola Lunch Caesar salad Grilled chicken wrap Dinner Pasta carbonara Stir fry Roasted salmon Desserts Chocolate cake Tiramisu Fruit tart

Item Icons

Decorative icons can be used before labels to provide hints for each node.

Documents Photos vacation.jpg family-portrait.png sunset.jpg Work quarterly-report.pdf budget.xls meeting-notes.txt Personal journal.txt resume.pdf Downloads archive.zip readme.txt

Lazy Loading

Use the lazy attribute on a tree item to indicate that the content is not yet present and will be loaded later. When the user tries to expand the node, the loading state is set to true and the cs-lazy-load event will be emitted to allow you to load data asynchronously. The item will remain in a loading state until its content is changed.

If you want to disable this behavior after the first load, remove the lazy attribute and, on the next expand, the existing content will be shown instead.

Remote Repositories

API

Importing

If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick this component, use one of the following snippets.

npm Self-Hosted React
import '@cruglobal/cornerstone-components/components/tree/tree.js';
import './cornerstone/components/tree/tree.js';
import CsTree from '@cruglobal/cornerstone-components/react/tree/index.js';

Slots

Learn more about using slots.

NameDescription
(default)The default slot.
collapse-iconThe icon to show when the tree item is collapsed. Works best with <cs-icon>.
expand-iconThe icon to show when the tree item is expanded. Works best with <cs-icon>.

Attributes & Properties

Learn more about attributes and properties.

PropertyAttributeDescriptionTypeDefaultReflects
selectionselectionThe selection behavior of the tree. Single selection allows only one node to be selected at a time. Multiple displays checkboxes and allows more than one node to be selected. Leaf allows only leaf nodes to be selected. Leaf-multiple allows multiple leaf nodes to be selected while parent nodes only expand and collapse.'single' | 'multiple' | 'leaf' | 'leaf-multiple''single'

Events

Learn more about events.

NameDescription
cs-selection-changeEmitted when a tree item is selected or deselected.

CSS Custom Properties

Learn more about CSS custom properties.

NameDescriptionDefault
--indent-guide-colorThe color of the indentation line.var(--cs-color-surface-border)
--indent-guide-offsetThe amount of vertical spacing to leave between the top and bottom of the indentation line's starting position.0
--indent-guide-styleThe style of the indentation line, e.g. solid, dotted, dashed.solid
--indent-guide-widthThe width of the indentation line.0
--indent-sizeThe size of the indentation for nested items.var(--cs-space-m)

CSS Parts

Learn more about CSS parts.

NameDescriptionCSS selector
treeThe component's outer wrapper.::part(tree)

Dependencies

This component automatically imports the following elements. Sub-dependencies, if any exist, are included in this list.