Web · Components
TreeSelect
Select box from a tree: for nested options like categories, departments, folders, country > city.
5 exports
Live example
Preview
Code
Events
- Events appear here when you interact with the preview.
In a form
Import
Select box from a tree: for nested options like categories, departments, folders, country > city. Clicking the box opens a TreeView below it.
- Single selection: clicking a node selects it and closes; with
leavesOnlyonly leaves are selectable. The box shows the name (the full path withshowPath). - Multiple selection: checkboxes with
multiple; a parent is linked to its children (tri-state). The value holds leaves (checkOutput="leaves"), fully selected branches ("top") or all ("all"). - Search: a search box appears with more than 15 nodes; non-matching branches are hidden, matches highlighted.
- Large tree: rows are virtualized; with
loadChildrenbranches load as they are expanded. - Mobile: the panel is a bottom sheet; it closes by pulling down and with the back button.
- Form:
nameis submitted via a hidden native<select>,requiredworks, and it returns to the initial value on form reset.
Examples
TreeSelectClassNames
interfaceClasses that can be passed to the inner parts of TreeSelect.
| Name | Type | Description |
|---|---|---|
trigger? | string | Open button (the visible box of the field). |
content? | string | The opened panel. |
tree? | string | The tree in the panel. |
SingleTreeSelectProps
interfaceSingle-select TreeSelect.
| Name | Type | Default | Description |
|---|---|---|---|
multiple? | false | false | If true, several nodes are selected with checkboxes. |
value? | string | Id of the selected node in controlled use; "" for none. | |
defaultValue? | string | Initial value in uncontrolled use. | |
onValueChange? | (value: string, node: TreeNode<T> | undefined) => void | Called with the id and node when the selection changes ("" when cleared). | |
leavesOnly? | boolean | false | Whether only leaves (nodes without children) can be selected. If true, clicking a parent node expands/collapses it. |
items | readonly TreeNode<T>[] | Nodes. See TreeNode; sub-branches can be loaded later with loadChildren. | |
loadChildren? | (node: TreeNode<T>, context: { signal: AbortSignal; }) => Promise<readonly TreeNode<T>[] | undefined | void> | hasChildren nodes fetch their children when expanded. See TreeView loadChildren. | |
search? | boolean | "auto" | "auto" | Search box in the panel. "auto": shows with more than 15 nodes. Insensitive to locale-specific letters and accents; non-matching branches are hidden. |
placeholder? | ReactNode | "Seçiniz" | Text shown while nothing is selected. |
defaultExpanded? | readonly string[] | "all" | Initially expanded nodes; "all" expands all. If omitted, the path of selected nodes is expanded. | |
icon? | IconProp | Icon at the start of the box. | |
clearable? | boolean | false | × button clearing the selection. |
showPath? | boolean | false | Whether the path of the selection is written in the box too. true: "Türkiye / İstanbul / Kadıköy"; false: only "Kadıköy". |
pathSeparator? | string | " / " | showPath separator. |
variant? | FieldVariant | CustomVariant<"field"> | Look. See FieldVariant. | |
effect? | EffectProp | Effect or effects of the field box (e.g. "glow", ["lift", "beam"]). The accent color is the focus color (--ui-field-focus). If omitted, UIProvider appearance.defaults.field.effect. See BuiltinEffect. | |
name? | string | Form field name; the selected id(s) are submitted under this name. | |
form? | string | Id of the form the field belongs to. | |
required? | boolean | The form can't be submitted without a selection. | |
disabled? | boolean | Disabled. | |
id? | string | Id of the open button. | |
autoFocus? | boolean | Focuses when the page opens. | |
open? | boolean | Whether the panel is open in controlled use. | |
defaultOpen? | boolean | false | Whether it starts open in uncontrolled use. |
onOpenChange? | (open: boolean) => void | When the panel opens or closes. | |
tooltip? | TooltipProp | Tooltip when hovering the box. See TooltipProp. | |
className? | string | Classes added to the container. | |
classNames? | TreeSelectClassNames | Classes added to the inner parts. | |
aria-label? | string | Screen reader name. | |
aria-labelledby? | string | Id of the element naming the box. | |
aria-describedby? | string | Id of the element describing the box. | |
aria-invalid? | boolean | "true" | "false" | Show as invalid. |
MultiTreeSelectProps
interfaceMulti-select TreeSelect.
| Name | Type | Default | Description |
|---|---|---|---|
multiple | true | Several nodes are selected with checkboxes; the panel doesn't close on selection. | |
value? | readonly string[] | Checked ids in controlled use (see checkOutput). | |
defaultValue? | readonly string[] | Initial values in uncontrolled use. | |
onValueChange? | (value: string[], nodes: TreeNode<T>[]) => void | Called with the ids and nodes when the selection changes. | |
checkOutput? | CheckOutput | "leaves" | Which nodes go into the value? "leaves": only leaves, "top": only the fully selected branch itself (if "Europe" is selected, not its countries), "all": all of them. See CheckOutput. |
checkMode? | "cascade" | "independent" | "cascade" | "cascade": a parent is linked to its children (tri-state). "independent": each node on its own. |
maxDisplay? | number | 2 | At most how many names are written in the box; the rest become "+3". |
items | readonly TreeNode<T>[] | Nodes. See TreeNode; sub-branches can be loaded later with loadChildren. | |
loadChildren? | (node: TreeNode<T>, context: { signal: AbortSignal; }) => Promise<readonly TreeNode<T>[] | undefined | void> | hasChildren nodes fetch their children when expanded. See TreeView loadChildren. | |
search? | boolean | "auto" | "auto" | Search box in the panel. "auto": shows with more than 15 nodes. Insensitive to locale-specific letters and accents; non-matching branches are hidden. |
placeholder? | ReactNode | "Seçiniz" | Text shown while nothing is selected. |
defaultExpanded? | readonly string[] | "all" | Initially expanded nodes; "all" expands all. If omitted, the path of selected nodes is expanded. | |
icon? | IconProp | Icon at the start of the box. | |
clearable? | boolean | false | × button clearing the selection. |
showPath? | boolean | false | Whether the path of the selection is written in the box too. true: "Türkiye / İstanbul / Kadıköy"; false: only "Kadıköy". |
pathSeparator? | string | " / " | showPath separator. |
variant? | FieldVariant | CustomVariant<"field"> | Look. See FieldVariant. | |
effect? | EffectProp | Effect or effects of the field box (e.g. "glow", ["lift", "beam"]). The accent color is the focus color (--ui-field-focus). If omitted, UIProvider appearance.defaults.field.effect. See BuiltinEffect. | |
name? | string | Form field name; the selected id(s) are submitted under this name. | |
form? | string | Id of the form the field belongs to. | |
required? | boolean | The form can't be submitted without a selection. | |
disabled? | boolean | Disabled. | |
id? | string | Id of the open button. | |
autoFocus? | boolean | Focuses when the page opens. | |
open? | boolean | Whether the panel is open in controlled use. | |
defaultOpen? | boolean | false | Whether it starts open in uncontrolled use. |
onOpenChange? | (open: boolean) => void | When the panel opens or closes. | |
tooltip? | TooltipProp | Tooltip when hovering the box. See TooltipProp. | |
className? | string | Classes added to the container. | |
classNames? | TreeSelectClassNames | Classes added to the inner parts. | |
aria-label? | string | Screen reader name. | |
aria-labelledby? | string | Id of the element naming the box. | |
aria-describedby? | string | Id of the element describing the box. | |
aria-invalid? | boolean | "true" | "false" | Show as invalid. |
TreeSelectProps
typeProps of the TreeSelect component.
| Name | Type | Default | Description |
|---|---|---|---|
multiple? | false | true | false | If true, several nodes are selected with checkboxes. |
value? | string | readonly string[] | Id of the selected node in controlled use; "" for none. | |
defaultValue? | string | readonly string[] | Initial value in uncontrolled use. | |
onValueChange? | (value: string, node: TreeNode<T> | undefined) => void | (value: string[], nodes: TreeNode<T>[]) => void | Called with the id and node when the selection changes ("" when cleared). | |
leavesOnly? | boolean | false | Whether only leaves (nodes without children) can be selected. If true, clicking a parent node expands/collapses it.(SingleTreeSelectProps<T>) |
items | readonly TreeNode<T>[] | Nodes. See TreeNode; sub-branches can be loaded later with loadChildren. | |
loadChildren? | (node: TreeNode<T>, context: { signal: AbortSignal; }) => Promise<readonly TreeNode<T>[] | undefined | void> | hasChildren nodes fetch their children when expanded. See TreeView loadChildren. | |
search? | boolean | "auto" | "auto" | Search box in the panel. "auto": shows with more than 15 nodes. Insensitive to locale-specific letters and accents; non-matching branches are hidden. |
placeholder? | ReactNode | "Seçiniz" | Text shown while nothing is selected. |
defaultExpanded? | readonly string[] | "all" | Initially expanded nodes; "all" expands all. If omitted, the path of selected nodes is expanded. | |
icon? | IconProp | Icon at the start of the box. | |
clearable? | boolean | false | × button clearing the selection. |
showPath? | boolean | false | Whether the path of the selection is written in the box too. true: "Türkiye / İstanbul / Kadıköy"; false: only "Kadıköy". |
pathSeparator? | string | " / " | showPath separator. |
variant? | FieldVariant | CustomVariant<"field"> | Look. See FieldVariant. | |
effect? | EffectProp | Effect or effects of the field box (e.g. "glow", ["lift", "beam"]). The accent color is the focus color (--ui-field-focus). If omitted, UIProvider appearance.defaults.field.effect. See BuiltinEffect. | |
name? | string | Form field name; the selected id(s) are submitted under this name. | |
form? | string | Id of the form the field belongs to. | |
required? | boolean | The form can't be submitted without a selection. | |
disabled? | boolean | Disabled. | |
id? | string | Id of the open button. | |
autoFocus? | boolean | Focuses when the page opens. | |
open? | boolean | Whether the panel is open in controlled use. | |
defaultOpen? | boolean | false | Whether it starts open in uncontrolled use. |
onOpenChange? | (open: boolean) => void | When the panel opens or closes. | |
tooltip? | TooltipProp | Tooltip when hovering the box. See TooltipProp. | |
className? | string | Classes added to the container. | |
classNames? | TreeSelectClassNames | Classes added to the inner parts. | |
aria-label? | string | Screen reader name. | |
aria-labelledby? | string | Id of the element naming the box. | |
aria-describedby? | string | Id of the element describing the box. | |
aria-invalid? | boolean | "true" | "false" | Show as invalid. | |
checkOutput? | CheckOutput | "leaves" | Which nodes go into the value? "leaves": only leaves, "top": only the fully selected branch itself (if "Europe" is selected, not its countries), "all": all of them. See CheckOutput.(MultiTreeSelectProps<T>) |
checkMode? | "cascade" | "independent" | "cascade" | "cascade": a parent is linked to its children (tri-state). "independent": each node on its own.(MultiTreeSelectProps<T>) |
maxDisplay? | number | 2 | At most how many names are written in the box; the rest become "+3".(MultiTreeSelectProps<T>) |