Skip to content

Commit 2542382

Browse files
Merge pull request #5659 from KeeganW/year-button-label-react-node
fix(calendar): Change type on YearButtonLabel to be the type ReactNode.
2 parents 9aae798 + 69ef33d commit 2542382

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/calendar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@ type CalendarProps = React.PropsWithChildren<
163163
onClickOutside: ClickOutsideHandler;
164164
outsideClickIgnoreClass?: string;
165165
previousMonthButtonLabel?: React.ReactNode;
166-
previousYearButtonLabel?: string;
166+
previousYearButtonLabel?: React.ReactNode;
167167
previousMonthAriaLabel?: string;
168168
previousYearAriaLabel?: string;
169169
nextMonthButtonLabel?: React.ReactNode;
170-
nextYearButtonLabel?: string;
170+
nextYearButtonLabel?: React.ReactNode;
171171
nextMonthAriaLabel?: string;
172172
nextYearAriaLabel?: string;
173173
showPreviousMonths?: boolean;

src/test/calendar_test.test.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,25 @@ describe("Calendar", () => {
403403
expect(nextButtonAriaLabel).toBe(nextButtonAriaLabel);
404404
});
405405

406+
it("should render by default aria labels for next and prev months buttons when providing a react node", () => {
407+
const previousMonthButtonLabel = <span>Custom react previous month</span>;
408+
const nextMonthButtonLabel = <span>Custom react next month</span>;
409+
const { calendar } = getCalendar({
410+
previousMonthButtonLabel,
411+
nextMonthButtonLabel,
412+
});
413+
414+
const previousButtonAriaLabel = calendar
415+
.querySelector(".react-datepicker__navigation--previous")
416+
?.getAttribute("aria-label");
417+
const nextButtonAriaLabel = calendar
418+
.querySelector(".react-datepicker__navigation--next")
419+
?.getAttribute("aria-label");
420+
421+
expect(previousButtonAriaLabel).toBe("Previous Month");
422+
expect(nextButtonAriaLabel).toBe("Next Month");
423+
});
424+
406425
it("should render the correct default aria labels for next and prev year buttons", () => {
407426
const { calendar } = getCalendar({ showYearPicker: true });
408427
const previousButtonAriaLabel = calendar
@@ -458,6 +477,26 @@ describe("Calendar", () => {
458477
expect(nextButtonAriaLabel).toBe(nextYearAriaLabel);
459478
});
460479

480+
it("should render by default aria labels for next and prev year buttons when providing a react node", () => {
481+
const previousYearButtonLabel = <span>Custom react previous year</span>;
482+
const nextYearButtonLabel = <span>Custom react next year</span>;
483+
const { calendar } = getCalendar({
484+
showYearPicker: true,
485+
previousYearButtonLabel,
486+
nextYearButtonLabel,
487+
});
488+
489+
const previousButtonAriaLabel = calendar
490+
.querySelector(".react-datepicker__navigation--previous")
491+
?.getAttribute("aria-label");
492+
const nextButtonAriaLabel = calendar
493+
.querySelector(".react-datepicker__navigation--next")
494+
?.getAttribute("aria-label");
495+
496+
expect(previousButtonAriaLabel).toBe("Previous Year");
497+
expect(nextButtonAriaLabel).toBe("Next Year");
498+
});
499+
461500
it("should not have previous month button when selecting a date in the second month, when min date is specified", () => {
462501
const minDate = new Date("2024-11-06");
463502
const maxDate = new Date("2025-01-01");

0 commit comments

Comments
 (0)