-
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.
Create rule S6842 for HTML: Non-interactive DOM elements should not h…
…ave interactive ARIA roles (#3657)
- Loading branch information
1 parent
30952d5
commit 5c68374
Showing
8 changed files
with
68 additions
and
39 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,3 @@ | ||
== How to fix it | ||
|
||
Ensure that non-interactive DOM elements do not use interactive ARIA roles. |
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,6 @@ | ||
== Resources | ||
=== Documentation | ||
|
||
* WCAG - https://www.w3.org/WAI/WCAG21/Understanding/name-role-value[Name, Role, Value] | ||
* WCAG - https://www.w3.org/TR/wai-aria-1.1/#usage_intro[WAI-ARIA Roles] | ||
* MDN web docs - https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles[WAI-ARIA Roles] |
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,9 @@ | ||
== Why is this an issue? | ||
|
||
Non-interactive DOM elements are those that do not have built-in interactivity or do not require user interaction. Examples include `<div>`, `<p>`, `<img>`, `<h1>` to `<h6>`, and `<ul>`, among others. These elements are typically used to structure content and layout but do not have any inherent interactive behavior. | ||
|
||
Interactive ARIA roles, on the other hand, are used to make elements interactive and accessible. These roles include `button`, `link`, `checkbox`, `menuitem`, `tab`, and others. They are used to communicate the type of interaction that users can expect from an element. | ||
|
||
Non-interactive DOM elements should not use interactive ARIA roles because it can confuse assistive technologies and their users. For example, if a `<div>` (a non-interactive element) is given an interactive role like "button", assistive technologies like screen readers will announce it as a button. However, since `<div>` doesn't have the inherent behavior of a button, it can confuse users who expect it to behave like a button when interacted with. | ||
|
||
This can lead to a poor user experience and can make the website less accessible for users relying on assistive technologies. Therefore, it's important to ensure that non-interactive DOM elements are not given interactive ARIA roles. |
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 @@ | ||
{ | ||
} |
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,21 @@ | ||
include::../common/why.adoc[] | ||
|
||
include::../common/how.adoc[] | ||
|
||
=== Code examples | ||
|
||
==== Noncompliant code example | ||
|
||
[source,html,diff-id=1,diff-type=noncompliant] | ||
---- | ||
<li role="button">Foo</li> <!--Noncompliant; "li" isn't interactive, but "button" is--> | ||
---- | ||
|
||
==== Compliant solution | ||
|
||
[source,html,diff-id=1,diff-type=compliant] | ||
---- | ||
<li role="listitem">Foo</li> | ||
---- | ||
|
||
include::../common/resources.adoc[] |
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,26 +1,6 @@ | ||
{ | ||
"title": "Non-interactive DOM elements should not have interactive ARIA roles", | ||
"type": "CODE_SMELL", | ||
"status": "ready", | ||
"remediation": { | ||
"func": "Constant\/Issue", | ||
"constantCost": "5min" | ||
}, | ||
"tags": [ | ||
"accessibility", | ||
"react" | ||
], | ||
"defaultSeverity": "Major", | ||
"ruleSpecification": "RSPEC-6842", | ||
"sqKey": "S6842", | ||
"scope": "All", | ||
"defaultQualityProfiles": ["Sonar way"], | ||
"quickfix": "infeasible", | ||
"code": { | ||
"impacts": { | ||
"MAINTAINABILITY": "LOW", | ||
"RELIABILITY": "MEDIUM" | ||
}, | ||
"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
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,2 +1,25 @@ | ||
{ | ||
"title": "Non-interactive DOM elements should not have interactive ARIA roles", | ||
"type": "CODE_SMELL", | ||
"status": "ready", | ||
"remediation": { | ||
"func": "Constant\/Issue", | ||
"constantCost": "5min" | ||
}, | ||
"tags": [ | ||
"accessibility" | ||
], | ||
"defaultSeverity": "Major", | ||
"ruleSpecification": "RSPEC-6842", | ||
"sqKey": "S6842", | ||
"scope": "All", | ||
"defaultQualityProfiles": ["Sonar way"], | ||
"quickfix": "infeasible", | ||
"code": { | ||
"impacts": { | ||
"MAINTAINABILITY": "LOW", | ||
"RELIABILITY": "MEDIUM" | ||
}, | ||
"attribute": "CONVENTIONAL" | ||
} | ||
} |