-
Notifications
You must be signed in to change notification settings - Fork 779
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(valid-lang): run on aria-hidden text (#3634)
- Loading branch information
1 parent
6f6a89e
commit a0860bd
Showing
8 changed files
with
126 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,28 @@ | ||
import { hasChildTextNodes } from './has-content-virtual'; | ||
import isVisualContent from './is-visual-content'; | ||
import isVisible from './is-visible'; | ||
import isHiddenWithCSS from './is-hidden-with-css'; | ||
|
||
/** | ||
* Check that a node has text, or an accessible name which language is defined by the | ||
* Check that a node has text, or an accessible name which language is defined by the | ||
* nearest ancestor's lang attribute. | ||
* @param {VirtualNode} virtualNode | ||
* @param {VirtualNode} virtualNode | ||
* @return boolean | ||
*/ | ||
export default function hasLangText(virtualNode) { | ||
if (typeof virtualNode.children === 'undefined' || hasChildTextNodes(virtualNode)) { | ||
if ( | ||
typeof virtualNode.children === 'undefined' || | ||
hasChildTextNodes(virtualNode) | ||
) { | ||
return true; | ||
} | ||
if (virtualNode.props.nodeType === 1 && isVisualContent(virtualNode)) { | ||
// See: https://github.com/dequelabs/axe-core/issues/3281 | ||
return !!axe.commons.text.accessibleTextVirtual(virtualNode); | ||
} | ||
return virtualNode.children.some(child => ( | ||
!child.attr('lang') && // non-empty lang | ||
hasLangText(child) && // has text | ||
isVisible(child, true) // Not hidden for AT | ||
)); | ||
return virtualNode.children.some( | ||
child => | ||
!child.attr('lang') && // non-empty lang | ||
hasLangText(child) && // has text | ||
!isHiddenWithCSS(child) // Not hidden for anyone | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"id": "de46e4", | ||
"title": "Element with lang attribute has valid language tag", | ||
"axeRules": ["valid-lang"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.