Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tabs: Cannot set the index of tab programmatically. #8809

Closed
1 task done
jstralko opened this issue Oct 23, 2017 · 4 comments
Closed
1 task done

Tabs: Cannot set the index of tab programmatically. #8809

jstralko opened this issue Oct 23, 2017 · 4 comments
Assignees
Labels
bug 🐛 Something doesn't work component: tabs This is the name of the generic UI component, not the React module!

Comments

@jstralko
Copy link

jstralko commented Oct 23, 2017

When trying to set the index of tab programmatically from componentDidMount the Tab indicator doesn't change.

  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

When changing the index in state the Tabs component should update the indicator.

Current Behavior

The indicator doesn't change even when the render is called again with the correct index from state.

Steps to Reproduce (for bugs)

Here is a codesandbox.io:

https://codesandbox.io/s/ykn36kzyj

The indicator should be set for index 1 but the indicator is set to index 0.

This worked earlier, I noticed this issue when I updated material-ui to beta-17

Context

Your Environment

Tech Version
Material-UI 1.0.0.Beta17
React 16.0.0
browser Chrome
@jstralko
Copy link
Author

looks like if I wrap the this.setState({index}) around a setTimeout it works.

setTimeout(()=>this.setState({index}), 0)

@oliviertassinari oliviertassinari added bug 🐛 Something doesn't work component: tabs This is the name of the generic UI component, not the React module! labels Oct 23, 2017
@mpaarating
Copy link

While I've not found an explicit reason as to why, there seems to be timing issues with rendering and using setState inside of componentDidMount. The general recommendation is to not use setState inside of componentDidMount (so much so, that eslint has a rule against it.

@oliviertassinari
Copy link
Member

This issue is definitely tricky. Thanks, @jstralko for the reproduction example. I have found a fix.

@jstralko
Copy link
Author

Thank you for the quick fix. Great work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: tabs This is the name of the generic UI component, not the React module!
Projects
None yet
Development

No branches or pull requests

3 participants