1
1
import { Component } from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
- import { styled } from '@mui/material/styles' ;
4
3
import Typography from '@mui/material/Typography' ;
5
- import KeyboardArrowDown from '@mui/icons-material/KeyboardArrowDownSharp' ;
6
- import KeyboardArrowUp from '@mui/icons-material/KeyboardArrowUpSharp' ;
7
- import MiradorMenuButton from '../containers/MiradorMenuButton' ;
8
-
9
- const StyledContainer = styled ( 'div' ) ( ( ) => ( {
10
- alignItems : 'flex-start' ,
11
- cursor : 'pointer' , // This style will be applied to Typography
12
- display : 'flex' ,
13
- justifyContent : 'space-between' ,
14
- } ) ) ;
4
+ import Accordion from '@mui/material/Accordion' ;
5
+ import AccordionDetails from '@mui/material/AccordionDetails' ;
6
+ import AccordionSummary from '@mui/material/AccordionSummary' ;
7
+ import ExpandMoreIcon from '@mui/icons-material/ExpandMore' ;
15
8
16
9
/**
17
10
* CollapsableSection ~
@@ -22,14 +15,12 @@ export class CollapsibleSection extends Component {
22
15
super ( props ) ;
23
16
24
17
this . state = { open : true } ;
25
- this . toggleSection = this . toggleSection . bind ( this ) ;
18
+ this . handleChange = this . handleChange . bind ( this ) ;
26
19
}
27
20
28
- /** */
29
- toggleSection ( ) {
30
- const { open } = this . state ;
31
-
32
- this . setState ( { open : ! open } ) ;
21
+ /** Control the accordion state so we can provide aria labeling */
22
+ handleChange ( event , isExpanded ) {
23
+ this . setState ( { open : isExpanded } ) ;
33
24
}
34
25
35
26
/**
@@ -42,28 +33,16 @@ export class CollapsibleSection extends Component {
42
33
const { open } = this . state ;
43
34
44
35
return (
45
- < >
46
- < StyledContainer sx = { { padding : 0 } } >
47
- < Typography
48
- sx = { { alignSelf : 'center' , cursor : 'pointer' } }
49
- id = { id }
50
- onClick = { this . toggleSection }
51
- variant = "overline"
52
- component = "h4"
53
- >
36
+ < Accordion id = { id } elevation = { 0 } expanded = { open } onChange = { this . handleChange } disableGutters square variant = "compact" >
37
+ < AccordionSummary id = { `${ id } -header` } aria-controls = { `${ id } -content` } aria-label = { t ( open ? 'collapseSection' : 'expandSection' , { section : label } ) } expandIcon = { < ExpandMoreIcon /> } >
38
+ < Typography variant = "overline" component = "h4" >
54
39
{ label }
55
40
</ Typography >
56
- < MiradorMenuButton
57
- aria-label = { t ( open ? 'collapseSection' : 'expandSection' , { section : label } ) }
58
- aria-expanded = { open }
59
- sx = { { padding : 0 } }
60
- onClick = { this . toggleSection }
61
- >
62
- { open ? < KeyboardArrowUp /> : < KeyboardArrowDown /> }
63
- </ MiradorMenuButton >
64
- </ StyledContainer >
65
- { open && children }
66
- </ >
41
+ </ AccordionSummary >
42
+ < AccordionDetails >
43
+ { children }
44
+ </ AccordionDetails >
45
+ </ Accordion >
67
46
) ;
68
47
}
69
48
}
0 commit comments