Tree Select

PRO

Select items from a hierarchy, such as an organization or folder structure.

Live preview
Interact with the component to see results here.
View code
HTML
<sy-tree-select
  placeholder="Choose a team"
  maxtagcount="2"
  expandable
  expandall
  line
  clearable
  name="team"
  id="sample"
  aria-label="Choose a team"
></sy-tree-select>

<script type="module">
  const component1 = document.querySelector("#sample");
  Object.assign(component1, {
    "nodes": [{
        "label": "Product",
        "value": "product",
        "children": [{
            "label": "Design",
            "value": "design"
          },
          {
            "label": "Engineering",
            "value": "engineering"
          }
        ]
      },
      {
        "label": "Business",
        "value": "business",
        "children": [{
            "label": "Sales",
            "value": "sales"
          },
          {
            "label": "Support",
            "value": "support"
          }
        ]
      }
    ]
  });
</script>

Usage guide

#

Use to select from hierarchical candidates, such as organizations or categories.

  1. Write the error message in the error slot.

    Inside the component, add <span slot="error">Error message</span>. You can include links and other guidance as well as text. For inputs supporting noNativeValidity, enable it to show this guidance instead of a browser popup. Switch always displays errors below the component.

  2. Report business rule failures with setCustomError().

    For example, if the server rejects a duplicate value, update the error slot and call setCustomError(). This method does not take a message argument. A custom error also blocks form submission.

  3. Clear the error after resolving it and check whether submission is allowed.

    Use clearCustomError() to clear a business rule error. Required-field and format validation remain active. await checkValidity() returns true or false; reportValidity() validates and displays errors. Read valid named values through FormData on submission.

  1. Prepare hierarchical data

    Pass a tree array with label, value, and children to nodes.

  2. Selection and expansion

    Use checkable for multiple selection and expandable for branch expansion. expandAll opens the whole tree initially.

  3. Manage selection results

    Use clearable to offer clearing and maxTagCount to control the number of visible selection tags.

Feature examples

#

Choose a feature from 20 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 · Clearable

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Default Value

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Disabled

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 · Loading

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Max Tag Count

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · No Native Validity

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 · Placeholder

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Readonly

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Required

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Property · Status

See how settings change appearance and behavior.

View code
HTML
Loading the example.

Methods · CheckValidity

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

View code
HTML
Loading the example.

Methods · ReportValidity

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

View code
HTML
Loading the example.

Methods · SetCustomError

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

View code
HTML
Loading the example.

Events · Changed

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-select>

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.
booleanfalseShow a button to clear the current value.
string''Initially selected value.
booleanfalseBlock user interaction and keyboard focus.
'error' | 'default''default'Visually represent default, success, warning, or error states.
booleanfalseAllow tree branches to be expanded and collapsed.
booleanfalseExpand all tree branches initially.
booleanfalseShow connectors between parent and child nodes.
booleanfalseIndicate that processing is in progress.
number0Number of selected tags shown at once. Set to 0 to show all.
number | nullnullDisplay width of tree nodes.
string''Placeholder shown when the value is empty.
booleanfalseControl how parent nodes are included in the selection result.
booleanfalseDisplay the current value while preventing edits.
booleanfalseFail form validation when no value is provided.
string''Field name used in FormData.
booleanfalseUse the app's error UI instead of the browser's built-in error display. checkValidity still performs validation.

Events

EventDetailDescription
CustomEvent<{ selectedItem: { value: string; label: string }[]; isValid: boolean }>Emitted when the value or selection state changes.

Methods

MethodReturnsDescription
Promise<void>Set custom validity with the specified message. An empty string clears the error.
Promise<boolean>Return true if the current constraints are satisfied, otherwise false.
Promise<boolean>Validate the current value and display errors to the user.
Promise<void>Set a custom error state.
Promise<void>Clear the custom error state.
Promise<"" | "custom" | "valueMissing">Return the current validation state.

Slots

SlotDescription
Validation error message.