Skip to main content
Skip to sidebar

TreeSelect

Designer doc
TreeSelect is an input component to select a value from an tree-structure option list.

Example

Basic Usage
View code
An icon button can be used to trigger dropdown selection too.
View code
Rendering from data
Different from Ant Design’s TreeSelect, Coral’s doesn’t include tree rendering from data inside the component, rather a utility function renderFromData is provided.
View code
In case you want to search locally within a tree, instead of using TreeSelectNode or renderFromData, you can use TreeSelectSearchableNodes inside TreeSelectList.
This component handles nodes pruning and expandedValues based on searchValue and the data you provided (same schema as utility function renderFromData). You only need to pass data prop and filter function.
Client side search
Search
View code
Note that searching in TreeSelect is a really complicated thing - ease of usage has some tradeoffs with flexibility, and TreeSelectSearchableNodes chooses for the former. While TreeSelectSearchableNodes component should never introduce any breaking changes, another new search component may be created if this component cannot cover all use cases.
By default, TreeSelectSearchableNodes will set expandedValues state to display all matched search nodes on every searchValue changes.
To customize a little bit how the expand state behaves, you can pass:
  • resetExpandedTo: array of values. This is different from expandedValues and initialExpandedValues in TreeSelect because this is triggered on query changes.
  • skip: either boolean or function accepting query. If the result is true, it includes all nodes and will set expandedValues to resetExpandedTo.
That said, the default value of resetExpandTo is [] (empty array), and skip is query => !query.length.
Below is an example of “Search only if query has more than 3 characters”.
More search options
Search
View code
More Examples
View code

Accessibility

  • Right arrow:
    • When focus is on a closed node, opens the node; focus and selection do not move.
    • When focus is on a open node, moves focus to the first child node and selects it if it is selectable.
    • When focus is on an end node, does nothing.
  • Left arrow:
    • When focus is on an open node, closes the node.
    • When focus is on a child node that is also either an end node or a closed node, moves focus to its parent node and selects it if it is selectable.
    • When focus is on a root node that is also either an end node or a closed node, does nothing.

Relevant components

References

API

TreeSelect
Prop nameTypeDefaultDescription
expandedValuesSelectValue[]
idstring
initialExpandedValuesSelectValue[][]
initialIsOpenboolean
initialKeyboardHighlightedIndexnumber
initialMouseHighlightedIndexnumber
initialSearchValuestring
initialSelectedIndexnumber
initialValueSelectValue
isOpenboolean
keyboardHighlightedIndexnumber
mouseHighlightedIndexnumber
onChangeChangeCallback
Called when selected value is changed. Different from onSelect, onChange is not called when the value is already selected.
onExpandedValuesChange(expanded: SelectValue[]) => void
onIsOpenChange(isOpen: boolean) => void
onKeyboardHighlightedIndexChange(index: number) => void
onMouseHighlightedIndexChange(index: number) => void
onSearchSearchCallback
onSelectChangeCallback
Different from onChange: onSelect is triggered even if the option's value is the selected one.
onSelectedIndexChange(index: number) => void
searchValuestring
This is not the selected value. Rather, it's a search value on input if you use SelectSearch.
selectedIndexnumber
stateReducerAcdcStateReducer(state, { nextState }) => nextState
valueSelectValue
TreeSelectButton
Prop nameTypeDefaultDescription
asany
Tag or component, but a simple tag (i.e. built-in components, e.g. div, span) is recommended.
disabledboolean
Equivalent to button's disabled property.
keyboardClickKeysstring[]
onBlurFocusEventHandler<HTMLDivElement>
onClickMouseEventHandler<HTMLDivElement>
onKeyDownKeyboardEventHandler<HTMLDivElement>
onKeyUpKeyboardEventHandler<HTMLDivElement>
onMouseDownMouseEventHandler<HTMLDivElement>
onMouseLeaveMouseEventHandler<HTMLDivElement>
onMouseUpMouseEventHandler<HTMLDivElement>
onReleaseEventHandler<SyntheticEvent<HTMLDivElement, Event>>
Callback that's triggered after click i.e. mouseup and keyup of enter or space.
onTouchEndTouchEventHandler<HTMLDivElement>
onTouchStartTouchEventHandler<HTMLDivElement>
placeholderReactNode
rightElementReactNode
TreeSelectHighlighter
Prop nameTypeDefaultDescription
textstring
TreeSelectIconButton
Prop nameTypeDefaultDescription
asany
Tag or component, but a simple tag (i.e. built-in components, e.g. div, span) is recommended.
badgePropsOmit<BadgeProps, "children">
colorTypeColorTypes
Set color based on theme. If color is specified, that prop is used instead of this.
disabledboolean
Equivalent to button's disabled property.
keyboardClickKeysstring[]
loadingboolean
onBlurFocusEventHandler<HTMLDivElement>
onClickMouseEventHandler<HTMLDivElement>
onKeyDownKeyboardEventHandler<HTMLDivElement>
onKeyUpKeyboardEventHandler<HTMLDivElement>
onMouseDownMouseEventHandler<HTMLDivElement>
onMouseLeaveMouseEventHandler<HTMLDivElement>
onMouseUpMouseEventHandler<HTMLDivElement>
onReleaseEventHandler<SyntheticEvent<HTMLDivElement, Event>>
Callback that's triggered after click i.e. mouseup and keyup of enter or space.
onTouchEndTouchEventHandler<HTMLDivElement>
onTouchStartTouchEventHandler<HTMLDivElement>
radiusstring
showBadgeboolean
sizeIconButtonSizes
tooltipReactNode
tooltipPropsOmit<TooltipProps, "title" | "children">
variantIconButtonVariants
TreeSelectList
Prop nameTypeDefaultDescription
acdcScrollerPropsOptionsUseAcdcScrollerPropsOptions
Options for the useAcdcScrollerProps hook
asany
Tag or component, but a simple tag (i.e. built-in components, e.g. div, span) is recommended.
containerHTMLElement
containerPropsDivProps
elevationLevelnumber
emptyPlaceholderReactNode
footerReactNode
headerReactElement<any, any>
immediateboolean
linedboolean
placement"left" | "right" | "bottom" | "top" | "top-start" | "top-end" | "left-start" | "left-end" | "right-start" | "right-end" | "bottom-start" | "bottom-end"
popperReferenceHTMLElement
popperUpdateKeystring
widthSelectListWidth
TreeSelectListFooter
Prop nameTypeDefaultDescription
asany
Tag or component, but a simple tag (i.e. built-in components, e.g. div, span) is recommended.
TreeSelectListSearch
Prop nameTypeDefaultDescription
asany
Tag or component, but a simple tag (i.e. built-in components, e.g. div, span) is recommended.
autoComplete"on" | "off" | "nope"
disabledboolean
fullWidthboolean
width: 100% is too troublesome to handle with custom css because of the nesting
invalidboolean
leftElementReactNode
leftElementContainerPropsHTMLAttributes<HTMLDivElement> & { ref?: MutableRefObject<HTMLDivElement>; }
onChange(e: ChangeEvent<HTMLInputElement>) => void
onTextChange(val: string) => void
placeholderReactNode
readOnlyboolean
rightElementReactNode
rightElementContainerPropsHTMLAttributes<HTMLDivElement> & { ref?: MutableRefObject<HTMLDivElement>; }
type"number" | "text" | "password"
wrapperPropsWrapperProps
TreeSelectNode
Prop nameTypeDefaultDescription
asany
Tag or component, but a simple tag (i.e. built-in components, e.g. div, span) is recommended.
childrenNodesPropsChildrenNodesProps
disabledboolean
expandButtonReactNode<TreeSelectNodeExpand />
indexnumber
labelReactNode<>{value}</>
leftElementReactNode
nodePropsNodeProps
valueSelectValue
TreeSelectNodeExpand
Prop nameTypeDefaultDescription
asany
Tag or component, but a simple tag (i.e. built-in components, e.g. div, span) is recommended.
colorTypeColorTypes
Set color based on theme. If color is specified, that prop is used instead of this.
disabledboolean
Equivalent to button's disabled property.
keyboardClickKeysstring[]
loadingboolean
onBlurFocusEventHandler<HTMLDivElement>
onClickMouseEventHandler<HTMLDivElement>
onKeyDownKeyboardEventHandler<HTMLDivElement>
onKeyUpKeyboardEventHandler<HTMLDivElement>
onMouseDownMouseEventHandler<HTMLDivElement>
onMouseLeaveMouseEventHandler<HTMLDivElement>
onMouseUpMouseEventHandler<HTMLDivElement>
onReleaseEventHandler<SyntheticEvent<HTMLDivElement, Event>>
Callback that's triggered after click i.e. mouseup and keyup of enter or space.
onTouchEndTouchEventHandler<HTMLDivElement>
onTouchStartTouchEventHandler<HTMLDivElement>
radiusstring
sizeIconButtonSizes
tooltipReactNode
tooltipPropsOmit<TooltipProps, "title" | "children">
variantIconButtonVariants
TreeSelectSearch
Prop nameTypeDefaultDescription
asany
Tag or component, but a simple tag (i.e. built-in components, e.g. div, span) is recommended.
autoComplete"on" | "off" | "nope"
contentPropsSelectSelectedContentProps
disabledboolean
fullWidthboolean
width: 100% is too troublesome to handle with custom css because of the nesting
invalidboolean
leftElementReactNode
leftElementContainerPropsHTMLAttributes<HTMLDivElement> & { ref?: MutableRefObject<HTMLDivElement>; }
onChange(e: ChangeEvent<HTMLInputElement>) => void
onTextChange(val: string) => void
placeholderReactNode
readOnlyboolean
rightElementReactNode
rightElementContainerPropsHTMLAttributes<HTMLDivElement> & { ref?: MutableRefObject<HTMLDivElement>; }
type"number" | "text" | "password"
wrapperPropsWrapperProps
TreeSelectSearchableNodes
Prop nameTypeDefaultDescription
dataTreeData
filter(node: TreeNode, query: string) => boolean
Different from FilterNode in utils.
renderFromData(data: TreeData) => ReactNode
resetExpandedToSelectValue[][]
skipboolean | ((query: string) => boolean)
    Example
    Example
    Basic Usage
    Basic Usage
    Rendering from data
    Rendering from data
    Client-side search
    Client-side search
    Managing client-side search
    Managing client-side search
    More Examples
    More Examples
    Accessibility
    Accessibility
    Relevant components
    Relevant components
    References
    References
    API
    API
    TreeSelect
    TreeSelect
    TreeSelectButton
    TreeSelectButton
    TreeSelectHighlighter
    TreeSelectHighlighter
    TreeSelectIconButton
    TreeSelectIconButton
    TreeSelectList
    TreeSelectList
    TreeSelectListFooter
    TreeSelectListFooter
    TreeSelectListSearch
    TreeSelectListSearch
    TreeSelectNode
    TreeSelectNode
    TreeSelectNodeExpand
    TreeSelectNodeExpand
    TreeSelectSearch
    TreeSelectSearch
    TreeSelectSearchableNodes
    TreeSelectSearchableNodes
Coral is a thoroughly developed design system widely adopted by developers and designers for creating beautiful and user-friendly Sea internal products.

Copyright © 2018-2025 Sea Labs