Skip to content

[bug]: Calendar doesn't honor locale in the month selection button #8430

@EndBug

Description

@EndBug

Describe the bug

The month selection dropdown will always render the month labels in the "default" locale, instead of honoring the on passed in props.

Here you can see a Calendar in Italian, where the months are still in English (which is the OS language of the user)
Image

The culprit:

formatters={{
formatMonthDropdown: (date) =>
date.toLocaleString("default", { month: "short" }),
...formatters,
}}

Affected component/components

Calendar

How to reproduce

Create a localized Calendar component like this:

import { format } from "date-fns";
import { it, enGB } from "react-day-picker/locale";

// ...

<Calendar
  mode="single"
  selected={date}
  captionLayout="dropdown"
  month={month}
  onMonthChange={setMonth}
  onSelect={(newDate) => {
    handleDateChange(newDate);
    setOpen(false);
  }}
  locale={locale === "it" ? it : enGB}
  labels={{
    labelDayButton: (date, { today, selected }) => {
      let label = format(date, "PPPP", {
        locale: locale === "it" ? it : enGB,
      });
      if (today) label = `${t("today")}, ${label}`;
      if (selected) label = `${label}, ${t("selected")}`;
      return label;
    },
    labelWeekNumber: (weekNumber) => `${t("week")} ${weekNumber}`,
    labelNext: () => t("nextMonth"),
    labelPrevious: () => t("previousMonth"),
    labelMonthDropdown: () => t("selectMonth"),
    labelYearDropdown: () => t("selectYear"),
    
  }}
/>

Codesandbox/StackBlitz link

https://codesandbox.io/p/devbox/g3dp2h

Logs

System Info

User timezone: Europe/Rome
Browser/OS language: en-US
Desired component locale: it

Before submitting

  • I've made research efforts and searched the documentation
  • I've searched for existing issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions