use-date-input - Build Your Own Date Picker
Getting StartedStateThemingCompositionDate FrameworksLocalization
Components
Hooks
AnimatedGroupAnimatedMonthGroupCalendarSingle DateDate RangeSetting Initial StateCustom Day RenderersBlock datesValidate Date RangesPropsCalendarProviderClickOutsideDayDayOfWeekHeaderHomeMonthMonthGroupPopperRootWeekWeekHeaderuseCalendarDispatchuseCalendarPropsuseCalendarStateuseDateAPIuseDateInputuseDateRangeInput

Calendar

The Calendar is the basic building block for all calendar controls. It supports

  • single or date ranges, via the configured reducers
  • any date framework, via the date adapter
  • theming
  • localisation, via the format method of the date adapter
  • a11y support

In the default implementation Calendar is used by the useDateInput and useDateRangeInput hooks but you can also use inline.
Alternatively you could use to compose your own date picker components or dialogs.

If you wrap your Calendar in a CalendarProvider it will use the state created by it, otherwise, it will internally rende the Calendar contents within a CalendarProvider. This optimization saves you having to wrap Calendars inside CalendarProvider, if you don't need to.

The render tree of Calendar

Calendar
|__ Root
|__ Header
|__ MonthGroup
|__ AnimatedMonthGroup
|__ AnimatedGroup
|__ Month
|__ MonthHeader
|__ WeekHeader
|__ Week
|__ DayOfWeek
|__ Day

Single Date

By default the Calendar will select single dates.

2021
June
Su
Mo
Tu
We
Th
Fr
Sa
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

Date Range

Using the allowRange prop the Calendar will select date ranges.

2021
June
Su
Mo
Tu
We
Th
Fr
Sa
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

Setting Initial State

The basic component operates as un-controlled, although the reducer pattern enables you to control the final state.
This example shows the basic use-case of the initial state.

2020
February
Su
Mo
Tu
We
Th
Fr
Sa
2627282930311
2345678
9101112131415
16171819202122
23242526272829
1234567
March
Su
Mo
Tu
We
Th
Fr
Sa
1234567
891011121314
15161718192021
22232425262728
2930311234
567891011
April
Su
Mo
Tu
We
Th
Fr
Sa
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789
May
Su
Mo
Tu
We
Th
Fr
Sa
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456
June
Su
Mo
Tu
We
Th
Fr
Sa
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011
July
Su
Mo
Tu
We
Th
Fr
Sa
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678
August
Su
Mo
Tu
We
Th
Fr
Sa
2627282930311
2345678
9101112131415
16171819202122
23242526272829
303112345
September
Su
Mo
Tu
We
Th
Fr
Sa
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910
October
Su
Mo
Tu
We
Th
Fr
Sa
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
November
Su
Mo
Tu
We
Th
Fr
Sa
1234567
891011121314
15161718192021
22232425262728
293012345
6789101112
December
Su
Mo
Tu
We
Th
Fr
Sa
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789
January
Su
Mo
Tu
We
Th
Fr
Sa
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456

Custom Day Renderers

Add your own renderers for Day, to render specific date states with your own styles, using the ccomponents prop.

2021
June
Mo
Tu
We
Th
Fr
Sa
Su
311234
7891011
1415161718
2122232425
28293012
56789
July
Mo
Tu
We
Th
Fr
Sa
Su
28293012
56789
1213141516
1920212223
2627282930
23456
August
Mo
Tu
We
Th
Fr
Sa
Su
2627282930
23456
910111213
1617181920
2324252627
3031123
September
Mo
Tu
We
Th
Fr
Sa
Su
3031123
678910
1314151617
2021222324
272829301
45678
October
Mo
Tu
We
Th
Fr
Sa
Su
272829301
45678
1112131415
1819202122
2526272829
12345
November
Mo
Tu
We
Th
Fr
Sa
Su
12345
89101112
1516171819
2223242526
2930123
678910
December
Mo
Tu
We
Th
Fr
Sa
Su
2930123
678910
1314151617
2021222324
2728293031
34567
January
Mo
Tu
We
Th
Fr
Sa
Su
2728293031
34567
1011121314
1718192021
2425262728
311234
February
Mo
Tu
We
Th
Fr
Sa
Su
311234
7891011
1415161718
2122232425
281234
7891011
March
Mo
Tu
We
Th
Fr
Sa
Su
281234
7891011
1415161718
2122232425
282930311
45678
April
Mo
Tu
We
Th
Fr
Sa
Su
282930311
45678
1112131415
1819202122
2526272829
23456
May
Mo
Tu
We
Th
Fr
Sa
Su
2526272829
23456
910111213
1617181920
2324252627
3031123

Block dates

Block out dates using a custom renderer and the isDayDisabled prop.

2021
June
Mo
Tu
We
Th
Fr
Sa
Su
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011
July
Mo
Tu
We
Th
Fr
Sa
Su
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678
August
Mo
Tu
We
Th
Fr
Sa
Su
2627282930311
2345678
9101112131415
16171819202122
23242526272829
303112345
September
Mo
Tu
We
Th
Fr
Sa
Su
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910
October
Mo
Tu
We
Th
Fr
Sa
Su
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
November
Mo
Tu
We
Th
Fr
Sa
Su
1234567
891011121314
15161718192021
22232425262728
293012345
6789101112
December
Mo
Tu
We
Th
Fr
Sa
Su
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789
January
Mo
Tu
We
Th
Fr
Sa
Su
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456
February
Mo
Tu
We
Th
Fr
Sa
Su
31123456
78910111213
14151617181920
21222324252627
28123456
78910111213
March
Mo
Tu
We
Th
Fr
Sa
Su
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910
April
Mo
Tu
We
Th
Fr
Sa
Su
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678
May
Mo
Tu
We
Th
Fr
Sa
Su
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

Validate Date Ranges

Validate date ranges with your own rules using the isRangeValid prop.

2021
June
Mo
Tu
We
Th
Fr
Sa
Su
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011
July
Mo
Tu
We
Th
Fr
Sa
Su
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678
August
Mo
Tu
We
Th
Fr
Sa
Su
2627282930311
2345678
9101112131415
16171819202122
23242526272829
303112345
September
Mo
Tu
We
Th
Fr
Sa
Su
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910
October
Mo
Tu
We
Th
Fr
Sa
Su
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
November
Mo
Tu
We
Th
Fr
Sa
Su
1234567
891011121314
15161718192021
22232425262728
293012345
6789101112
December
Mo
Tu
We
Th
Fr
Sa
Su
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789
January
Mo
Tu
We
Th
Fr
Sa
Su
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456
February
Mo
Tu
We
Th
Fr
Sa
Su
31123456
78910111213
14151617181920
21222324252627
28123456
78910111213
March
Mo
Tu
We
Th
Fr
Sa
Su
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910
April
Mo
Tu
We
Th
Fr
Sa
Su
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678
May
Mo
Tu
We
Th
Fr
Sa
Su
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

Props

Prop NameTypeIs RequiredDefault ValueDescription
adapterfuncoptionalDate API adapter
allowRangebooloptionalfalseWhen true will select a date range
ignoreClickOutsideRefsarrayoptional[]Array of refs to ignore clicks, when determining whether the user clicked outside the Calendar
initialSelectedDateobject or arrayoptionalThe initial selectedDate (for un-controlled use-case)
initialVisibleFromMonthobjectoptionalThe initial visible from calendar month (unless date is set)
isDayDisabledfuncoptionalCallback to set days as disabled @param day - Date to check @returns true when disabled
isRangeValidfuncoptionalCallback to determine whether the current selection is valid @param day - startDate @param day - endDate @returns true when valid
numOfColumnsnumberoptional1Number of columns
numOfVisibleMonthsnumberoptional1Number of visible months
onChangefuncoptionalSelected date change handler
onStateChangefuncoptionalState change handler
reducersarray of funcsoptionalReducer(s), to override default state
themeobjectoptionalTheme
weekOffsetnumberoptional0Start of week offset from date API's default