Skip to content

Commit

Permalink
updated Pagination and select to ensure more WCAG compliancy
Browse files Browse the repository at this point in the history
  • Loading branch information
remko48 committed Jan 30, 2024
1 parent eb431c5 commit 8df53e5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/components/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface PaginationProps {
currentPage: number;
setCurrentPage: React.Dispatch<React.SetStateAction<number>>;
ariaLabels: {
pagination: string;
nextPage: string;
previousPage: string;
page: string;
Expand All @@ -28,6 +29,32 @@ export const Pagination: React.FC<PaginationProps> = ({
}) => {
if (totalPages < 1) return <></>; // no pages available

const setAttributes = (): void => {
const setRoleToPresentation = (selector: string) => {
document.querySelectorAll(selector).forEach((element) => {
if (element.getAttribute("role") !== "list") element.setAttribute("role", "list");
});
};

setRoleToPresentation('ul[role*="navigation"][class*="Pagination"][aria-label="Pagination"]');
};

React.useEffect(() => {
setAttributes();
}, []);

React.useEffect(() => {
const setRoleToPresentation = (selector: string) => {
document.querySelectorAll(selector).forEach((element) => {
if (element.getAttribute("aria-label") !== ariaLabels.pagination) {
element.setAttribute("aria-label", ariaLabels.pagination);
}
});
};

setRoleToPresentation('ul[role*="list"][class*="Pagination"]');
}, [ariaLabels.pagination]);

return (
<ReactPaginate
className={clsx(styles.container, layoutClassName && layoutClassName)}
Expand Down
3 changes: 3 additions & 0 deletions src/components/formFields/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ const setAttributes = (): void => {
const setRoleToPresentation = (selector: string, role: string) => {
document.querySelectorAll(selector).forEach((element) => {
if (element.getAttribute("role") !== "presentation") element.setAttribute("role", role);
element.removeAttribute("aria-relevant");
element.removeAttribute("aria-atomic");
element.removeAttribute("aria-live");
});
};

Expand Down

0 comments on commit 8df53e5

Please sign in to comment.