Skip to content

Commit 8435e8f

Browse files
authored
Merge pull request #20471 from calixteman/bug1998046_1
Aria-hide the text content part of a MathML formula (bug 1998046)
2 parents 615965f + 87b3b52 commit 8435e8f

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

β€Žtest/integration/accessibility_spec.mjsβ€Ž

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,20 @@ describe("accessibility", () => {
336336
expect(mathML)
337337
.withContext(`In ${browserName}`)
338338
.toEqual(
339-
" <msqrt><msup><mi>x</mi><mn>2</mn></msup></msqrt> <mo>=</mo> <mrow><mo>|</mo><mi>x</mi><mo>|</mo></mrow> "
339+
` <msqrt><msup><mi>x</mi><mn>2</mn></msup></msqrt> <mo>=</mo> <mrow intent="absolute-value($x)"><mo>|</mo><mi arg="x">x</mi><mo>|</mo></mrow> `
340340
);
341+
342+
// Check that the math corresponding element is hidden in the text
343+
// layer.
344+
const ariaHidden = await page.$eval("span#p58R_mc13", el =>
345+
el.getAttribute("aria-hidden")
346+
);
347+
expect(ariaHidden).withContext(`In ${browserName}`).toEqual("true");
341348
} else {
342-
pending(`Sanitizer API (in ${browserName}) is not supported`);
349+
// eslint-disable-next-line no-console
350+
console.log(
351+
`Pending in Chrome: Sanitizer API (in ${browserName}) is not supported`
352+
);
343353
}
344354
})
345355
);
@@ -379,7 +389,10 @@ describe("accessibility", () => {
379389
'<math display="block"> <msup> <mi>𝑛</mi> <mi>𝑝</mi> </msup> <mo lspace="0.278em" rspace="0.278em">=</mo> <mi>𝑛</mi> <mspace width="1.000em"></mspace> <mi> mod </mi> <mspace width="0.167em"></mspace> <mspace width="0.167em"></mspace> <mi>𝑝</mi> </math>'
380390
);
381391
} else {
382-
pending(`Sanitizer API (in ${browserName}) is not supported`);
392+
// eslint-disable-next-line no-console
393+
console.log(
394+
`Pending in Chrome: Sanitizer API (in ${browserName}) is not supported`
395+
);
383396
}
384397
})
385398
);

β€Žweb/struct_tree_layer_builder.jsβ€Ž

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,18 @@ class StructTreeLayerBuilder {
341341
element.setHTML(node.mathML, {
342342
sanitizer: MathMLSanitizer.sanitizer,
343343
});
344+
// Hide all the corresponding content elements in the text layer in
345+
// order to avoid screen readers reading both the MathML and the
346+
// text content.
347+
for (const { id } of node.children || []) {
348+
if (!id) {
349+
continue;
350+
}
351+
const elem = document.getElementById(id);
352+
if (elem) {
353+
elem.ariaHidden = true;
354+
}
355+
}
344356
}
345357
if (
346358
!node.mathML &&

0 commit comments

Comments
Β (0)