A complete input field with integrated label and description.
import { InputControl } from '@wordpress/ui';
LinksPermalink to this section
PropsPermalink to this section
| Name | Default | Description |
|---|---|---|
details |
Additional information about the field, which unlike a normal description, can include links and other semantic elements. Do not use this prop when the content is only plain text;
use | |
label Required |
The accessible label. All controls must be labeled. | |
style |
CSS style to apply to the element. | |
disabled |
Whether the field is disabled. | |
type |
The type of the input element. | |
value |
The value to use in controlled mode. | |
defaultValue |
The default value to use in uncontrolled mode. | |
className |
CSS class name to apply to the element. | |
prefix |
Element to render before the input. | |
description |
The accessible description, associated using For screen reader accessibility, this should only contain plain text, and no semantics such as links. | |
size |
The size of the field. | |
suffix |
Element to render after the input. | |
render |
Replaces the component’s default HTML element using a given React element, or a function that returns a React element. | |
hideLabelFromVision | false |
Whether to visually hide the label while keeping it accessible to screen readers. |
onValueChange |
Callback fired when the |
ExamplesPermalink to this section
DefaultPermalink to this section
const Default = () => <InputControl
label="Label"
description="This is the description."
placeholder="Placeholder" />;
Visually Hidden LabelPermalink to this section
const VisuallyHiddenLabel = () => <InputControl hideLabelFromVision />;
With DetailsPermalink to this section
const WithDetails = () => <InputControl description={undefined} details={DETAILS_EXAMPLE} />;
With PrefixPermalink to this section
const WithPrefix = () => <InputControl ref={undefined} />;
With Suffix ControlPermalink to this section
const WithSuffixControl = () => <InputControl ref={undefined} />;
PasswordPermalink to this section
const Password = () => {
const [ show, setShow ] = useState( false );
return (
<InputControl
defaultValue="password"
type={ show ? 'text' : 'password' }
suffix={
<InputLayout.Slot padding="minimal">
<IconButton
label={ show ? 'Hide password' : 'Show password' }
onClick={ () => setShow( ! show ) }
icon={ show ? unseen : seen }
size="small"
variant="minimal"
/>
</InputLayout.Slot>
} />
);
};
DatePermalink to this section
const Date = () => <InputControl type="date" />;
NumberPermalink to this section
const Number = () => <InputControl placeholder="0" type="number" />;
Number With SteppersPermalink to this section
const NumberWithSteppers = () => {
const [ value, setValue ] = useState( 0 );
return (
<InputControl
type="number"
value={ value }
onValueChange={ ( v ) => setValue( parseInt( v, 10 ) ) }
suffix={
<InputLayout.Slot padding="minimal">
<Stack direction="row" gap="xs">
<IconButton
label="Increment"
icon={ plus }
onClick={ () => setValue( value + 1 ) }
size="small"
variant="minimal"
/>
<IconButton
label="Decrement"
icon={ reset }
onClick={ () => setValue( value - 1 ) }
size="small"
variant="minimal"
/>
</Stack>
</InputLayout.Slot>
} />
);
};
DisabledPermalink to this section
const Disabled = () => <InputControl disabled />;