Examples
Code
React
Name | Type | Default | Description |
---|---|---|---|
name required | string | The input field's name attribute | |
onBlur | (event: FocusEvent<HTMLInputElement, Element>) => any | Called anytime any date input is blurred | |
onChange required | (updatedValue: string, formattedValue: string) => any | Called anytime any date input is changed. This function is called with two arguments.
The first argument should be used to update whatever state your application uses to
supply back to this component's value prop in a controlled component pattern.
@param updatedValue - The input's new value
@param formattedValue - The input's new value with date formatting applied, included
for convenience. Do not use this value as the component's value prop. An appropriate
use for this value would be to run date-validation checks against it. | |
value | string | Sets the input's value . Use in combination with an onChange handler to implement
a controlled component pattern. This component expects the value to match
whatever string the user types (i.e., the first argument provided to your onChange
handler). | |
defaultMonth | Date | The initial month to show in the calendar picker. If not provided, defaults to the month of the currently selected date. | |
fromDate | Date | Earliest day to start month navigation in the calendar picker. (This does not restrict dates entered manually.) | |
fromMonth | Date | Earliest month to start month navigation in the calendar picker. (This does not restrict dates entered manually.) | |
fromYear | number | Earliest year to start month navigation in the calendar picker. (This does not restrict dates entered manually.) | |
toDate | Date | Latest day to end month navigation in the calendar picker. (This does not restrict dates entered manually.) | |
toMonth | Date | Latest month to end month navigation in the calendar picker. (This does not restrict dates entered manually.) | |
toYear | number | Latest year to end month navigation in the calendar picker. (This does not restrict dates entered manually.) | |
className | string | Additional classes to be added to the root element. | |
errorPlacement | "top" | "bottom" | Location of the error message relative to the field input | |
id | string | A unique id for the field element. Useful for referencing the field from
other components with aria-describedby . | |
label required | ReactNode | Label for the field. | |
labelClassName | string | Additional classes to be added to the field label | |
labelId | string | A unique id to be used on the field label. If one isn't provided, a unique ID
will be generated. | |
errorMessage | ReactNode | Enable the error state by providing an error message. | |
errorMessageClassName | string | Additional classes to be added to the error message | |
errorId | string | The ID of the error message applied to this field. | |
hint | ReactNode | Additional hint text to display | |
inversed | boolean | Set to true to apply the "inverse" theme | |
requirementLabel | ReactNode | Text showing the requirement (ie. "Optional", or "Required"). In most cases, this should be used to indicate which fields are optional. See the form guidelines for more info. | |
textClassName | string | Additional classes to be added to the label text. |
Styles
The following CSS variables can be overridden to customize Input/Form components:
Form components
This component also makes use of form field styles, which can be customized by the following variables:
Guidance
When to use
- Use the date input when your user flow does not require separate fields for month, day, and year.
- Use the date input for most dates, particularly memorable dates like date of birth, marriage date, health coverage start or end dates, or income start date.
When to consider alternatives
- Don't use if users are entering a date within the last year or a future date. Instead, use the date picker.
Usage
Allow users to have flexibility in entering the date, such as allowing one-digit numbers with or without "0" prior to the number, or entering a date with or without slashes to separate month, day, and year.
- Example: "1" as well as "01" for a month or day.
- Example: "05/01/2022" as well as "05012022".
Accessibility
- These text fields should follow the accessibility guidelines for all text inputs.
- Users will be able to enter a variety of date formats that automatically format to the correct date format of MM/DD/YYYY. This change happens once the form field loses focus. For example, a user enters a date as "4122020" and it changes to "04/01/2020" once focus leaves the date input.
Related components
Component maturity
For more information about how we tested and validated our work for each checklist item, read our component maturity documentation.