Date input
Use the date input component to help users enter a memorable date.
Read the Design System guidance for date input
Import
import * as DateInput from 'govuk-react/date-input';Examples
Default
Code
<DateInput.Field
id="passport-issued"
namePrefix="passport-issued"
legend="When was your passport issued?"
hint="For example, 27 3 2007"
/>Date with default values
Code
<DateInput.Field
id="passport-issued"
namePrefix="passport-issued"
legend="When was your passport issued?"
hint="For example, 27 3 2007"
values={{ day: '27', month: '3', year: '2007' }}
/>Date with hint text error
Code
<DateInput.Field
id="passport-issued"
namePrefix="passport-issued"
legend="When was your passport issued?"
hint="For example, 27 3 2007"
errorMessage="The date your passport was issued must be in the past"
/>Date with custom items
Code
<DateInput.Field
id="passport-issued"
namePrefix="passport-issued"
legend="When does your passport expire?"
hint="For example, 3 2027"
>
{(
<>
<DateInput.Item>
<DateInput.Label htmlFor="expiry-month">Month</DateInput.Label>
<DateInput.Input id="expiry-month" name="expiry-month" width={2} />
</DateInput.Item>
<DateInput.Item>
<DateInput.Label htmlFor="expiry-year">Year</DateInput.Label>
<DateInput.Input id="expiry-year" name="expiry-year" width={4} />
</DateInput.Item>
</>
)}
</DateInput.Field>API reference
DateInput.Root
Use the date input component to help users enter a memorable date.
No props of its own. Other props are passed to the element it renders.
DateInput.Field
Use the date input component to help users enter a memorable date.
| Prop | Type |
|---|---|
legendSize | "s" | "m" | "l" | "xl" |
legendIsPageHeading | boolean |
valuesSpecify | { day?: string; month?: string; year?: string; } |
namePrefixOptional prefix. This is used to prefix each item | string |
legendRequiredThe legend for the fieldset used by the date input component. | ReactNode |
hintCan be used to add a hint to a date input component. | ReactNode |
errorMessageCan be used to add an error message to the date input component. The error message component will not display if you use a falsy value for | ReactNode |
DateInput.Input
| Prop | Type |
|---|---|
error | boolean |
widthA number of characters, or a fraction of the container. | 2 | 3 | 4 | 5 | 10 | 20 | 30 | FluidWidth |
extraLetterSpacing | boolean |
DateInput.Item
No props of its own. Other props are passed to the element it renders.
DateInput.Label
| Prop | Type |
|---|---|
size | "s" | "m" | "l" | "xl" |
isPageHeadingWhether the label also acts as the heading for the page. | boolean |