CustomSelectControl is a dropdown for selecting a single option from a
list, with support for custom styling. Use it instead of the SelectControl
when options need richer markup (e.g. per-option styles or hints).
import { CustomSelectControl } from '@wordpress/components';
LinksPermalink to this section
PropsPermalink to this section
| Name | Default | Description |
|---|---|---|
className |
Optional classname for the component. | |
hideLabelFromVision |
Hide the label visually, while keeping available to assistive technology. | |
describedBy |
Description for the select trigger button used by assistive technology. If no value is passed, the text “Currently selected: selectedItem.name” will be used fully translated. | |
label Required |
Label for the control. | |
onChange |
Function called with the control’s internal state changes. The | |
onBlur |
A handler for | |
onFocus |
A handler for | |
onMouseOut |
A handler for | |
onMouseOver |
A handler for | |
options Required |
The list of options that can be chosen from. | |
size | 'default' |
The size of the control. |
value |
Can be used to externally control the value of the control. | |
__experimentalShowSelectedHint |
Use the | |
showSelectedHint | false |
Show the hint of the selected item in the trigger button. |
__nextUnconstrainedWidth |
Opt-in prop for an unconstrained width style which became the default in WordPress 6.5. The prop is no longer needed and can be safely removed. | |
__next40pxDefaultSize |
Start opting into the larger default height that will become the default size in a future version. |
ExamplesPermalink to this section
DefaultPermalink to this section
const Default = ( props ) => {
const [ value, setValue ] = useState( props.options[ 0 ] );
const onChange: React.ComponentProps<
typeof CustomSelectControl
>[ 'onChange' ] = ( changeObject ) => {
setValue( changeObject.selectedItem );
props.onChange?.( changeObject );
};
return (
<CustomSelectControl
{ ...props }
onChange={ onChange }
value={ value }
/>
);
};
With Long LabelsPermalink to this section
const WithLongLabels = ( props ) => {
const [ value, setValue ] = useState( props.options[ 0 ] );
const onChange: React.ComponentProps<
typeof CustomSelectControl
>[ 'onChange' ] = ( changeObject ) => {
setValue( changeObject.selectedItem );
props.onChange?.( changeObject );
};
return (
<CustomSelectControl
{ ...props }
onChange={ onChange }
value={ value }
/>
);
};
With HintsPermalink to this section
const WithHints = ( props ) => {
const [ value, setValue ] = useState( props.options[ 0 ] );
const onChange: React.ComponentProps<
typeof CustomSelectControl
>[ 'onChange' ] = ( changeObject ) => {
setValue( changeObject.selectedItem );
props.onChange?.( changeObject );
};
return (
<CustomSelectControl
{ ...props }
onChange={ onChange }
value={ value }
/>
);
};