Answer the question
In order to leave comments, you need to log in
How to open a tab element on a site that is written in React.js?
import React, { Component } from 'react';
import './Faq.css';
class Faq extends Component {
state = {
isOpen : false
}
render() {
return (
<div className="faq-page">
<section>
<div id="open-btn" className={this.state.isOpen ? "isactive" : "ishidden"} onClick = {this.open}>
<div className="open-btn">
<div className="open-img1"></div>
<div className="open-img2"></div>
</div>
</div>
<div className={this.state.isOpen ? "show-answer" : "hide-answer"}>
<div className="answer-wrapper">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Impedit quaerat aperiam quibusdam suscipit accusantium,
dolores architecto numquam, ducimus sed. Quod a quia veritatis
ipsum alias tempore facilis, sunt rem exercitationem!</p>
</div>
</div>
</section>
<section>
<div id="open-btn" className={this.state.isOpen ? "isactive" : "ishidden"} onClick = {this.open}>
<div className="open-btn">
<div className="open-img1"></div>
<div className="open-img2"></div>
</div>
</div>
<div className={this.state.isOpen ? "show-answer" : "hide-answer"}>
<div className="answer-wrapper">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Impedit quaerat aperiam quibusdam suscipit accusantium,
dolores architecto numquam, ducimus sed. Quod a quia veritatis
ipsum alias tempore facilis, sunt rem exercitationem!</p>
</div>
</div>
</section>
<section>
<div id="open-btn" className={this.state.isOpen ? "isactive" : "ishidden"} onClick = {this.open}>
<div className="open-btn">
<div className="open-img1"></div>
<div className="open-img2"></div>
</div>
</div>
<div className={this.state.isOpen ? "show-answer" : "hide-answer"}>
<div className="answer-wrapper">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Impedit quaerat aperiam quibusdam suscipit accusantium,
dolores architecto numquam, ducimus sed. Quod a quia veritatis
ipsum alias tempore facilis, sunt rem exercitationem!</p>
</div>
</div>
</section>
</div>
);
}
open = () => this.setState ({
isOpen : !this.state.isOpen
})
}
export default Faq;
Answer the question
In order to leave comments, you need to log in
Instead of manually creating each block, put the text content of the blocks in an array, map it. Instead of isOpen, store the index of the open block (if only one can be open), or add isOpen to each element of the array (if multiple blocks can be open at the same time).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question