WeekPicker
Inline week, multiple weeks and weeks range picker
Source
Package
Usage
WeekPicker renders the same calendar as DatePicker, but selects whole weeks.
Hovering any day highlights its week and clicking selects it:
| # | Mo | Tu | We | Th | Fr | Sa | Su |
|---|---|---|---|---|---|---|---|
Week value
The value is a date string in YYYY-MM-DD format that points to the first day of the selected week.
The first day of the week is set by the firstDayOfWeek prop or by DatesProvider, Monday by default.
Use getStartOfWeek and getEndOfWeek exported from @mantine/dates to get the week boundaries from the value:
| # | Mo | Tu | We | Th | Fr | Sa | Su |
|---|---|---|---|---|---|---|---|
Value: –
Week: –
Allow deselect
Set allowDeselect to allow users to deselect the selected week by clicking on it, onChange is called with null.
allowDeselect is ignored when the type prop is range or multiple:
| # | Mo | Tu | We | Th | Fr | Sa | Su |
|---|---|---|---|---|---|---|---|
Multiple weeks
Set type="multiple" to allow users to pick multiple weeks:
| # | Mo | Tu | We | Th | Fr | Sa | Su |
|---|---|---|---|---|---|---|---|
Weeks range
Set type="range" to allow users to pick a weeks range. The value is a tuple of the first day of the
first week and the first day of the last week:
| # | Mo | Tu | We | Th | Fr | Sa | Su |
|---|---|---|---|---|---|---|---|
Single week in range
By default, clicking the same week twice deselects it, a single week cannot be selected as a range.
Set allowSingleDateInRange to allow it:
| # | Mo | Tu | We | Th | Fr | Sa | Su |
|---|---|---|---|---|---|---|---|
First day of week
Set the firstDayOfWeek prop to change which day starts the week, 0 is Sunday and 6 is Saturday.
It changes both the calendar layout and the emitted value:
| # | Su | Mo | Tu | We | Th | Fr | Sa |
|---|---|---|---|---|---|---|---|
Week controls
Every week number is a button that selects its week, days can be clicked with the mouse only.
Use getWeekControlProps to pass props to week controls, for example to disable specific weeks:
| # | Mo | Tu | We | Th | Fr | Sa | Su |
|---|---|---|---|---|---|---|---|
Presets
Use the presets prop to add custom week presets. Presets are displayed next to the calendar.
Any date inside the week can be used as a preset value:
| # | Mo | Tu | We | Th | Fr | Sa | Su |
|---|---|---|---|---|---|---|---|
To use presets with type="range", define the value as a tuple of two dates:
| # | Mo | Tu | We | Th | Fr | Sa | Su |
|---|---|---|---|---|---|---|---|
Default date
Use the defaultDate prop to set the month that is displayed initially.
defaultDate is ignored when the date prop is set:
| # | Mo | Tu | We | Th | Fr | Sa | Su |
|---|---|---|---|---|---|---|---|
Hide outside dates
Set hideOutsideDates to hide days of the selected week that are outside of the displayed month.
When numberOfColumns is larger than 1, outside dates are hidden by default,
set hideOutsideDates={false} to display whole weeks:
| # | Mo | Tu | We | Th | Fr | Sa | Su |
|---|---|---|---|---|---|---|---|
Controlling with useCalendar
WeekPicker component supports the controller pattern. Use the useCalendar hook to manage the displayed date and level.
The controller does not own the selected value, keep using value and onChange for it.
When the controller prop is set, the date and level props of the component are ignored, pass them to useCalendar instead:
| # | Mo | Tu | We | Th | Fr | Sa | Su |
|---|---|---|---|---|---|---|---|
Min and max date
Set the minDate and maxDate props to define minimum and maximum dates.
A week can be selected if it contains at least one enabled day, so the value can be before minDate:
| # | Mo | Tu | We | Th | Fr | Sa | Su |
|---|---|---|---|---|---|---|---|
Exclude dates
excludeDate disables individual days. A week that contains enabled days can still be selected through those days:
| # | Mo | Tu | We | Th | Fr | Sa | Su |
|---|---|---|---|---|---|---|---|
Add props to day, year and month control
Use getDayProps, getMonthControlProps and getYearControlProps to add props to the corresponding controls:
| # | Mo | Tu | We | Th | Fr | Sa | Su |
|---|---|---|---|---|---|---|---|
Number of columns
Set the numberOfColumns prop to define the number of pickers that will be rendered side by side:
| # | Mo | Tu | We | Th | Fr | Sa | Su |
|---|---|---|---|---|---|---|---|
| # | Mo | Tu | We | Th | Fr | Sa | Su |
|---|---|---|---|---|---|---|---|
Demo is not available on small screens. Make your screen larger to see the demo.
Max level
To disallow users from going to the decade level, set maxLevel="year":
| # | Mo | Tu | We | Th | Fr | Sa | Su |
|---|---|---|---|---|---|---|---|
Full width
Set the fullWidth prop to make the week picker stretch to fill 100% of its parent container width:
| # | Mo | Tu | We | Th | Fr | Sa | Su |
|---|---|---|---|---|---|---|---|
Size
| # | Mo | Tu | We | Th | Fr | Sa | Su |
|---|---|---|---|---|---|---|---|
Localization
Usually it is better to specify the @mantine/dates package locale in DatesProvider,
but you can also override the locale per component:
| # | пн | вт | ср | чт | пт | сб | вс |
|---|---|---|---|---|---|---|---|
Native level select
Set the withNativeLevelSelect prop to replace the calendar header level button with native <select> elements:
| # | Mo | Tu | We | Th | Fr | Sa | Su |
|---|---|---|---|---|---|---|---|
Accessibility
Aria labels
Set the ariaLabels prop to specify aria-label attributes for next/previous controls:
Week control aria-label
By default, the aria-label of a week control contains the first and the last day of the week.
Use getWeekControlProps to change it:
Keyboard interactions
Only week controls (week numbers) can be focused with the keyboard.
When presets are used, only one preset button is in the tab order.
ArrowDown and ArrowUp move focus between presets, Enter or Space selects the focused preset and Tab moves focus to the calendar.