Reputation:
I have my custom tab navigation in React.js. I want to change the background color of the active tab using conditional rendering or state change. I tried passing state for color but nothing is changing in CSS. Here is my code link: https://stackblitz.com/edit/reacttabs
Please help!
Upvotes: 0
Views: 130
Reputation: 340
you have to conditionally style the li
element
first define a variable for active tab style
var active = Object.assign({},tabStyles);
active.backgroundColor = '#000';
then inside the render conditionally call the desired style
<li style={this.state.active == '1' ? active : tabStyles} onClick={() => {this.toggle('1')}}>A</li>
<li style={this.state.active == '2' ? active : tabStyles} onClick={() => {this.toggle('2')}}>B</li>
Upvotes: 2