1

Why React doesn't automatically make tag focusable, assign button aria role and onKeyPress when adding onClick event handler to the tag? Wouldn't it improve accessibility of the website? I understand that if you use <button> tag, it will be focusable and have button aria role by default. However, sometimes you have to use other tags to serve functionality of a button.

I know that you can manually add role=button, tabindex="0", onKeyPress={({keyCode}) => keyCode === 13 ? handleClick()}, onClick={handleClick} to the tag but it is too cumbersome.

Am I getting whole accessibility stuff wrong?

Noname
  • 4,432
  • 2
  • 10
  • 17
  • "However, sometimes you have to use other tags to serve functionality of a button." - do you want to provide an example? There are **very few** cases where you **have** to use another tag and normally it is just a limitation of your current setup and libraries chosen. At the moment there is nothing in here that we can really help with, but you do raise an excellent point, perhaps raise an issue for this idea and see what people think? – GrahamTheDev Jul 06 '21 at 07:25
  • @GrahamRitchie an example is when you want the table row to be clickable. As I know, `` cannot be wrapped in anything. See [this issue](https://stackoverflow.com/questions/17147821/how-to-make-a-whole-row-in-a-table-clickable-as-a-link) for example – Noname Jul 06 '21 at 07:36
  • https://stackoverflow.com/a/64789744/2702894 covers this but I do agree if you have no other option then that is a valid use case. As I said though unfortunately there is not much we can do (unless someone can point you to a plugin that does this for you) as it isn't a problem with your code. To answer your last question: no you are not doing this accessibility stuff wrong, you are using the correct method for if you cannot use a button. – GrahamTheDev Jul 06 '21 at 07:40
  • Which `tag`? If you mean any tag like `div`, `section`, `article`, `anchor`, `img` and so on then why they should be called as buttons if there is a click handler? – Ritesh Jagga Jul 11 '21 at 12:01

0 Answers0