Tree

PRO

Expand and explore a hierarchy, then select or edit items.

Live preview
Interact with the component to see results here.
View code
HTML
<sy-tree
  expandable
  checkable
  clickable
  searchterm=""
  id="sample"
></sy-tree>

<script type="module">
  const component1 = document.querySelector("#sample");
  Object.assign(component1, {
    "nodes": [{
        "value": "project",
        "label": "Project",
        "expanded": true,
        "appendable": true,
        "children": [{
            "value": "core",
            "label": "Design System",
            "editable": true,
            "removable": true
          },
          {
            "value": "charts",
            "label": "Charts",
            "editable": true,
            "removable": true
          },
          {
            "value": "grid",
            "label": "Grid",
            "disabled": true
          }
        ]
      },
      {
        "value": "docs",
        "label": "Documents",
        "appendable": true,
        "children": [{
          "value": "guide",
          "label": "Guide"
        }]
      }
    ]
  });
</script>

Usage guide

#

Use to explore and manage hierarchical data, such as files or organizations. Use Tree Select to collect a value in a form.

  1. Build the tree

    Provide unique value identifiers, label, and children in nodes.

  2. Set the interaction scope

    Enable expandable, clickable, or checkable, and further restrict interactions on individual nodes.

  3. Save changes

    Handle nodesChanged and save in your app. Example changes affect only the local view.

Feature examples

#

Choose a feature from 22 topics. Explore property settings, method calls, event results, and slot layouts through live examples and code.

Usage examples · Overview

Try the selected example. Topics with multiple configurations let you switch between detailed examples.

View code
HTML
Loading the example.

Property · Checkable

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Clickable

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Editable

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Expand All

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Expandable

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Line

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Manual Add

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Manual Remove

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Node Width

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Nodes

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Search Term

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Selected Value

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Tree Draggable

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Methods · ClearAllSelectedItem

Use the example's buttons to call methods and inspect their results.

View code
HTML
Loading the example.

Methods · FindNode

Use the example's buttons to call methods and inspect their results.

View code
HTML
Loading the example.

Methods · ManualAddChildNode

Use the example's buttons to call methods and inspect their results.

View code
HTML
Loading the example.

Methods · ManualRemoveNode

Use the example's buttons to call methods and inspect their results.

View code
HTML
Loading the example.

Methods · SetCheckState

Use the example's buttons to call methods and inspect their results.

View code
HTML
Loading the example.

Events · ItemChecked

Interact with the component to see event names and payloads in the live preview below.

View code
HTML
Loading the example.

Events · ItemSelected

Interact with the component to see event names and payloads in the live preview below.

View code
HTML
Loading the example.

Events · NodesChanged

Interact with the component to see event names and payloads in the live preview below.

View code
HTML
Loading the example.

API reference

#

Hover over a name or focus it with the keyboard to see the code. On touch screens, tap the name.

<sy-tree>

Properties

Attribute / PropertyTypeDefaultDescription
TreeNode[][]Array of tree nodes with label, value, and children.

Pass objects and arrays as JavaScript properties.

booleanfalseSelect multiple items using checkboxes.
booleanfalseAllow user selection and emit the selected event.
booleanfalseAllow nodes to be moved by dragging.
booleanfalseAllow node names to be edited.
booleanfalseAllow tree branches to be expanded and collapsed.
booleanfalseExpand all tree branches initially.
booleanfalseHave the app call manualAddChildNode after an add request.
booleanfalseHave the app call manualRemoveNode after a removal request.
booleanfalseShow connectors between parent and child nodes.
number | nullnullDisplay width of tree nodes.
string''Unique key of the selected node.
string''Search query used to filter and highlight candidates.
booleanfalseUsed internally with Tree Select. Keep the default for a regular Select.

Events

EventDetailDescription
CustomEvent<TreeNodesChangedDetail>Read the result from the event's detail.
CustomEvent<TreeItemCheckedDetail>Read the result from the event's detail.
CustomEvent<TreeItemSelectedDetail>Read the result from the event's detail.

Methods

MethodReturnsDescription
Promise<void>Change the checked state of the specified tree node.
Promise<void>Clear all checked tree selections.
Promise<void>Add a new child under a parent node.
Promise<void>Remove a tree node by its unique key.
Promise<TreeNode | null>Find the node matching a unique key in the supplied node array.

<sy-tree-item>

Properties

Attribute / PropertyTypeDefaultDescription
booleanfalseShow the add-child action.
booleanfalseSelect multiple items using checkboxes.
booleanfalseSelected or on state.
booleanfalseAllow user selection and emit the selected event.
booleanfalseBlock user interaction and keyboard focus.
booleanfalseAllow this node to be dragged.
booleanfalseWhether the node is being dragged. Managed by the parent.
'none' | 'valid' | 'invalid''none'Indicate whether dropping is allowed. Managed by the parent.
booleanfalseAllow name editing.
booleanfalseAllow tree branches to be expanded and collapsed.
booleanfalseWhether children are expanded.
booleanfalseRestrict node movement.
booleanfalseIndicate whether child nodes exist.
string'New item'Placeholder for the new node name input.
string''Set icon visibility or icon content. Check the format supported by each component.
booleanfalseIndeterminate state when only some items are selected.
booleanfalseWhether the node is nested under another node. Managed by the parent.
booleanfalseIndicate whether the name is being edited.
string''Label describing the item.
number0Hierarchy depth. Managed by the parent.
booleanfalseAllow the node removal action.
any[][]Child node array, passed down by the parent.

Pass objects and arrays as JavaScript properties.

string''Tag text beside the node.
"gray" | "purple" | "blue" | "green" | "cyan" | "yellow" | "orange" | "red" | undefinedundefinedTag color beside the node.
string''Current value or item identifier.
string''Search query used to filter and highlight candidates.
string''Unique key of the currently selected node.
number | nullnullDisplay width of tree nodes.
booleanfalseShow connectors between parent and child nodes.

Events

EventDetailDescription
CustomEvent<{ value: string; label: string; expanded: boolean }>Read the result from the event's detail.
CustomEvent<{ value: string; label: string; checked: boolean }>Read the result from the event's detail.
CustomEvent<{ parentValue: string; childLabel: string; childValue: string; childLevel: number }>Read the result from the event's detail.
CustomEvent<{ value: string; label: string }>Read the result from the event's detail.
CustomEvent<{ value: string; label: string }>Read the result from the event's detail.
CustomEvent<any>Read the result from the event's detail.
CustomEvent<any>Read the result from the event's detail.
CustomEvent<{ targetKey: string; draggedKey: string; dropPosition: string; targetLevel: number }>Read the result from the event's detail.
CustomEvent<{ value: string; label: string; checked: boolean }>Read the result from the event's detail.
CustomEvent<string>Read the result from the event's detail.

Methods

MethodReturnsDescription
Promise<void>Layout only, and called fire-and-forget by the parent tree, so it never rejects: a no-op before the item started, and it still runs while frozen.