onClick on a summary element causes S6848 and S1082

Please provide

  • Operating system: Arch Linux
  • SonarLint plugin version: v4.4.1
  • Programming language you’re coding in: React/Javascript
  • Is connected mode used: No
    • Connected to SonarCloud or SonarQube (and which version):

And a thorough description of the problem / question:

The summary-element has the role button by default, so it should be considered a native interactive element. The following code produces a warning for S6848 and S1082:

    <summary onClick={() => { ... }}>

Is this intended or overlooked?

@weelink, thanks a lot for your report, and welcome to the SonarSource community.

To answer your question, it was intended, as our rules are honoring the ARIA specification that doesn’t assign a role to the summary element (see ARIA in HTML for reference).

That said, the team discussed the issue and agreed that the rules should adopt the same position as most user agents - that is, to consider that the summary element default role is button.

I’ve created this ticket in order to address this issue: [SONARHTML-226] - Jira