Skip to main content
DatePicker
@coinbase/cds-web@8.34.1
Date Picker allows our global users to input past, present, future and important dates into our interface in a simple and intuitive manner. Date Picker offers both manual and calendar entry options - accommodating both internationalization and accessibility needs while being adaptable across screen platforms.
Import
import { DatePicker } from '@coinbase/cds-web/dates/DatePicker'
SourceView source codeStorybookView StorybookFigmaView Figma (internal only)
Peer dependencies
  • framer-motion: ^10.18.0
Related components
View as Markdown

DatePicker combines DateInput with Calendar for date selection.

Basics

A basic DatePicker with the minimum props necessary for correct UX.

Loading...

Custom Label

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

Loading...

Invalid dates

Always provide the invalidDateError prop for when users type an impossible date like 99/99/2000.

Loading...

Validation

The DatePicker handles common error states internally, and calls onErrorDate when the validity / error state changes.

You can use the DateInputValidationError class to create custom error states.

Loading...

Accessibility

Always provide the accessibility label props and all necessary error props. See the Accessibility section under the Guidelines tab at the top of the page for more info.

Loading...

Localization

The date format is automatically adjusted to the LocaleContext. Check LocaleProvider usage below.

Loading...

Seeding the date

Defaults to today when undefined.

On web the seedDate prop is used to generate the Calendar month when there is no selected date value.

On mobile the seedDate prop is the default date that the react-native-date-picker keyboard control will open to when there is no selected date value.

Loading...

Required field

Make sure to provide the requiredError prop when setting the required prop to true. The requiredError will be displayed if a user blurs the input, without a date selected, after having typed into it.

Loading...

Highlighted dates

The highlightedDates prop is an array of Dates and Date tuples for date ranges. A number is created for every individual date within a tuple range, so do not abuse this with massive ranges.

The highlightedDates prop is only available on web because the mobile DatePicker uses react-native-date-picker instead of a Calendar component.

Loading...

Minimum and maximum dates

Make sure to provide the disabledDateError prop when providing minDate, maxDate, or disabledDates props. Navigation to dates before the minDate and after the maxDate is disabled.

Loading...

Disabled dates

The disabledDates prop is an array of Dates and Date tuples for date ranges. A number is created for every individual date within a tuple range, so do not abuse this with massive ranges.

The disabledDates prop is only available on web because the mobile DatePicker uses react-native-date-picker instead of a Calendar component.

Make sure to provide the disabledDateError prop when providing minDate, maxDate, or disabledDates props.

Loading...

Multiple pickers

This is a complex example using many different props. We use multiple DatePickers together to allow a user to select a date range.

We enforce that the time between the start date and end date must be at least 5 days but less than 14 days long, that the end date comes after the start date, and that all days are within the current month. We use the onChange prop to automatically suggest an end date of 1 week after the start date, or the last of the month - whichever is sooner. We also explicitly disable 1 week at the beginning of the month.

Loading...

Event lifecycle

  • Selecting a date with the native picker (mobile) or Calendar (web):

    onOpen -> onConfirm -> onChangeDate -> onErrorDate -> onClose

  • Closing the native picker (mobile) or Calendar (web) without selecting a date:

    onOpen -> onCancel -> onClose

  • 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

Loading...

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.