Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jsx-a11y/no-static-element-interactions: how to make span clickable

Tags:

reactjs

eslint

In my project we have this lines of codes:

    <span
      onClick={this.toggleEditing}
    >
      {this.state.value}
    </span>

Needless to say, it produces an error in eslint with message "Visible, non-interactive elements should not have mouse or keyboard event listeners jsx-a11y/no-static-element-interactions". But I don't know what is the best way to fix this situation, should we change it to button and change style to look like a span. I really don't have much experience with this problem.

like image 540
Tu Anh Avatar asked Jan 22 '26 09:01

Tu Anh


1 Answers

Look at the documentation it beautifully tells you what to do.
https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-static-element-interactions.md#how-do-i-resolve-this-error

For your case, the resolution is to add role="button"

<span onClick={this.toggleEditing} role="button">
  {this.state.value}
</span>
like image 195
Aftab Khan Avatar answered Jan 25 '26 05:01

Aftab Khan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!