SearchControl components let users display a search control.
import { SearchControl } from '@wordpress/components';
LinksPermalink to this section
PropsPermalink to this section
| Name | Default | Description |
|---|---|---|
value |
The current value of the input. | |
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 | |
__next40pxDefaultSize |
| |
__nextHasNoMarginBottom | false |
Start opting into the new margin-free styles that will become the default in a future version. |
hideLabelFromVision | true |
If true, the label will only be visible to screen readers. |
label | __( 'Search' ) |
The accessible label for the input. A label should always be provided as an accessibility best practice,
even when a placeholder is defined and |
onChange Required |
A function that receives the value of the input when the value is changed. | |
onClose |
When an Use this if you want the button to trigger your own logic to close the search field entirely, rather than just clearing the input value. | |
onDrag |
| |
onDragStart |
| |
onDragEnd |
| |
placeholder | __( 'Search' ) |
A placeholder for the input. |
size | 'default' |
The size of the component |
ExamplesPermalink to this section
DefaultPermalink to this section
const Default = ( {
onChange,
...props
} ) => {
const [ value, setValue ] = useState< string >();
return (
<SearchControl
{ ...props }
value={ value }
onChange={ ( ...changeArgs ) => {
setValue( ...changeArgs );
onChange( ...changeArgs );
} }
/>
);
};