Date picker
The date picker component allows merchants to select dates using a calendar interface. Use it when merchants benefit from seeing dates in context of the full month, such as selecting dates relative to today or needing weekday context.
The component supports single dates, multiple dates, and date ranges. For text date entry, use date field.
Anchor to DatePickerDate Picker
Configure the following properties on the date picker component.
- Anchor to defaultViewdefaultViewdefaultViewstringstringrequiredrequired
The default month to display in
format. Used until theviewcallback is set by user interaction or programmatically. Defaults to the current month in the user's locale.- Anchor to viewviewviewstringstringrequiredrequired
The currently displayed month in
format. When changed, theviewchangecallback is triggered. Defaults to.- Anchor to allowallowallowstringstringDefault: ""Default: ""requiredrequired
Specifies which dates can be selected as a comma-separated list. An empty string (default) allows all dates.
Formats:
: Single date: Whole month: Whole yearstart--end: Date range (inclusive, unbounded if start/end omitted)
Examples:
2024-02--2025: February 2024 through end of 20252024-05-09, 2024-05-11: Only May 9th and 11th, 2024
- Anchor to disallowdisallowdisallowstringstringDefault: ""Default: ""requiredrequired
Specifies which dates can't be selected as a comma-separated list. These dates are excluded from those specified in
allow. An empty string (default) has no effect.Formats:
: Single date: Whole month: Whole yearstart--end: Date range (inclusive, unbounded if start/end omitted)
Examples:
--2024-02: All dates before February 20242024-05-09, 2024-05-11: May 9th and 11th, 2024
- Anchor to allowDaysallowDaysallowDaysstringstringDefault: ""Default: ""requiredrequired
Specifies which days of the week can be selected as a comma-separated list. Further restricts dates from
allowanddisallow. An empty string (default) has no effect.Valid days:
sunday,monday,tuesday,wednesday,thursday,friday,saturdayExample:
saturday, sunday(only weekends)- Anchor to disallowDaysdisallowDaysdisallowDaysstringstringDefault: ""Default: ""requiredrequired
Specifies which days of the week can't be selected as a comma-separated list. Excludes days from
and intersects withallowanddisallow. An empty string (default) has no effect.Valid days:
sunday,monday,tuesday,wednesday,thursday,friday,saturdayExample:
saturday, sunday(no weekends)- Anchor to typetypetype"single" | "range""single" | "range"Default: "single"Default: "single"requiredrequired
The type of date selection allowed.
single: Select a single daterange: Select a date range
- Anchor to defaultValuedefaultValuedefaultValuestringstringDefault: ""Default: ""requiredrequired
The initially selected date(s) when the component first renders. An empty string means no date is initially selected.
- Single date in
format whentypeis set to"single" - Date range in
format (inclusive) whentypeis set to"range"
- Single date in
- Anchor to namenamenamestringstringrequiredrequired
The name attribute for the field, used to identify the field's value when the form is submitted. Must be unique within the nearest containing form.
- Anchor to valuevaluevaluestringstringDefault: ""Default: ""requiredrequired
The currently selected date(s). An empty string means no date is selected.
- Single date in
format whentypeis set to"single" - Date range in
format (inclusive) whentypeis set to"range"
- Single date in
Anchor to EventsEvents
The date picker component provides event callbacks for handling user interactions. Learn more about handling events.
- Anchor to blurblurblurCallbackEventListener<typeof tagName> | nullCallbackEventListener<typeof tagName> | nullrequiredrequired
A callback fired when the date picker loses focus.
Learn more about the blur event.
- Anchor to changechangechangeCallbackEventListener<typeof tagName> | nullCallbackEventListener<typeof tagName> | nullrequiredrequired
A callback fired when the date picker value changes.
Learn more about the change event.
- Anchor to focusfocusfocusCallbackEventListener<typeof tagName> | nullCallbackEventListener<typeof tagName> | nullrequiredrequired
A callback fired when the date picker receives focus.
Learn more about the focus event.
- Anchor to inputinputinputCallbackEventListener<typeof tagName> | nullCallbackEventListener<typeof tagName> | nullrequiredrequired
A callback fired when the user inputs data into the date picker.
Learn more about the input event.
- Anchor to viewchangeviewchangeviewchangeCallbackEventListener<typeof tagName> | nullCallbackEventListener<typeof tagName> | nullrequiredrequired
A callback fired when the calendar view changes, such as when navigating between months.
CallbackEventListener
A function that handles events from UI components. This type represents an event listener callback that receives a `CallbackEvent` with a strongly-typed `currentTarget`. Use this for component event handlers like `click`, `focus`, `blur`, and other DOM events.
(EventListener & {
(event: CallbackEvent<T>): void;
}) | nullCallbackEvent
An event object with a strongly-typed `currentTarget` property that references the specific HTML element that triggered the event. This type extends the standard DOM `Event` interface and ensures type safety when accessing the element that fired the event.
Event & {
currentTarget: HTMLElementTagNameMap[T];
}Anchor to ExamplesExamples
Anchor to Add a date range pickerAdd a date range picker
Add a calendar picker for selecting a date or date range. This example shows a range-type date picker with a pre-selected date range and a specific month view.
Preview
html
Anchor to Select a single dateSelect a single date
Configure the picker for single date selection when merchants need to choose one specific date. This example shows a single-type date picker with a pre-selected date and month view.
Preview
html
Anchor to Restrict selectable dates to a rangeRestrict selectable dates to a range
Restrict which dates merchants can select by defining an allowed range. This example shows a date picker that blocks past dates and limits selection to a specific month.
Preview
html
Anchor to Capture date selections with onChangeCapture date selections with on Change
Capture the selected date when the merchant makes a change so you can update your app state. This example shows a range picker inside a form with an onChange handler that stores the selected value.
Preview
html
Add preset buttons so merchants can quickly select common date ranges like "Last 7 days" or "This month." This example shows a range picker with quick-selection buttons that programmatically update the selected value.
Preview
html
Anchor to Best practicesBest practices
- Use smart defaults: Pre-populate the picker with sensible dates to speed up the selection process.
- Provide quick selections: Offer preset date options for common selections (like Today, Last 7 days, or This month) to improve usability.
- Use date ranges when appropriate: Enable range selection mode when merchants need to select start and end dates for reports, analytics, or time-based filters.
- Restrict dates appropriately: Use the
allowanddisallowproperties to prevent selection of invalid dates for your specific use case. - Provide adequate space: Ensure sufficient spacing around the picker to avoid interfering with on-screen keyboards or other interactive elements.
- Consider alternatives for distant dates: Navigating month-by-month becomes impractical for dates more than a few years away. For dates outside a 5-10 year range, consider providing date presets or manual year input.