Skip to main content
DateInput
@coinbase/cds-web@8.38.5
DateInput is a text input field for entering dates by typing. The input automatically formats dates based on the user's locale.
import { DateInput } from '@coinbase/cds-web/dates/DateInput'
Related components

DateInput uses TextInput for entering dates by typing. Check out DatePicker if you would like Calendar to be shown in a popup as well.

Basics

DateInput requires controlled state for both the date value and error state. The component automatically formats dates based on the user's locale and validates input on blur.

Loading...

Validation

Minimum and maximum dates

Use minDate and maxDate props to restrict the date range. Provide the disabledDateError prop to show an error when users enter a date outside the allowed range.

Loading...

Disabled dates

The disabledDates prop accepts an array of Date objects or [Date, Date] tuples to disable specific dates or ranges.

Loading...

Custom validation

Use the DateInputValidationError class to create custom error states for application-specific validation rules.

Loading...

Accessibility

DateInput inherits accessibility props from TextInput. If no accessibilityLabel is passed, it will use the label as the accessibilityLabel. If you want an accessibilityLabel that differs from the label, you can set this prop.

Here, since no accessibilityLabel is passed, the accessibilityLabel will be "Birthdate".

<DateInput label="Birthdate" />

Example of passing an accessibilityLabel. For web, this will set aria-label="Enter your date of birth" under the hood.

<DateInput accessibilityLabel="Enter your date of birth" label="Birthdate" />
Accessibility tip

Like any component system, much of the responsibility for building accessible UIs is in your hands as the consumer to properly implement the component composition. We'll do our best to provide sane fallbacks, but here are the biggest gotchas for DateInputs you can watch out for.


Error message format

It's advised you always format error messages with Error: ${errorMessage}. We'd do that for you, but i18n isn't baked into CDS. DateInput automatically switches to variant="negative" when an error is present.

Localization

The date format automatically adjusts based on the LocaleContext provided by LocaleProvider.

Loading...

Styling

DateInput supports the same styling functionality as TextInput.

Compact

Use the compact prop for a smaller input size.

Loading...

Disabled

Loading...

Helper text

Loading...

Label

If you need to render a custom label (e.g. a label with a tooltip), you can use the labelNode prop.

Loading...

Required

Use the required prop to indicate that the field is mandatory. Provide requiredError to display a message if the user blurs the input without a date after typing.

Loading...

Variants

Use the variant prop to change the visual style of the input.

Loading...

Separator

Customize the date format separator using the separator prop. Defaults to /.

Loading...

Event Lifecycle

The DateInput fires events in a specific order:

  • Typing a date in a blank DateInput:

    onChange -> onChange -> ... -> onChangeDate -> onErrorDate

  • Typing a date in a DateInput that already had a date:

    onChange -> onChangeDate -> onChange -> onChange -> ... -> onChangeDate -> onErrorDate

Is this page useful?

Coinbase Design is an open-source, adaptable system of guidelines, components, and tools that aid the best practices of user interface design for crypto products.