Localization
Learn how to set the locale, adjust the week start day, and apply ISO Week Dates to enhance the user experience across different regions and languages.
Configure the Locale​
Prop Name | Type | Description |
---|---|---|
locale | Locale | Set the locale. Default is en-US . |
weekStartsOn | 1 | 2 | 3 | 4 | 5 | 6 | 7 | Display the days falling into the other months. |
firstWeekContainsDate | 1 | 4 | Configure the first date in the first week of the year. |
ISOWeek | boolean | Use ISO Week Dates. |
Set a Different Locale​
By default, the locale is set to English (US). To localize the calendar, pass a Locale
object to the locale
prop.
For example, to localize the calendar in Spanish, import the es
locale object from date-fns and pass it to the component.
import { es } from "date-fns/locale";
<DayPicker locale={es} />; // Set the locale to Spanish
lu | ma | mi | ju | vi | sá | do |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
First Date of the Week​
Utilize the weekStartsOn
prop to specify the starting day of the week.
<DayPicker locale={es} weekStartsOn={0} /> // Start the week on Domingo
do | lu | ma | mi | ju | vi | sá |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
First Week Contains Date​
The firstWeekContainsDate
prop can be used to change the first day of the week for the year's initial week, which is used in the calculation of week numbers.
Acceptable values are 1
for Monday and 4
for Thursday.
<DayPicker
showWeekNumber
firstWeekContainsDate={1} // First week must contain Monday
/>
Su | Mo | Tu | We | Th | Fr | Sa | |
---|---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | |||
6 | 7 | 8 | 9 | 10 | 11 | 12 | |
13 | 14 | 15 | 16 | 17 | 18 | 19 | |
20 | 21 | 22 | 23 | 24 | 25 | 26 | |
27 | 28 | 29 | 30 | 31 |
ISO Week Dates​
Use ISOWeek
to switch using ISO Week Dates instead of the locale setting.
<DayPicker
showWeekNumber
ISOWeek // Switch to ISO week
/>
Mo | Tu | We | Th | Fr | Sa | Su | |
---|---|---|---|---|---|---|---|
27 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
28 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
29 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
30 | 22 | 23 | 24 | 25 | 26 | 27 | 28 |
31 | 29 | 30 | 31 |
UTC Dates​
DayPicker uses the local time zone by default. To switch to UTC dates, add @date-fns/utc to your dependencies and import DayPicker
from react-day-picker/utc
instead.
The UTC mode is an experimental feature. Please report any issues you may encounter, thanks!
1. Install the @date-fns/utc
package​
- npm
- Yarn
- pnpm
npm install @date-fns/utc
yarn add @date-fns/utc
pnpm add @date-fns/utc
2. Import DayPicker
from react-day-picker/utc
​
- import { DayPicker } from 'react-day-picker';
+ import { DayPicker } from 'react-day-picker/utc';
3. Use DayPicker as usual​
import { UTCDate } from "@date-fns/utc";
import { DayPicker } from "react-day-picker/utc";
export function Utc() {
const [selected, setSelected] = React.useState<Date>(new UTCDate());
return (
<DayPicker
mode="single"
required
selected={selected}
onSelect={(date: Date) => {
setSelected(date);
}}
footer={selected ? `Selected: ${selected.toUTCString()}` : null}
/>
);
}
Observe how dates are always GMT.
Su | Mo | Tu | We | Th | Fr | Sa |
---|---|---|---|---|---|---|
Translate DayPicker​
These props will assist in translating the labels and formatters utilized in DayPicker.
Prop Name | Type | Description |
---|---|---|
labels | Labels | Map the ARIA labels used within DayPicker. |
formatters | Formatters | Map the function used as date formatters. |
dir | rtl | ltr | Set the text direction. |
ARIA Labels​
DayPicker utilizes ARIA labels to enhance screen reader accessibility. The labels
prop allows for customization of these ARIA labels. For additional information, please refer to the Accessibility guide.
<DayPicker
labels={{
labelNext: () => "Prossimo mese"
labelPrevious: () => "Mese precedente"
}}
/>
Function | Description |
---|---|
labelDay | The label for the day button. |
labelDayButton | The label for the day button. |
labelGrid | The label for the month grid, that will be announced when entering the grid. |
labelGridcell | The label for the day gridcell when the calendar is not interactive. |
labelMonthDropdown | The label for the months dropdown. |
labelNav | The label for the navigation toolbar, that will be announced when entering it. |
labelNext | The label for next month button. |
labelPrevious | The label for next month button. |
labelWeekNumber | The label for the week number element. |
labelWeekNumberHeader | The label for the week number header element. |
labelWeekday | The label for the Weekday element. |
labelYearDropdown | The label for the years dropdown. |
RTL Text Direction​
To set the right-to-left text direction, toggle the dir
prop to rtl
.
import { arSA } from "date-fns/locale";
<DayPicker locale={arSA} dir="rtl" />;
Ø£Øد | اثنين | ثلاثاء | أربعاء | خميس | جمعة | سبت |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 |