ReactFix
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • React
  • React Native
  • Programming
  • Object Oriented Programming

Friday, November 4, 2022

[FIXED] How to change Material-UI Button's tabIndex?

 November 04, 2022     button, material-ui, reactjs, tabindex   

Issue

I am using Material-UI in one of my ReactJS projects. I have a few buttons: some - primary, the rest are secondary. What I want to achieve is to disable the tabIndex property on secondary buttons, leaving only the primary buttons accessible with the keyboard tab.

Turns out setting tabIndex attribute to the Button component does not work, nor setting the tabIndex via inputProps:

<Button
  variant="contained"
  tabIndex="-1"  //does not work
  size="small"
  startIcon={SearchIcon}
  color='secondary'
  inputProps={{ tabIndex: "-1" }}  //does not work either
 > some text
</Button>

How do I achieve disabling the accessibility of the secondary buttons via keyboard tab? I can't set tabindex attribute to an element via CSS, can I?

Any help would be appreciated. Thank you.


Solution

for textfield and input you must code like this

      <TextField label="1" inputProps={{ tabIndex: "1" }} />

for button your code must be like this

      <Button tabIndex="2">Button 2</Button>


Answered By - amirreza mojarad
Answer Checked By - - Robin (ReactFix Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Newer Post Older Post Home

Featured Post

Is Learning React Difficult?

React is difficult to learn, no ifs and buts. React isn't inherently difficult to learn. It's a framework that's different from ...

Total Pageviews

Copyright © ReactFix