Generates a hierarchical select input.
import { TreeSelect } from '@wordpress/components';
LinksPermalink to this section
PropsPermalink to this section
| Name | Default | Description |
|---|---|---|
noOptionLabel |
If this property is added, an option will be added with this label to represent empty selection. | |
onChange |
A function that receives the value of the new option that is being selected as input. | |
tree | [] |
An array containing the tree objects with the possible nodes the user can select. |
selectedId |
The id of the currently selected node. | |
label |
If this property is added, a label will be generated using label property as the content. | |
children |
As an alternative to the | |
disabled | false |
If true, the |
prefix |
Renders an element on the left side of the input. By default, the prefix is aligned with the edge of the input border, with no padding. If you want to apply standard padding in accordance with the size variant, wrap the element in the provided `} /> | |
__next40pxDefaultSize |
Start opting into the larger default height that will become the default size in a future version. | |
size | 'default' |
Adjusts the size of the input. |
variant | 'default' |
The style variant of the control. |
suffix |
Renders an element on the right side of the input. By default, the suffix is aligned with the edge of the input border, with no padding. If you want to apply standard padding in accordance with the size variant, wrap the element in the provided `} /> | |
help |
Additional description for the control. Only use for meaningful description or instructions for the control. An element containing the description will be programmatically associated to the BaseControl by the means of an | |
__nextHasNoMarginBottom |
Start opting into the new margin-free styles that will become the default in a future version. | |
hideLabelFromVision | false |
If true, the label will only be visible to screen readers. |
__next36pxDefaultSize | false |
Deprecated. Use |
options |
An array of option property objects to be rendered,
each with a | |
labelPosition | 'top' |
The position of the label. |
ExamplesPermalink to this section
DefaultPermalink to this section
const Default = ( props ) => {
const [ selection, setSelection ] =
useState< ComponentProps< typeof TreeSelect >[ 'selectedId' ] >();
return (
<TreeSelect
{ ...props }
onChange={ setSelection }
selectedId={ selection }
/>
);
};