material-ui icon indicating copy to clipboard operation
material-ui copied to clipboard

unnecessary to always have tabindex=0 on <button /> in html

Open yuanwei0525 opened this issue 3 years ago β€’ 6 comments

  • [x] The issue is present in the latest release.
  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

Following code <Button variant="contained">Contained</Button> renders image

Expected Behavior πŸ€”

If tabIndex is not provided to component Button, it is unnecessary to render tabindex=0 in result html since button is tab-able by default, unless a number is provided to Button as parameter.

Steps to Reproduce πŸ•Ή

Steps:

  1. go to https://mui.com/components/buttons/
  2. inspect button from one of example

Context πŸ”¦

Accessibility

Your Environment 🌎

Chrome browser

yuanwei0525 avatar Oct 19 '21 16:10 yuanwei0525

But this is not breaking something tough right? It's safer to always have it, as it may be rendered as another element too. We could remove it, but why complicate the logic.

Is there something that is not working for your use-case?

mnajdova avatar Oct 20 '21 08:10 mnajdova

It does not break anything but redundant to have. Our team is working on a project using mui and our accessibility team recommended us to remove tabindex on button element.

I was curious about how other popular UI frameworks render button component and noticed bootstrap, semantic ui, ant, elemental ui do not render tabindex to button element in html. There might be more because I did not check every framework.

Reference:

  • https://react-bootstrap.github.io/components/buttons/
  • https://react.semantic-ui.com/elements/button/
  • https://ant.design/components/button/
  • http://elemental-ui.com/buttons

yuanwei0525 avatar Oct 23 '21 18:10 yuanwei0525

Same issue here. My developers have been trying to circumvent by sending an empty tabindex over, but that just makes it worse.

Focusable Items are already focusable. The only time to add a TabIndex is to bring a non-focusable Item into focus or to remove a focusable item from focus. Having a tabIndex ="0" on an HTML Semantic Element is redundant and should be removed.

sandyClark603 avatar Dec 22 '21 22:12 sandyClark603

for anyone who's interested in a reasonable workaround, if you assign null to tabIndex it will not appear in the html. the props type doesn't accept null but you can workaround that with a cast

<Button tabIndex={ null as unknown as undefined }>no tabindex!</Button>

i think at the very least the type should be changed to accept null

danielcavanagh avatar Feb 01 '23 07:02 danielcavanagh

~It turns out that having tabindex="0" on all buttons solves a pretty significant yet wontfix bug from Safari.~ Basically Safari does not assign the <button> node to document.activeElement, which has serious accessibility repercussions for dialog libraries like a11y-dialog. ~If the button has a non-null tabindex attribute however, Safari does behave as expected. πŸ™ƒ~

In other words: considering it doesn’t cause any problem to have it on every button, and since it can both help when using polymorphic components ~and as a workaround for a 15 years old focus bug in a major browser~, Iβ€˜d say keep it. :)

Edit: My bad, I spoke too fast. :(

KittyGiraudel avatar May 01 '23 10:05 KittyGiraudel

ok. that's good info. if the current behaviour avoids an issue in safari then it seems reasonable to keep it

however this was actually causing an issue for us, which is why we had to work around it. it's not just a tidyness issue or whatever. the only problem is i can't remember what the issue was right now... πŸ˜†

at the very least null should be passable without a cast

danielcavanagh avatar May 01 '23 23:05 danielcavanagh