Select
Tree Select
NewA select whose options form a tree, with branches that fold open, cascading checkboxes and a search that keeps the path to every match.
npx motionsnack add tree-selectCustomize
<TreeSelect />Props
32 properties
| Property | Type | Default | Description |
|---|---|---|---|
| nodes | { id: string; label: string; description?: string; icon?: string; children?: Node[]; disabled?: boolean }[] | demo services tree | The tree of choices. A node with children is a branch, one without is a leaf. |
| defaultExpanded | string[] | ['design'] | Ids of the branches open when the list first opens. |
| value | string[] | - | Controlled value: the picked ids. Leave undefined to let the component manage it. |
| defaultValue | string[] | [] | Value on first render when uncontrolled. |
| onChange | (ids: string[], nodes?: TreeSelectNode[]) => void | - | Called with the picked ids and their nodes. |
| open | boolean | - | Controlled open state of the list. Leave undefined to let the component manage it. |
| defaultOpen | boolean | false | Open state on first render when uncontrolled. |
| onOpenChange | (open: boolean) => void | - | Called whenever the user opens or closes the list. |
| errorColor | string | - | Overrides the error colour on both themes (keep 4.5 : 1). Left out, the theme pair #dc2626 / #ef4444 is used. |
| name | string | - | Name submitted with a form; the ids go comma-joined. |
| id | string | generated | Id of the field. |
| className | string | '' | Extra classes on the wrapper. |
| label | string | 'Services' | Label above the field. Empty hides it. |
| placeholder | string | 'Pick services' | Text in the field while nothing is picked. |
| helperText | string | 'Pick everything you need, we will quote it together.' | Small text under the field. Empty hides it. |
| error | string | '' | Error message. Any text marks the field invalid and replaces the helper text. |
| selectionMode | 'leaves' | 'all' | 'leaves' | With Multiple: the value holds only checked leaves, or also every fully checked branch. |
| searchPlaceholder | string | 'Search services' | Hint in the search box. |
| noResultsText | string | 'No results' | Text when the search finds nothing. |
| height | number | 48 | Height of the field. With several chips it grows. |
| radius | number | 12 | Corner radius of the field. |
| listMaxHeight | number | 320 | Tallest the list gets before it scrolls. |
| maxVisibleChips | number | 3 | Most chips in the field; the rest fold into +N more. |
| multiple | boolean | true | Pick several nodes with checkboxes. Without it one leaf is picked and the list closes. |
| searchable | boolean | true | A search box at the top of the list that filters the tree. |
| showGuides | boolean | true | Thin vertical lines that show which branch a row belongs to. |
| showIcons | boolean | true | Show the node icons. |
| showDescriptions | boolean | false | Show the line under each node's label. |
| clearable | boolean | false | An × in the field that clears the choice. |
| required | boolean | false | Marks the field as required. |
| disabled | boolean | false | Disables the field. |
| readOnly | boolean | false | Shows the value at full contrast; focusable, but the list never opens. |
About Tree Select
Tree Select is for choices that nest: services under disciplines, pages under sections, products under categories. Closed, it looks like every other field of the library; open, a list drops 6px below it and its rows come in one after another out of a soft blur. Each branch has a chevron that turns as its children fold open with a smooth height and fade, and thin guide lines show which branch a row belongs to. Checking a branch checks everything under it, and a branch with only some children checked shows a dash. In the field the picks show as chips, a fully checked branch as one chip, folding into +N more after a number you set. The search box at the top filters the tree as you type, keeps the path to every match visible and opens it, and shows the matched letters in full contrast. The keyboard follows the tree pattern people know from file browsers: arrows up and down, right to open or step in, left to close or step out, Home, End, Space, Enter, star to open a whole level and typing to jump. The value can hold only the checked leaves or the fully checked branches too, and a single-pick mode closes the list on a leaf.
What's included
- Branches that fold open with a smooth height and fade
- Cascading checkboxes with a mixed state on parents
- Search that keeps and opens the path to every match
- Chips in the field, a full branch as one chip
- Tree keyboard: arrows, Home/End, Space, Enter, star, typeahead
- Leaves-only or full-branch value, or single pick
- Light and dark look
- Type
- Animated React select component
- Library
- Components · Select