DatePicker
DatePicker is used when the user has to select a date or date range.
DatePicker is distributed in its own package and must be installed separately.
also known as Calendar
Props
Usage guidelines
- Allowing users to choose a date or date range by clicking through the calendar popup or typing in the text field.
- Limiting date options to a specific range of dates.
- When the native date picking experience is preferred (typically mobile and mWeb experiences). In this case, use TextField with type=”date”.
Accessibility
Variants
Basic Date Picker
Use DatePicker to select date inputs.
Preselected Date
Provide pre-selected date values to DatePicker.
Date Range Picker
Use DatePicker to select date range inputs.
Disabled
Delimited selection period
Disable dates outside of a min and max date range.
Enabled dates
Enable an array of dates.
Disabled dates
Disable an array of dates.
Helper Text
Display a helper message for cases where you want to provide more information about the date field.
Error Message
Display an error message. Error message overrides the helper text.
Ideal Direction
Define the preferred direction for the DatePicker popover to open. If that placement doesn't fit, the opposite direction will be used.
Supporting locales
Adjust the date format to each date-fns locale (https://date-fns.org/v2.14.0/docs/Locale).
The following locale examples show the different locale format variants.
IMPORTANT: Locale data from date-fns is external to gestalt-datepicker, it's not an internal dependency. Add date-fns to your app's dependencies.
import DatePicker from 'gestalt-datepicker';
import { it } from 'date-fns/locale';
<DatePicker localeData={it}/>
Component quality checklist
Quality item | Status | Status description |
---|---|---|
Figma Library | Partially ready | Component is live in Figma, however may not be available for all platforms. |
Responsive Web | Ready | Component is available in code for web and mobile web. |
iOS | Component is not currently available in code for iOS. | |
Android | Component is not currently available in code for Android. |