Skip to content

Commit e7144fa

Browse files
committed
fix: page header adjacent hidden link
Moves page header image link adjacent to image, with aria-hidden, to allow its exclusion from screen reader and tab order, but allowing reading of any alt text entered in the content.
1 parent 3f110a3 commit e7144fa

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

blocks/page-header/page-header.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@
9191
height: 100%;
9292
}
9393

94+
.page-header__image {
95+
position: relative;
96+
}
97+
98+
.page-header__image > a::after {
99+
content: "";
100+
display: block;
101+
inset: 0;
102+
position: absolute;
103+
}
104+
105+
.page-header__image picture {
106+
display: block;
107+
}
108+
94109
.page-header__image img {
95110
display: block;
96111
max-width: 100%;

blocks/page-header/page-header.js

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -98,31 +98,24 @@ export default async function decorate(block) {
9898
// Add image or video if they exist.
9999
if (pageHeaderData.visual) {
100100
if (pageHeaderData.visual?.nodeName == "PICTURE") {
101-
// Image
102-
let pageHeaderVisual = pageHeaderData.visual;
101+
// Image:
102+
const visualWrapper = document.createElement("div");
103+
visualWrapper.classList.add("page-header__image", "grid-item", "grid-item--50");
103104

104-
// If there's a link, wrap the image in an anchor.
105+
// If there's a link, add it adjacent to image.
105106
if (pageHeaderData.anchorNode) {
106-
const wrappingAnchor = document.createElement("a");
107-
wrappingAnchor.setAttribute("href", anchorHref);
108-
109-
// Give the link a proper accessible name.
110-
wrappingAnchor.setAttribute("aria-label", pageHeaderData.altText ? pageHeaderData.altText : pageHeaderData.title);
111-
112-
// Treat image as decorative. It is already described by the adjacent text.
113-
const imgElement = pageHeaderVisual.querySelector('img');
114-
if (imgElement) {
115-
imgElement.setAttribute("alt","");
116-
}
117-
118-
wrappingAnchor.append(pageHeaderVisual);
119-
pageHeaderVisual = wrappingAnchor;
107+
const imageAnchor = document.createElement("a");
108+
imageAnchor.setAttribute("href", anchorHref);
109+
// Allows clicking image but prevents repetitive link text from being read.
110+
imageAnchor.setAttribute("aria-hidden", "true");
111+
imageAnchor.setAttribute("tabindex", "-1");
112+
visualWrapper.append(imageAnchor);
120113
}
121-
122-
pageHeaderVisual.classList.add("page-header__image", "grid-item", "grid-item--50");
123-
pageHeader.append(pageHeaderVisual);
114+
115+
visualWrapper.append(pageHeaderData.visual);
116+
pageHeader.append(visualWrapper);
124117
} else {
125-
// Video
118+
// Video:
126119
const embedCode = pageHeaderData.visual?.innerText?.trim();
127120
if (embedCode.startsWith("<iframe")) {
128121
// Create a figure and populate it with the embed code.

0 commit comments

Comments
 (0)