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
MM/DD/YYYY
With timezone options for timezone selector
MM/DD/YYYY
Basic usage
Business Hours
States
Clearable
Disabled
Error
Date Constraints
Min Date
Max Date
Date Picker With Multiple Months
Date Picker With Format string
Date Picker With Fixed Height
Date Picker With Overrides
Stateless Datepicker
API
Date Picker props
Name | Type | Default | Description |
---|---|---|---|
autoSizeInput | boolean | false | Adjusts the width according to value |
clearable | boolean | false | If true, adds a clear value icon button to the end of the input container. |
disableTimezoneSwitch | boolean | false | If true, will not allow user to switch the timezone |
disabled | boolean | false | Renders 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. | |
getDefaultTime | function | called when a value is undefined and a new date is selected | |
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 | true | Defines if dates outside of the range of the current month are displayed. |
showTimezone | boolean | false | If 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 | true | Determines if TimePicker component will be enabled for start time |
timezone | string | System Timezone | Currently selected timezone. |
timezoneOptions | array | A list of timezones to show in timezone input component | |
trapTabbing | boolean | false | Defines 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
- StyledDay
- StyledInputWrapper
- StyledMonth
- StyledMonthContainer
- StyledMonthHeader
- StyledMonthYearSelectButton
- StyledMonthYearSelectIconContainer
- StyledNextButton
- StyledPrevButton
- StyledRoot
- StyledSelectorContainer
- StyledWeek
- StyledWeekdayHeader
- formatDate
- useDatePickerState