Three text fields are the easiest way for users to enter most dates.
<DateField>
Code snippet
Props
Name | Type | Default | Description |
---|---|---|---|
autoComplete | boolean | Adds | |
dateFormatter | (...args: any[]) => any | Optional method to format the By default | |
label | React.ReactNode | The primary label, rendered above the individual month/day/year fields | |
labelId | string | A unique ID to be used for the MultiInputDateField label. If one isn't provided, a unique ID will be generated. | |
requirementLabel | React.ReactNode | Text showing the requirement ("Required", "Optional", etc.). See Required and Optional Fields. | |
onBlur | (...args: any[]) => any | Called anytime any date input is blurred | |
onComponentBlur | (...args: any[]) => any | Called when any date input is blurred and the focus does not land on one of the other date inputs inside this component (i.e., when the whole component loses focus) | |
onChange | (...args: any[]) => any | Called anytime any date input is changed | |
dayLabel | React.ReactNode | Label for the day field | |
dayName | string |
| |
dayDefaultValue | string | number | Initial value for the day | |
dayFieldRef | (...args: any[]) => any | Access a reference to the day | |
dayInvalid | boolean | Apply error styling to the day | |
dayValue | string | number | Sets the day input's | |
monthLabel | React.ReactNode | Label for the month field | |
monthName | string |
| |
monthDefaultValue | string | number | Initial value for the month | |
monthFieldRef | (...args: any[]) => any | Access a reference to the month | |
monthInvalid | boolean | Apply error styling to the month | |
monthValue | string | number | Sets the month input's | |
yearDefaultValue | string | number | Initial value for the year | |
yearFieldRef | (...args: any[]) => any | Access a reference to the year | |
yearInvalid | boolean | Apply error styling to the year | |
yearLabel | React.ReactNode | Label for the year | |
yearName | string |
| |
yearValue | string | number | Sets the year input's |
Guidance
When to use
- Use this format for most dates, particularly memorized dates.
When to consider alternatives
- If users are trying to schedule something, a calendar picker might make more sense. Be sure to also provide an option for text entry as well.
Usage
- Allow users to enter the date as flexibly as possible, for example, allowing
1
as well as01
for a month input. - Be sure each field is properly labeled — some countries enter dates in day, month, year order.
- It may be tempting to switch all or some of these text fields to drop downs, but these tend to be more difficult to use than text boxes.
- When handling date errors, if the part of the date that has an error is known, only highlight the part with an error. For example, if month and day are valid inputs, but the year is invalid, use
yearInvalid=true
so that only the year field will be highlighted red. - If the entire date is incorrect, all fields can be highlighted. For example, if a date in the past is required and a date in the future is entered, all fields should be highlighted.
Accessibility
- These text fields should follow the accessibility guidelines for all text inputs.
- Do not use JavaScript to auto advance the focus from one field to the next. This makes it difficult for keyboard-only users to navigate and correct mistakes.