Skip to main content

TreeSelect

A tree-structured dropdown selector.

Source: Re-exported from antd with VEF hook enhancement. Full documentation: Ant Design TreeSelect

Basic Usage

import { TreeSelect } from '@vef-framework-react/components';

const treeData = [
{
value: 'parent1',
title: 'Parent 1',
children: [
{ value: 'child1', title: 'Child 1' },
{ value: 'child2', title: 'Child 2' },
],
},
];

export default function Demo() {
return (
<TreeSelect
style={{ width: 300 }}
treeData={treeData}
placeholder="Select a node"
/>
);
}

VEF Enhancement: useDataOptionsTreeSelect

Load tree data from an async source with built-in loading state and optional pinyin filtering. Fetch options are nested under queryOptions (the same shape TanStack Query's useQuery accepts); useDataOptionsTreeSelect-specific options sit alongside it.

import { TreeSelect, useDataOptionsTreeSelect } from '@vef-framework-react/components';

async function fetchOrgs() {
const res = await fetch('/api/orgs');
return res.json();
}

export default function Demo() {
const treeSelectProps = useDataOptionsTreeSelect({
queryOptions: {
queryKey: ['orgs'],
queryFn: fetchOrgs,
},
filterable: true,
});

return <TreeSelect style={{ width: 300 }} {...treeSelectProps} />;
}

useDataOptionsTreeSelect Options

OptionTypeDefaultDescription
queryOptionsUseQueryOptions<TQueryFnData[], TData[], TParams>requiredTanStack Query options (queryKey, queryFn, and the rest of useQuery's options)
filterablebooleanfalseEnable client-side text/pinyin filtering
onFetch(data: TData[]) => voidCallback after data is fetched
labelKeystring | (item: TData) => string"label"Field mapping for the node label
valueKeystring | (item: TData) => Key"value"Field mapping for the node value
disabledKeystring | (item: TData) => boolean | undefined"disabled"Field mapping for the disabled state
descriptionKeystring | (item: TData) => string | undefined"description"Field mapping for the node description
childrenKeystring | (item: TData) => TData[] | undefined"children"Field mapping for nested children (recursively transformed)

Each *Key option accepts either a string path (e.g. "user.name") or an extractor function.

useDataOptionsTreeSelect Result

The hook returns a ready-to-spread TreeSelectProps<Key, DataOptionWithPinyin<TData>> carrying:

FieldValueDescription
treeDataDataOptionWithPinyin<TData>[]The transformed tree, each node enhanced with precomputed pinyin for label and description
loadingbooleantrue while the query is fetching
fieldNames{ label, value, children }Maps DataOption's shape onto the tree select
maxTagCount'responsive'Collapses excess tags in multiple mode
listHeight280Dropdown list height
notFoundContentLoader while fetchingShows a loader instead of "no data" during the initial fetch
showSearchbooleanThe filterable flag
filterTreeNode(input, node) => booleanMatches label / description, their full pinyin, and pinyin initials (only set when filterable)
treeNodeFilterProp / treeNodeLabelProp'labelPinyinInitials' / 'label'Search matches against pinyin initials; the trigger displays the label
treeLine{ showLeafIcon: false }Connecting lines without leaf icons

For all other props, see Ant Design TreeSelect documentation.