Text input
Help users enter information with the text input component.
Read the Design System guidance for text input
Import
import { Input, InputField, InputPrefix, InputSuffix, InputWrapper } from 'govuk-react/input';Examples
Default
Code
<InputField
id="event-name"
name="event-name"
label="What is the name of the event?"
/>Input with hint text
Code
<InputField
id="event-name"
name="event-name"
label="What is the name of the event?"
hint="The name you’ll use on promotional material"
/>Input with hint text error
Code
<InputField
id="event-name"
name="event-name"
label="What is the name of the event?"
hint="The name you’ll use on promotional material"
errorMessage="Enter an event name"
/>With prefix and suffix
Code
<InputField
id="cost-per-item"
name="costPerItem"
label="What is the cost per item, in pounds?"
prefix="£"
suffix="per item"
width={5}
spellCheck={false}
/>With type and auto complete
Code
<InputField
id="email"
name="email"
label="Email address"
type="email"
autoComplete="email"
spellCheck={false}
/>As page heading
Code
<InputField
id="event-name"
name="event-name"
label="What is the name of the event?"
labelSize="l"
labelIsPageHeading
/>API reference
Input
Help users enter information with the text input component.
| Prop | Type |
|---|---|
error | boolean |
widthA number of characters, or a fraction of the container. | 2 | 3 | 4 | 5 | 10 | 20 | 30 | FluidWidth |
extraLetterSpacing | boolean |
InputField
Help users enter information with the text input component.
| Prop | Type |
|---|---|
labelSize | "s" | "m" | "l" | "xl" |
labelIsPageHeading | boolean |
widthA number of characters, or a fraction of the container. | 2 | 3 | 4 | 5 | 10 | 20 | 30 | FluidWidth |
extraLetterSpacing | boolean |
labelThe label used by the text input component. | ReactNode |
hintCan be used to add a hint to a text input component. | ReactNode |
errorMessageCan be used to add an error message to the text input component. The error message component will not display if you use a falsy value for | ReactNode |
prefixCan be used to add a prefix to the text input component. | ReactNode |
suffixCan be used to add a suffix to the text input component. | ReactNode |
InputPrefix
No props of its own. Other props are passed to the element it renders.
InputSuffix
No props of its own. Other props are passed to the element it renders.
InputWrapper
No props of its own. Other props are passed to the element it renders.