Repository navigation
fix(commons/text/visibleVirtual): separate the words around a visually hidden element - #5476
maricastroc wants to merge 1 commit into
Conversation
…y hidden element visibleVirtual leaves out the text of an element that is not visible and joins the text around it with no separator, so a visually hidden separator turns "No file chosen" and "Choose file" into the single word "chosenChoose". The accessible name keeps the hidden text, and with it that word boundary, so label-content-name-mismatch reports a violation for a button labelled by its own content. Return a space for an element that is rendered but has no visible text, as in the ACT definition of visible inner text, which gives such an element a single space. An element that is not rendered, or that has no width, still contributes nothing, so the words around a display: none element stay joined as they are on screen. Closes: dequelabs#5475
|
Thanks for the pr, however I'm not able to reproduce the problem. Testing the provided code passes Accessible name = |
|
@straker Thanks for taking a look! In your results Here is a self-contained repro with the styles the NHS.UK page applies: <style>
.visually-hidden {
position: absolute;
width: 1px;
height: 1px;
margin: 0;
padding: 0;
border: 0;
overflow: hidden;
white-space: nowrap;
clip-path: inset(50%);
}
.status {
display: block;
}
.group {
display: flex;
}
</style>
<label id="file-upload-label">Upload a file</label>
<button
id="file-upload"
type="button"
aria-labelledby="file-upload-label file-upload-comma file-upload"
><span class="status">No file chosen</span><span class="visually-hidden" id="file-upload-comma">, </span><span class="group">Choose file</span></button>
The live NHS.UK file upload example gives the same result: a violation on |
|
Thanks for the additional information. We have a lot of open prs at the moment so we'll try to get to this as soon as we can. |
Closes issue #5475
Problem
visibleVirtualleaves out the text of an element that is not visible and joins the text around it with no separator at all. When the hidden element is a separator, the words on either side of it become one:The styles and the missing whitespace between the
<span>s are part of the repro: they match what the NHS.UK page renders (its markup is generated by JavaScript, with no whitespace between the spans). Without the.visually-hiddenstyles the comma is visible text, and the button passes.Upload a file , No file chosen, Choose filedevelop)No file chosenChoose fileNo file chosen Choose fileThe accessible name keeps the hidden comma, and with it the word boundary, because visually hidden content is exposed to assistive technology. The visible text drops it and keeps no boundary, so
label-content-name-mismatchtokenizeschosenchoose, finds no such word in the name, and reports a violation for a button that is labelled by its own content.This is the NHS.UK frontend file upload component from the issue. Neither the self reference in
aria-labelledbynoraria-liveis involved: with the hidden separator removed, the same button passes ondevelop.Fix
An element that is rendered but has no visible text now contributes a single space, which is what the ACT definition of visible inner text gives it:
An element that is not rendered, or whose box has no width, still contributes nothing, so the words around a
display: noneorhiddenelement stay joined, as they are on screen. The space is only ever added where the text of an element was left out, so visible elements are untouched.Testing
test/commons/text/visible-virtual.jscover the visually hidden andvisibility: hiddenseparators, and thedisplay: none, zero-width and visible cases that must stay joined.test/checks/label/label-content-name-mismatch.jscover the reported markup, the same pattern witharia-label, and a genuine mismatch that the new separator must not rescue.#pass20and#fail10.#pass20fails ondevelop.No file chosen Choose file or drop file.tsc, ESLint and Prettier. ACT rule 2ee8b8 passes all 16 passed and all 16 failed examples; the only ACT failure,78fd32Failed Example 2, fails the same way ondevelop.Across an 18 case matrix of hidden separators, only the reported pattern changed outcome, plus a
visibility: hiddenelement between two words, which the ACT definition separates for the same reason. Nothing went from pass to violation.Note on #5460
#5460 fixes the related case where the text of two adjacent block elements is joined. It does not fix this issue: here the separated elements are
<span>s, which are phrasing content, so #5460 keeps them joined — verified by building that branch against the NHS.UK page. The two patches touch the same statement and will conflict textually, but they compose: #5460 handles a child whose text is non-empty, this one a child whose text is empty.