Skip to content

Commit

Permalink
Merge pull request #4693 from plahteenlahti/fix/aria-labels-on-weekdays
Browse files Browse the repository at this point in the history
fix: Add aria-label to read the day of the week instead of the shorthand
  • Loading branch information
martijnrusschen authored Apr 15, 2024
2 parents 5e9cfa4 + fd4c02e commit 1c6546f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/calendar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ export default class Calendar extends React.Component {
return (
<div
key={offset}
aria-label={formatDate(day, "EEEE", this.props.locale)}
className={clsx("react-datepicker__day-name", weekDayClassName)}
>
{weekDayName}
Expand Down
31 changes: 31 additions & 0 deletions test/calendar_test.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1882,6 +1882,37 @@ describe("Calendar", () => {
});
});

it("should add the aria-label correctly to day names", () => {
const expectedAriaLabels = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
];

const { container } = render(
<Calendar
dateFormat={DATE_FORMAT}
onSelect={() => {}}
onClickOutside={() => {}}
/>,
);

const header = container.querySelector(".react-datepicker__header");
const dayNameElements = header.querySelectorAll(
".react-datepicker__day-name",
);

dayNameElements.forEach((element, index) => {
expect(element.getAttribute("aria-label")).toBe(
expectedAriaLabels[index],
);
});
});

it("should have a next-button with the provided aria-label for year", () => {
const ariaLabel = "A label in my native language for next year";
const { container } = render(
Expand Down

0 comments on commit 1c6546f

Please sign in to comment.