Command palette

@yasinsensoy/native

React Native · Components

TreeSelect

A select box picking from a tree (same API as the web TreeSelect): nested options such as categories, departments, folders.

4 exports

Live example

The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.

Preview

Code

import { TreeSelect } from "@yasinsensoy/native";

<TreeSelect name="unit" items={units} showPath clearable />

Events

  1. Events appear here when you interact with the preview.

In a form

Import

import { TreeSelect } from "@yasinsensoy/native";

TreeSelect

component

A select box picking from a tree (same API as the web TreeSelect): nested options such as categories, departments, folders. Tapping the box opens a TreeView; on phones it is a bottom sheet.

  • Single selection: tapping a node selects it and closes; with leavesOnly only leaves. With showPath the full path in the box.
  • Multiple selection: checkboxes with multiple; a parent is linked to its children (tri-state). The value holds leaves, fully selected branches or all of them.
  • Search: a search box with more than 15 nodes; non-matching branches are hidden.
  • Large trees: rows are virtualized; with loadChildren branches load as they expand.
  • Form: binds inside a Form via name.
TreeSelect(props: TreeSelectProps<T>): ReactElement<unknown, string | JSXElementConstructor<any>>

Examples

<TreeSelect name="category" label="Category" leavesOnly showPath items={categories} />
<TreeSelect multiple name="departments" checkOutput="top" clearable items={departments} />

Single selection TreeSelect.

Extends: FieldProps

NameTypeDefaultDescription
multiple?falsefalseWhen true, multiple nodes are selected with checkboxes.
value?stringSelected id in controlled use; "" for none.
defaultValue?stringInitial value in uncontrolled use.
onValueChange?(value: string, node: TreeNode<T> | undefined) => voidWith the id and node when the selection changes ("" when cleared).
leavesOnly?booleanfalseOnly leaves can be selected; tapping a parent node toggles it.
itemsreadonly TreeNode<T>[]Nodes; children 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.
search?boolean | "auto""auto"Search box in the panel; "auto": with more than 15 nodes.
placeholder?string"Seçiniz"Text shown when nothing is selected.
defaultExpanded?readonly string[] | "all"Initially expanded nodes; "all" for all. If omitted the paths of the selected nodes expand.
icon?IconPropIcon at the start of the box.
clearable?booleanfalseClear button.
showPath?booleanfalseShow the selection's path in the box too ("Türkiye / İstanbul / Kadıköy")?
pathSeparator?string" / "showPath separator.
variant?FieldVariant"outline"Field appearance.
open?booleanIs the panel open, in controlled use?
onOpenChange?(open: boolean) => voidWhen the panel opens or closes.
aria-label?stringScreen reader name; give it when there is no visible label.
style?StyleProp<ViewStyle>Container style.

Multiple selection TreeSelect.

Extends: FieldProps

NameTypeDefaultDescription
multipletrueMultiple nodes are selected with checkboxes; the panel does not 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>[]) => voidWith the ids and nodes when the selection changes.
checkOutput?CheckOutput"leaves"Which nodes go into the value? See CheckOutput.
checkMode?"cascade" | "independent""cascade""cascade": a parent is linked to its children (tri-state); "independent".
maxDisplay?number2Maximum names written in the box; the rest become "+3".
itemsreadonly TreeNode<T>[]Nodes; children 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.
search?boolean | "auto""auto"Search box in the panel; "auto": with more than 15 nodes.
placeholder?string"Seçiniz"Text shown when nothing is selected.
defaultExpanded?readonly string[] | "all"Initially expanded nodes; "all" for all. If omitted the paths of the selected nodes expand.
icon?IconPropIcon at the start of the box.
clearable?booleanfalseClear button.
showPath?booleanfalseShow the selection's path in the box too ("Türkiye / İstanbul / Kadıköy")?
pathSeparator?string" / "showPath separator.
variant?FieldVariant"outline"Field appearance.
open?booleanIs the panel open, in controlled use?
onOpenChange?(open: boolean) => voidWhen the panel opens or closes.
aria-label?stringScreen reader name; give it when there is no visible label.
style?StyleProp<ViewStyle>Container style.

TreeSelect props (same names as web).

type TreeSelectProps = SingleTreeSelectProps<T> | MultiTreeSelectProps<T>

Extends: FieldProps

NameTypeDefaultDescription
multiple?false | truefalseWhen true, multiple nodes are selected with checkboxes.
value?string | readonly string[]Selected id 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>[]) => voidWith the id and node when the selection changes ("" when cleared).
leavesOnly?booleanfalseOnly leaves can be selected; tapping a parent node toggles it.(SingleTreeSelectProps<T>)
itemsreadonly TreeNode<T>[]Nodes; children 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.
search?boolean | "auto""auto"Search box in the panel; "auto": with more than 15 nodes.
placeholder?string"Seçiniz"Text shown when nothing is selected.
defaultExpanded?readonly string[] | "all"Initially expanded nodes; "all" for all. If omitted the paths of the selected nodes expand.
icon?IconPropIcon at the start of the box.
clearable?booleanfalseClear button.
showPath?booleanfalseShow the selection's path in the box too ("Türkiye / İstanbul / Kadıköy")?
pathSeparator?string" / "showPath separator.
variant?FieldVariant"outline"Field appearance.
open?booleanIs the panel open, in controlled use?
onOpenChange?(open: boolean) => voidWhen the panel opens or closes.
aria-label?stringScreen reader name; give it when there is no visible label.
style?StyleProp<ViewStyle>Container style.
checkOutput?CheckOutput"leaves"Which nodes go into the value? See CheckOutput.(MultiTreeSelectProps<T>)
checkMode?"cascade" | "independent""cascade""cascade": a parent is linked to its children (tri-state); "independent".(MultiTreeSelectProps<T>)
maxDisplay?number2Maximum names written in the box; the rest become "+3".(MultiTreeSelectProps<T>)