JGuang

TreeSelect

TreeSelect · Arco Design

Preview
npm install @arco-design/web-react@2.66.18

TreeSelect

Can choose tree structure data.Only Single choice is supports.

Install

npm install @arco-design/web-react@2.66.18

Import @arco-design/web-react/dist/css/arco.css at the entry and set the locale with ConfigProvider. React 19 projects must also import @arco-design/web-react/es/_util/react-19-adapter first, or imperative APIs such as Message and Modal cannot render.

Examples

  • Basic: Basic usage example.
  • Value Format: When labelInValue is true, the format of value is: { label: string, value: string }.
  • custom render: Under single selection, the rendering display can be customized through renderFormat
  • Front label: Specify addBefore to add elements before the select box. (2.41.0)
  • Form TreeData: Generate a tree structure by treeData.
  • Controlled: Controlled mode.
  • Dynamic Loading: Load nodes dynamically via loadMore. At this time, isLeaf can be set to indicate leaf nodes.
  • Search: Set showSearch=true to enable the search function. You can only search in the loaded data during dynamic loading. The default keyword search is to match from the value field. You can also pass in filterTreeNode to customize the filtering method.
  • Remote search: Custom search can be enabled when the passed onSearch is a function, and data can be loaded remotely.
  • Size: Four sizes (small, default, large, huge) can be selected through size. The height corresponds to 24px, 32px, 36px, 40px.
  • Customize Trigger: Set triggerElement to customize the display.
  • Multiple Selection: Multiple Selection
  • Checkable: The treeCheckable property can display checkbox.
  • Check Strategy: Customize the return value through the treeCheckStrategy property.
  • Customize Dropdown: Use dropdownRender to freely expand the drop-down menu.
  • Control Collapse: The dropdown expanded by default. Use popupVisible and onVisibleChange to control the expansion and collapse of the dropdown. For example, in this demo, onVisibleChange is triggered when the mouse moves out of the dropdown and the popup, the parameter is false, and the dropdown box is collapsed. For details on triggering onVisibleChange, please refer to Trigger
  • Customize treeData: You can customize treeData by fieldNames.
  • Virtual List: By specifying treeProps.virtualListProps to turn on the virtual list, high performance can be obtained when a large amount of data is used.
  • Draggable: In multiple mode, specify the dragToSort property to allow sort the entered values by dragging.

Examples come from the official Arco Design repository (MIT) at the commit published as npm 2.66.18. Some use online images or upload endpoints; network requests are disabled in previews.

API

TreeSelect

PropertyDescriptionTypeDefaultValueVersion
allowClearWhether allow to clear selected optionsboolean--
animationWhether to add animation for internal label changesbooleantrue2.15.0
borderedWhether show borderbooleantrue-
disabledWhether is disabledboolean--
dragToSortWeather it is possible to sort tags by dragboolean-2.27.0
errorWhether the textarea is error.(Deprecated, removed in the next major version, use status='error' instead)boolean--
labelInValueSetting value format.The default is string, when set to true, the value format will turn to: { label: string, value: string }boolean--
loadingWhether is in loadingboolean--
multipleWhether to select multipleboolean--
popupVisibleWhether the popup is visible or notboolean--
treeCheckableWhether to show checkboxboolean--
treeCheckStrictlyWhether the parent and child nodes are relatedboolean--
unmountOnExitWhether to destroy the DOM after hidingboolean--
inputValueTo set input search valuestring-2.39.0
placeholderPlaceholder of elementstring--
autoWidthauto width. minWidth defaults to 0, maxWidth defaults to 100%| boolean| { minWidth?: CSSProperties['minWidth']; maxWidth?: CSSProperties['maxWidth'] }-2.54.0
fieldNamesCustom field name for key, title, isLeaf, disabled and childrenTreeProps['fieldNames']DefaultFieldNames2.11.0
maxTagCountThe maximum number of tags is displayed, only valid in multiple and label mode. Setting the number of responsive responsive display tags is not recommended when there are many options, as there may be performance issues.| number| 'responsive'| {count: number | 'responsive';render?: (invisibleTagCount: number) => ReactNode;}-Object type in 2.37.0. responsive in 2.62.0
sizeHeight of element, 24px 28px 32px 36px'mini' | 'small' | 'default' | 'large'--
statusStatus'error' | 'warning'-2.45.0
treeCheckedStrategyCustomize the return valueTreeProps['checkedStrategy']all-
addBeforeThe label text displayed before (on the left side of) the select fieldReactNode-2.41.0
clearIconConfigure the icon of the clear button when allowClear.ReactNode-2.26.0
notFoundContentThe content display when no dataReactNode--
prefixCustomize select suffixReactNode-2.11.0
suffixIconCustomize select suffix iconReactNode--
arrowIconCustomize select arrow icon.ReactNode | null--
classNameAdditional css classstring | string[]--
defaultValueThe key of node selected by default| string| string[]| { label: ReactNode; value: string; disabled?: boolean }| { label: ReactNode; value: string; disabled?: boolean }[]--
dropdownMenuStyleThe additional css style for dropdown menuCSSProperties-2.3.0
removeIconCustomize the delete icon of tags selected in multiple and label mode.ReactNode | null--
showSearchWhether single mode Select is searchable. { retainInputValue: true } to retain the existing content when the search box is focused,{ retainInputValueWhileSelect: true } to retain the existing content when multiple selection is selected.boolean | { retainInputValue?: boolean; retainInputValueWhileSelect?: boolean }--
styleAdditional styleCSSProperties--
treeDataThe data of treeTreeSelectDataType[]--
treePropsThe props of the Tree componentPartial<TreeProps>--
triggerPropsThe props of the Trigger componentPartial<TriggerProps>--
valueThe key of the selected node| string| string[]| { label: ReactNode; value: string; disabled?: boolean }| { label: ReactNode; value: string; disabled?: boolean }[]--
dropdownRenderCustomize dropdown rendering(dom: ReactNode) => ReactNode-2.3.0
filterTreeNodeFilter data based on entered value. Accepted two parameters, inputText and treeNode.When the option matches the filter conditions, it returns true, otherwise it returns false. treeNode is the tree node.(inputText, treeNode: any) => boolean | void--
getPopupContainerThe parent node of the popup(node: HTMLElement) => Element--
loadMoreCallback when loaded data asynchronously(treeNode: NodeProps, dataRef) => void--
onChangeCallback when the selection changed(value: any,extra: {trigger?: NodeProps;checked?: boolean;selected?: boolean;}) => void-extra in 2.29.0
onClearCallback when clicked clear, the parameter is the visible state of current dropdown(visible: boolean) => void--
onClickCallback when the mouse clicks on the drop-down box(e) => void--
onInputValueChangeCallback when the search value of input is changed.(value: string, reason: InputValueChangeReason) => void-2.39.0
onKeyDownCallback when keyboard pressed(e) => void-2.40.0
onSearchCallback when searching data. When undefined, it will search in the data already(inputValue: string) => void--
onVisibleChangeCallback when the visibility of the popup is changed(visible: boolean) => void--
renderFormatCustomize the content that will be displayed in the Select.If the Option corresponding to value does not exist, the first parameter will be null(option: NodeProps | null, value: string | LabelValue) => ReactNode-2.46.0
renderTagCustom tag rendering, props is the current tag attribute, index is the order of the current tag, values is the value of all tags(props: {value: any;label: ReactNode;closable: boolean;onClose: (event) => void;},index: number,values: ObjectValueType[]) => ReactNode-index、values added in 2.15.0
triggerElementCustomize the trigger elementReactNode | ((params: { value: any }) => ReactNode)-() => ReactNode in 2.31.0

LabelValue

export type LabelValue = {
  label: ReactNode;
  value: string;
  disabled?: boolean;
};

FieldNamesType

export type FieldNamesType = {
  key?: string;
  title?: string;
  disabled?: string;
  children?: string;
  isLeaf?: string;
  disableCheckbox?: string;
  checkable?: string;
};

TreeSelectDataType

export type TreeSelectDataType = TreeDataType & {
  value?: string;
};

TreeDataType

export type TreeDataType = NodeProps & {
  key?: string;
  _index?: number;
  children?: TreeDataType[];
  [key: string]: any;
};

InputValueChangeReason

// 造成输入框值改变的原因:用户输入、选中选项、选项下拉框收起
export type InputValueChangeReason =
  | "manual"
  | "optionChecked"
  | "optionListHide";

ObjectValueType

export type ObjectValueType = {
  value?: any;
  label?: ReactNode;
  closable?: boolean;
};