Skip to content

Commit 1240044

Browse files
authored
Merge pull request #78 from adobe/a11y-link-labels
fix(a11y): add aria-label for links to achieve 100 a11y scores
2 parents dd679f4 + 733dfb0 commit 1240044

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

scripts/scripts.js

+14
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ function buildAutoBlocks(main) {
6565
}
6666
}
6767

68+
function a11yLinks(main) {
69+
const links = main.querySelectorAll('a');
70+
links.forEach((link) => {
71+
let label = link.textContent;
72+
if (!label && link.querySelector('span.icon')) {
73+
const icon = link.querySelector('span.icon');
74+
label = icon ? icon.classList[1]?.split('-')[1] : label;
75+
}
76+
link.setAttribute('aria-label', label);
77+
});
78+
}
79+
6880
/**
6981
* Decorates the main element.
7082
* @param {Element} main The main element
@@ -77,6 +89,8 @@ export function decorateMain(main) {
7789
buildAutoBlocks(main);
7890
decorateSections(main);
7991
decorateBlocks(main);
92+
// add aria-label to links
93+
a11yLinks(main);
8094
}
8195

8296
/**

0 commit comments

Comments
 (0)