This repository was archived by the owner on Mar 9, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
components/learn-components Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -18,9 +18,16 @@ export default class AccordGuide extends Component {
1818 } ) ;
1919 this . state = {
2020 markdown : '' ,
21+ activeIndex : - 1 ,
2122 } ;
2223 }
24+ handleClick = ( e , titleProps ) => {
25+ const { index } = titleProps ;
26+ const { activeIndex } = this . state ;
27+ const newIndex = activeIndex === index ? - 1 : index ;
2328
29+ this . setState ( { activeIndex : newIndex } ) ;
30+ } ;
2431 async componentDidMount ( ) {
2532 try {
2633 const request = await fetch ( this . props . url ) ;
@@ -32,15 +39,20 @@ export default class AccordGuide extends Component {
3239 }
3340
3441 render ( ) {
42+ const { activeIndex } = this . state ;
3543 return (
3644 < div >
3745 < main >
3846 < Accordion fluid styled >
39- < Accordion . Title >
47+ < Accordion . Title
48+ active = { activeIndex === 0 }
49+ onClick = { this . handleClick }
50+ index = { 0 }
51+ >
4052 < Icon name = "dropdown" />
4153 { this . props . title }
4254 </ Accordion . Title >
43- < Accordion . Content >
55+ < Accordion . Content active = { activeIndex === 0 } >
4456 { this . state . markdown === '' ? (
4557 < Loader active inline = "centered" />
4658 ) : (
You can’t perform that action at this time.
0 commit comments