forked from jackdomleo7/Checka11y.css
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check elements with mouse event handlers
When HTMLElements use mouse event handlers such as onclick, ondblclick, onmouseup/down, onmouseenter/leave or onmouseover, without providing the proper alternatives (i.e. onkeydown/up/press, no or wrong tabindex and no or wrong role), they could become unreachable via the keyboard. We therefore should warn users of the danger, but it is ultimately up to them if they want to ignore it because they might have, for example, provided some alternative way of doing the same action. This excludes <a> and <button> elements. fixes jackdomleo7#59
- Loading branch information
Showing
5 changed files
with
54 additions
and
2 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
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,37 @@ | ||
/* | ||
HTMLElements other than <a> and <button> that have mouse event handlers without the appropriate keyboard handlers are not accessible | ||
*/ | ||
[onclick]:not( a ):not( button ):not( [onkeydown] ):not( [onkeyup] ):not( [onkeypress] )::after, | ||
[onclick][onkeyup]:not( [tabindex] ):not( a ):not( button )::after, | ||
[onclick][onkeyup][tabindex = "-1"]:not( a ):not( button )::after, | ||
[onclick][onkeydown]:not( [tabindex] ):not( a ):not( button )::after, | ||
[onclick][onkeydown][tabindex = "-1"]:not( a ):not( button )::after, | ||
[onclick][onkeypress]:not( [tabindex] ):not( a ):not( button )::after, | ||
[onclick][onkeypress][tabindex = "-1"]:not( a ):not( button )::after, | ||
[ondblclick]:not( a ):not( button ):not( [onkeydown] ):not( [onkeyup] ):not( [onkeypress] )::after, | ||
[ondblclick][onkeyup]:not( [tabindex] ):not( a ):not( button )::after, | ||
[ondblclick][onkeyup][tabindex = "-1"]:not( a ):not( button )::after, | ||
[ondblclick][onkeydown]:not( [tabindex] ):not( a ):not( button )::after, | ||
[ondblclick][onkeydown][tabindex = "-1"]:not( a ):not( button )::after, | ||
[ondblclick][onkeypress]:not( [tabindex] ):not( a ):not( button )::after, | ||
[ondblclick][onkeypress][tabindex = "-1"]:not( a ):not( button )::after, | ||
[onmousedown]:not( a ):not( button ):not( [onkeydown] ):not( [onkeyup] ):not( [onkeypress] )::after, | ||
[onmousedown][onkeyup]:not( [tabindex] ):not( a ):not( button )::after, | ||
[onmousedown][onkeyup][tabindex = "-1"]:not( a ):not( button )::after, | ||
[onmousedown][onkeydown]:not( [tabindex] ):not( a ):not( button )::after, | ||
[onmousedown][onkeydown][tabindex = "-1"]:not( a ):not( button )::after, | ||
[onmousedown][onkeypress]:not( [tabindex] ):not( a ):not( button )::after, | ||
[onmousedown][onkeypress][tabindex = "-1"]:not( a ):not( button )::after, | ||
[onmouseup]:not( a ):not( button ):not( [onkeydown] ):not( [onkeyup] ):not( [onkeypress] )::after, | ||
[onmouseup][onkeyup]:not( [tabindex] ):not( a ):not( button )::after, | ||
[onmouseup][onkeyup][tabindex = "-1"]:not( a ):not( button )::after, | ||
[onmouseup][onkeydown]:not( [tabindex] ):not( a ):not( button )::after, | ||
[onmouseup][onkeydown][tabindex = "-1"]:not( a ):not( button )::after, | ||
[onmouseup][onkeypress]:not( [tabindex] ):not( a ):not( button )::after, | ||
[onmouseup][onkeypress][tabindex = "-1"]:not( a ):not( button )::after, | ||
[onmouseover]:not( a ):not( button )::after, | ||
[onmouseenter]:not( a ):not( button )::after, | ||
[onmouseleave]:not( a ):not( button )::after { | ||
@extend %contentWarning; | ||
@include contentMessage(warning, "Potentially inaccessible click event used on non-clickable element. Ensure you have an accessible alternative."); | ||
} |
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