Skip to main content

Date Picker Button

The Date Picker Button is a Popover widget which allows for either a single date or a date range selection.

There are two types of date ranges: static and dynamic. The difference between them is that dynamic date ranges are relative to today's date, while static date ranges are fixed regardless of time. If users choose one of the specified date ranges on the period selector sidebar, except of Custom, they start working with dynamic date ranges. Interacting directly on the calendar lets deal with static date ranges.

Example

Live Editor
Result
Loading...

Variants

Custom Current Date

You can pass currentDate. Its value will be assigned to "today" and relative dates will be calculated relatively to it.

Live Editor
Result
Loading...

Custom Dates Formatting

You can use a customDateFormat property to format dates inside trigger button as you will.

Live Editor
Result
Loading...

Date and time formatting and hourly periods

You can use showTime property to show dates with date-time format. Also, when showTime is provided, we include hourly relative periods in popover side menu. Current hourly relative periods supported are: last-hour and last-24-hours.

Live Editor
Result
Loading...

Disabled

You can use prop disabled to disabled the selection.

Live Editor
Result
Loading...

Hide Clear Button

You can hide the clear button with isClearButtonHidden prop.

Live Editor
Result
Loading...

onClear callback

you can use onClear to run a function when clear button is clicked

Live Editor
Result
Loading...

Relative Date Options Formatting

You can use a relativeDateOptions property to manage the Date Options.

The props accepts only array of Period, an ENUM from DatePickerButton utils.

Live Editor
Result
Loading...

Translate

You can use a getElementLabel property to define the text for all available elements within the DatePicker. This function will be called with one of the following values as an argument:

type DatePickerButtonTextElements =
| 'last-hour'
| 'today'
| 'yesterday'
| 'last-7-days'
| 'last-14-days'
| 'last-30-days'
| 'last-3-months'
| 'this-month'
| 'last-month'
| 'this-week'
| 'last-week'
| 'custom'
| 'start-date-label'
| 'end-date-label'
| 'cancel-button'
| 'apply-button';

Each value matches the element within the DatePicker, e.g. 'apply-button' specifies the label for the Apply button etc.

Also, you will need to use the locale prop to set a localized version of the Months and Date Range values.

Do:

  • Always provide locale code with the locale prop to the component when using the getElementLabel prop.
info

Supported languages:

English (Default), Chinese, French, German, Japanese, Korean, Portuguese, Russian, Spanish, Turkish, Vietnamese

Live Editor
Result
Loading...

Props

NameTypeDefault
startDate
The beginning date of the selected date range. Should be provided when working with a static date range. If 'period' prop provided it will be ignored.
Date | null
null
endDate
The end date of the selected date range. Should be provided when working with a static date range. If 'period' prop provided it will be ignored.
Date | null
null
period
Allows to set a dynamic date range. If provided 'startDate' and 'endDate' props will be ignored. To work with static date ranges it should be undefined. Please use values from Period enum for this prop: Today, Yesterday, Last7Days, Last14Days, Last30Days, Last3Months, LastMonth, LastWeek, ThisMonth, ThisWeek.
"last-hour" | "last-24-hours" | "today" | "yesterday" | "last-7-days" | "last-14-days" | "last-30-days" | "last-3-months" | "last-month" | "this-month" | "last-week" | "this-week"
relativeDateOptions
Allows to provide Date Options, if empty provide all options
Period[]
[]
onApply
The handler will be called after clicking Apply button
((dateRange: DateRange) => void)
onClear
The handler will be called after clicking Clear button
(() => void)
getElementLabel
Use this prop to override the default elements texts and labels. DatePickerButtonTextElements contains elements: | 'period-today' | 'period-yesterday' | 'period-last-7-days' | 'period-last-14-days' | 'period-last-30-days' | 'period-last-3-months' | 'custom' | 'start-date-label' | 'end-date-label' | 'cancel-button' | 'apply-button' | 'this-month' | 'last-month' | 'this-week' | 'last-week'
((element: DatePickerButtonTextElements) => string)
customDateFormat
Use this function to format dates inside trigger button
((date: Date) => string)
minDate
The earliest date the user can select
Date
maxDate
The latest date the user can select
Date
currentDate
The custom date to be used as the current date. If undefined, the machine current date is used.
string | number | Date
currentMonthPosition
Use this prop to set the position of the current month
"left" | "right"
"right"
aria-label
Provide at least one label(visual or non-visual) property for better accessibility. Check Accessibility page for more info: Link
string
zIndex
Add z-index rule to the pop-over window
number | "auto"
"auto"
locale
Use this prop to set localization for the date values
"tr" | "en" | "de" | "es" | "fr" | "ja" | "ko" | "pt" | "ru" | "vi" | "zh"
"'en' as LocaleCode"
showTime
Include time in date format
boolean
false
isClearButtonHidden
Determines whether the clear button is hidden
boolean
false
disabled
Allow to disable the selection
boolean
false
data-{foo}
Data attributes can be used by testing libraries to retrieve components or assert their existence
string
* - the prop is required.