Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add aria-label to read the day of the week instead of the shorthand #4693

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading