Skip to content

Commit

Permalink
fix: month not being localized with dropdown-years caption layout
Browse files Browse the repository at this point in the history
  • Loading branch information
gpbl committed Sep 28, 2024
1 parent b9e92d5 commit 5e7f3ae
Show file tree
Hide file tree
Showing 3 changed files with 437 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/DayPicker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { user } from "@/test/user";
import { DayPicker } from "./DayPicker";
import { MonthProps } from "./components/Month";
import { MonthsProps } from "./components/Months";
import { es } from "./locale";

const testId = "test";
const dayPicker = () => screen.getByTestId(testId);
Expand Down Expand Up @@ -193,3 +194,15 @@ describe("when not interactive", () => {
expect(document.body).toHTMLValidate();
});
});

describe("should localize the calendar", () => {
const today = new Date(2024, 10, 25);

beforeAll(() => jest.setSystemTime(today));
afterAll(() => jest.useRealTimers());

test("should use the custom locale", () => {
render(<DayPicker locale={es} />);
expect(document.body).toMatchSnapshot();
});
});
5 changes: 4 additions & 1 deletion src/DayPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,10 @@ export function DayPicker(props: DayPickerProps) {
/>
) : (
<span role="status" aria-live="polite">
{formatMonthDropdown(calendarMonth.date.getMonth())}
{formatMonthDropdown(
calendarMonth.date.getMonth(),
locale
)}
</span>
)}
{captionLayout === "dropdown" ||
Expand Down
Loading

0 comments on commit 5e7f3ae

Please sign in to comment.