-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1048d2
commit 82cc53e
Showing
3 changed files
with
65 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"title": "Non-interactive elements shouldn't have event handlers", | ||
"type": "CODE_SMELL", | ||
"status": "ready", | ||
"remediation": { | ||
"func": "Constant\/Issue", | ||
"constantCost": "5min" | ||
}, | ||
"tags": [ | ||
"accessibility", | ||
"react" | ||
], | ||
"defaultSeverity": "Minor", | ||
"ruleSpecification": "RSPEC-6847", | ||
"sqKey": "S6847", | ||
"scope": "All", | ||
"defaultQualityProfiles": ["Sonar way"], | ||
"quickfix": "infeasible", | ||
"code": { | ||
"impacts": { | ||
"MAINTAINABILITY": "MEDIUM", | ||
"RELIABILITY": "LOW" | ||
}, | ||
"attribute": "CONVENTIONAL" | ||
} | ||
} |
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 @@ | ||
Non-interactive HTML elements, such as ``++<div>++`` and ``++<span>++``, are not designed to have event handlers. When these elements are given event handlers, it can lead to accessibility issues. | ||
|
||
== Why is this an issue? | ||
|
||
Attaching event handlers to non-interactive HTML elements can lead to significant accessibility issues. These elements, such as ``++<div>++`` and ``++<span>++``, are not designed to interact with assistive technologies like screen readers, making it difficult for users with disabilities to navigate and interact with the website. Additionally, these elements may not be focusable or provide visual feedback when interacted with, resulting in a confusing and potentially frustrating user experience. Therefore, to maintain an accessible and user-friendly website, event handlers should be used exclusively with interactive elements. | ||
|
||
== How to fix it | ||
|
||
To fix this issue, remove the event handler from the non-interactive element and attach it to an interactive element instead. If the element is not interactive, it should not have an event handler. | ||
|
||
=== Code examples | ||
|
||
==== Noncompliant code example | ||
|
||
[source,text,diff-id=1,diff-type=noncompliant] | ||
---- | ||
<li onClick={() => void 0} /> | ||
<div onClick={() => void 0} role="listitem" /> | ||
---- | ||
|
||
==== Compliant solution | ||
|
||
[source,text,diff-id=1,diff-type=compliant] | ||
---- | ||
<div onClick={() => void 0} role="button" /> | ||
<div onClick={() => void 0} role="presentation" /> | ||
<input type="text" onClick={() => void 0} /> // Interactive element does not require role. | ||
<button onClick={() => void 0} className="foo" /> // button is interactive. | ||
<div onClick={() => void 0} role="button" aria-hidden /> // This is hidden from the screenreader. | ||
---- | ||
|
||
|
||
== Resources | ||
=== Documentation | ||
|
||
* WCAG - https://www.w3.org/TR/wai-aria-practices-1.1/#aria_ex[WAI-ARIA Authoring Practices Guide - Design Patterns and Widgets] | ||
* MDN - https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_button_role#Keyboard_and_focus[ARIA Techniques] |
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,2 @@ | ||
{ | ||
} |