Skip to content

Commit

Permalink
Create rule S6842 for HTML: Non-interactive DOM elements should not h…
Browse files Browse the repository at this point in the history
…ave interactive ARIA roles (#3657)
  • Loading branch information
github-actions[bot] authored Feb 20, 2024
1 parent 30952d5 commit 5c68374
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 39 deletions.
3 changes: 3 additions & 0 deletions rules/S6842/common/how.adoc
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.
6 changes: 6 additions & 0 deletions rules/S6842/common/resources.adoc
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]
9 changes: 9 additions & 0 deletions rules/S6842/common/why.adoc
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.
2 changes: 2 additions & 0 deletions rules/S6842/html/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
21 changes: 21 additions & 0 deletions rules/S6842/html/rule.adoc
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[]
22 changes: 1 addition & 21 deletions rules/S6842/javascript/metadata.json
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"
}
]
}
21 changes: 3 additions & 18 deletions rules/S6842/javascript/rule.adoc
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
== Why is this an issue?
include::../common/why.adoc[]

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.

== How to fix it

Ensure that non-interactive DOM elements do not use interactive ARIA roles.
include::../common/how.adoc[]

=== Code examples

Expand All @@ -32,9 +22,4 @@ function myListElement() {
}
----

== 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]
include::../common/resources.adoc[]
23 changes: 23 additions & 0 deletions rules/S6842/metadata.json
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"
}
}

0 comments on commit 5c68374

Please sign in to comment.