-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(color-contrast): ignore aria-disabled labels (#2130)
* fix(color-contrast): ignore aria-disabled labels If an element is a descendent of an aria-labelledby reference, and any of the elements referencing it has disabled, the label must be ignored by the color-contrast rule. * Apply suggestions from code review Co-authored-by: Steven Lambert <2433219+straker@users.noreply.github.com> * linter stuff * chore: update from feedback * chore: fix CI failures * Apply suggestions from code review Co-authored-by: Steven Lambert <2433219+straker@users.noreply.github.com> * chore: fix buggy test Co-authored-by: Steven Lambert <2433219+straker@users.noreply.github.com>
- Loading branch information
1 parent
cf11b64
commit e451b87
Showing
5 changed files
with
273 additions
and
96 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const disabledNodeNames = ['fieldset', 'button', 'select', 'input', 'textarea']; | ||
|
||
/** | ||
* Determines if an element disabled, or part of a disabled element | ||
* | ||
* IMPORANT: This method is fairly loose. There are significant differences in browsers of when | ||
* they'll announce a thing disabled. This tells us if any accessibility supported browser | ||
* identifies an element as disabled, but not if all of them do. | ||
* | ||
* @method isDisabled | ||
* @memberof axe.commons.forms | ||
* @param {VirtualNode} virtualNode | ||
* @return {boolean} whether or not the element is disabled in some way | ||
*/ | ||
function isDisabled(virtualNode) { | ||
let disabledState = virtualNode._isDisabled; | ||
if (typeof disabledState === 'boolean') { | ||
return disabledState; // From cache | ||
} | ||
|
||
const { nodeName } = virtualNode.props; | ||
const ariaDisabled = virtualNode.attr('aria-disabled'); | ||
if (disabledNodeNames.includes(nodeName) && virtualNode.hasAttr('disabled')) { | ||
disabledState = true; // Native | ||
} else if (ariaDisabled) { | ||
// ARIA | ||
disabledState = ariaDisabled.toLowerCase() === 'true'; | ||
} else if (virtualNode.parent) { | ||
// Inherited | ||
disabledState = isDisabled(virtualNode.parent); | ||
} else { | ||
// Default | ||
disabledState = false; | ||
} | ||
|
||
virtualNode._isDisabled = disabledState; | ||
return disabledState; | ||
} | ||
|
||
export default isDisabled; |
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.