TreeSelect

Generates a hierarchical select input.

View on Storybook

View source on GitHub

Import

import { TreeSelect } from '@wordpress/components';

Props

NameTypeDefaultRequiredDescription
noOptionLabelstring

If this property is added, an option will be added with this label to represent empty selection.

onChangeSelectControlSingleSelectionProps[ 'onChange' ]

A function that receives the value of the new option that is being selected as input.

treeTree[]

An array containing the tree objects with the possible nodes the user can select.

selectedIdSelectControlSingleSelectionProps[ 'value' ]

The id of the currently selected node.

Examples

Default

const Default = ( props ) => {
	const [ selection, setSelection ] =
		useState< ComponentProps< typeof TreeSelect >[ 'selectedId' ] >();

	return (
		<TreeSelect
			__next40pxDefaultSize
			{ ...props }
			onChange={ setSelection }
			selectedId={ selection }
		/>
	);
};