DatePicker

A simple and reusable component to work with or select a date or a range of dates.

Accessibility

  • Supports keyboard hotkeys: tab - to switch between inputs, arrows, monthyear select and day grid. escape to close datepicker dropdown.
  • When month and year selects focused, up and down causes dropdown to open and move to value, enter and space to choose selected year or month. When day grid is focused, left, down right and up to move through the grid days. Enter to pick date.
  • When left or right arrow is focused, enter causes the same as click on this arrow.
  • Accessibility best practices for this component (aria-valuenow, aria-valuetext, aria-valuemin, aria-valuemax, role=datepicker).

Examples

With timezone selector

Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.

With timezone options for timezone selector

Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.

Basic usage

Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.

Business Hours

Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.

States

Clearable
Disabled
Error
Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.
Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.
Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.
Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.
Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.
Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.

Date Constraints

Min Date
Max Date
Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.
Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.

Date Picker With Multiple Months

Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.Selected date is 05/09/2024.

Date Picker With Format string

Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.Selected date is 09–05–24.

Date Picker With Fixed Height

Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.

Date Picker With Overrides

Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.Selected date is 05/09/2024.

Stateless Datepicker

Press down arrow key to navigate quick select options and tab key to navigate to calendar. Press the down arrow key to interact with the calendar and select a date. Press the escape button to close the calendar.

API

Date Picker props

NameTypeDefaultDescription
autoSizeInput
boolean
falseAdjusts the width according to value
clearable
boolean
falseIf true, adds a clear value icon button to the end of the input container.
disableTimezoneSwitch
boolean
falseIf true, will not allow user to switch the timezone
disabled
boolean
falseRenders component in disabled state.
excludeDates
array
A list of dates to disable. Array<Date>
filterDate
function
A filter function (Date => boolean) that is called to check the disabled state of a day. If false is returned the day is considered to be disabled.
fixedHeight
boolean
Defines if 6 rows should always be displayed for all the months.
formatString
string
String format passed to date-fns.
getTimeRangesForDate
function
Allows to selectively show the options based on date
intent
'default'| 'success'| 'warning'| 'error'
Defines the intent of the Input.
maxDate
date
A max date that is selectable.
minDate
date
A min date that is selectable.
monthsShown
number
A number of months rendered in the calendar.
onChange
function
Event handler that is called when a new date is selected.
overrides
custom
Lets you customize all aspects of the component.
peekNextMonth
boolean
trueDefines if dates outside of the range of the current month are displayed.
showTimezone
boolean
falseIf true, shows the timezone picker within datepicker. If false will only hide picker. If user passes timezone, date adaption will continue to happen
size
'xs'| 'sm'| 'md'
Input's size. SPACIOUS | COMFORTABLE -> md, COMPACT -> xxxs, DEFAULT -> md
startOpen
boolean
If true, opens the dropdown when the date picker mounts.
timeSelect
boolean
trueDetermines if TimePicker component will be enabled for start time
timezone
string
System TimezoneCurrently selected timezone.
timezoneOptions
array
A list of timezones to show in timezone input component
trapTabbing
boolean
falseDefines if tabbing inside the calendar is circled within it.
value
date
Currently selected date (Date object).
variant
'default'| 'line'
Input's variant - default, line
weekStartsOn
number
Decides the start day of week. 0 indicates Sunday. This will depend on locale

Date Picker exports

You can import this module like so:

import {Calendar} from 'spaceweb/date-picker'

It exports the following components or utility functions:

  • Calendar
  • DEFAULT_FORMAT_STRING
  • DISABLE_WHOLE_DAY
  • DatePicker
  • DatePickerInput
  • DateTimeRangeInputs
  • ENABLE_WHOLE_DAY
  • StatelessDatePicker
  • StyledCalendarContainer
  • StyledCalendarHeader
  • StyledInputWrapper
  • StyledMonth
  • StyledMonthContainer
  • StyledMonthHeader
  • StyledMonthYearSelectButton
  • StyledMonthYearSelectIconContainer
  • StyledNextButton
  • StyledPrevButton
  • StyledRoot
  • StyledSelectorContainer
  • StyledWeek
  • StyledWeekdayHeader
  • formatDate
  • useDatePickerState