-
-
Save ovpv/440293d7a04b241e9f4c256e07daf01c to your computer and use it in GitHub Desktop.
updateTabs method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Accordion extends React.Component { | |
constructor(props) { | |
... | |
this.handleTabClick = this.handleTabClick.bind(this); | |
this.updateTabs = this.updateTabs.bind(this); | |
} | |
updateTabs(id){ | |
let tabs = this.state.tabs; | |
let newtabs = tabs.map((tab, index)=>{ | |
if(tab.id == id){ | |
if(tab.active == true){ | |
tab.active = false; | |
}else{ | |
tab.active = true; | |
} | |
}else{ | |
tab.active = false; | |
} | |
return tab; | |
}); | |
return newtabs; | |
} | |
handleTabClick(id){ | |
this.setState({tabs: this.updateTabs(id)}); | |
} | |
render() { | |
... | |
<div> | |
<h2>Accordion:</h2> | |
<div id="accordion"> | |
{ | |
tabsArray.map((tab,index)=>{ | |
return <Tab key={index} id={tab.id} handleclick={this.handleTabClick} title={tab.title} content={tab.content} active={tab.active} /> | |
}) | |
} | |
</div> | |
</div> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment