False positive for "Mouse events should have corresponding keyboard events"

Make sure to read this post before raising a thread here:

Then tell us:

  • What language is this for?

html/javascript/Angular

  • Which rule?

Mouse events should have corresponding keyboard events

  • Why do you believe it’s a false-positive/false-negative?

The rule excludes standard HTML <button> elements because they inherently support keyboard events (like Enter or Space).

Our Context:
We use Inhouse custom buttons (<sh-button>) instead of native <input type="button"> or <button>. These custom components already handle keyboard accessibility internally, should we need a way to exclude them from the rule as they appear not as 100s of “Bugs”

  • Are you using
    • SonarQube Cloud version 2025.5.0
  • How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)

using an item from our inhouse library

<sh-tab-item
*ngFor=“let tab of visibleTabs”
id=“tab.id”
[attr.label]=“tab.label | translate”
[active]=“isTabSelected(tab)”
(click)=“onTabNavigation(tab)”
>

We only starting seeing this in the last few weeks, may be coinciding with Central IT updating our Sonar instance ?

Hey there.

We have an item in the backlog, SONARHTML-304, to parameterize this rule to support custom frameworks. In the meantime, you’ll want to mark these issues as FPs or turn off the rule in your Quality Profile.

It’s probably a side effect of the upgrade, and this rule being added to the Sonar Way (Jira)

1 Like

How are you handling tab(s) + enter for the click on the sh-tab-item? :thinking:

In my experience this has always been a valid positive. It is better for the custom component to take a click action and bind it to a button internally then to bind it directly to the component. This is because it is significantly easier to make a button not look like a button then it is to make a non button work like a button (keyboard events, tab-index/navigation, cursor pointer consistency, ex.).

thanks, for the feedback on 304, we will mark as false positives and have a link to an open issue helps with our process dept !