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

how to add a class of the selected tab ? #85

Closed
MingXingTeam opened this issue Mar 22, 2016 · 3 comments
Closed

how to add a class of the selected tab ? #85

MingXingTeam opened this issue Mar 22, 2016 · 3 comments

Comments

@MingXingTeam
Copy link

I do it as this, but the first tab seems not clickable.

getInitialState() {
return {
      selectedIndex: 0
    };
},
handleSelect(index, last) {
    this.setState({
       selectedIndex: index
    });
}

tabs:

<Tabs
onSelect={this.handleSelect}
selectedIndex={0}
 >
  <TabList>
     <Tab>
      <div className={
cx({"bg-color-w": (this.state.selectedIndex == 0?true:false)
                            })}>涨幅榜
</div>
...

please give me a hint~~thanks very much. 😃

@joepvl
Copy link
Collaborator

joepvl commented Apr 1, 2016

Try using selectedIndex={ this.state.selectedIndex } instead :). That way, the component will rerender when you change the state in your handleSelect method, updating the view to show the tab you selected. To illustrate, here's a JSBin example that has a <div> inside the <Tab>, like your example code: http://jsbin.com/wifelo/edit?css,js,output (uses an ES6 class instead of React.createClass, but the principle is the same).

Alternatively, the package adds a classname of ReactTabs__Tab--selected and a selected attribute to selected <Tab>s, so you can use those in your CSS if you want instead.

@MingXingTeam
Copy link
Author

Thanks for your awesome answer!! 😄

@joepvl
Copy link
Collaborator

joepvl commented Apr 4, 2016

My pleasure! Looks like this issue can be closed now.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants