github-actions[bot] 1a0597fc41
Create rule S6847: Non-interactive elements shouldn't have event handlers (#3658)
* Add html to rule S6847

* Share description with HTML

* Use a common folder

---------

Co-authored-by: yassin-kammoun-sonarsource <yassin-kammoun-sonarsource@users.noreply.github.com>
Co-authored-by: yassin-kammoun-sonarsource <yassin.kammoun@sonarsource.com>
Co-authored-by: Yassin Kammoun <52890329+yassin-kammoun-sonarsource@users.noreply.github.com>
2024-02-23 09:00:34 +00:00

28 lines
722 B
Plaintext

include::../common/why.adoc[]
include::../common/how.adoc[]
=== Code examples
==== Noncompliant code example
[source,js,diff-id=1,diff-type=noncompliant]
----
<li onClick={() => void 0} />
<div onClick={() => void 0} role="listitem" />
----
==== Compliant solution
[source,js,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.
----
include::../common/resources.adoc[]