fix(audit): use textContent instead of innerText#15568
fix(audit): use textContent instead of innerText#15568
Conversation
…vent false positives inside closed <details>
🦋 Changeset detectedLatest commit: 1da384f The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| 'Headings and anchors must have an accessible name, which can come from: inner text, aria-label, aria-labelledby, an img with alt property, or an svg with a tag <title></title>.', | ||
| selector: a11y_required_content.join(','), | ||
| match(element: HTMLElement) { | ||
| // innerText is used to ignore hidden text |
There was a problem hiding this comment.
I feel like we purposely used innerText for this reason and it used to be textContent before?
There was a problem hiding this comment.
IIRC, it was something with if you had elements nested in a certain common way, you can see the original PR that changed this here: #9483
There was a problem hiding this comment.
Unfortunately there aren't tests for possible regressions :/
There was a problem hiding this comment.
Oh yeah, textContent collects children element text too.
There was a problem hiding this comment.
@ematipico use const text = element.firstChild?.nodeType === 3 ? element.firstChild.nodeValue.trim() : ""; instead
Changes
Closes #15558
Did some research and
textContentis generally safer thaninnerText, so it's safe to use.Testing
Added a test
Docs