From 785ba3bc8ce0500a26531ad82f1aaabbfac5d9be Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Tue, 28 Nov 2023 10:36:13 -0800 Subject: [PATCH] Use an MUI accordion for the sidebar collapsing sections --- .../src/components/CollapsibleSection.test.js | 6 +-- src/components/CollapsibleSection.js | 53 ++++++------------- src/config/settings.js | 19 +++++++ 3 files changed, 38 insertions(+), 40 deletions(-) diff --git a/__tests__/src/components/CollapsibleSection.test.js b/__tests__/src/components/CollapsibleSection.test.js index 9e3ee8757c..aad2dd0f4c 100644 --- a/__tests__/src/components/CollapsibleSection.test.js +++ b/__tests__/src/components/CollapsibleSection.test.js @@ -34,9 +34,9 @@ describe('CollapsibleSection', () => { expect(screen.getByRole('button')).toHaveAttribute('aria-label', 'expandSection'); }); - it('renders children based on the open state', async () => { - expect(screen.getByTestId('child')).toBeInTheDocument(); + it('displays children based on the open state', async () => { + expect(screen.getByTestId('child')).toBeVisible(); await userEvent.click(screen.getByRole('button')); - expect(screen.queryByTestId('child')).not.toBeInTheDocument(); + expect(screen.queryByTestId('child')).not.toBeVisible(); }); }); diff --git a/src/components/CollapsibleSection.js b/src/components/CollapsibleSection.js index d7c13d8156..04c5f7d513 100644 --- a/src/components/CollapsibleSection.js +++ b/src/components/CollapsibleSection.js @@ -1,17 +1,10 @@ import { Component } from 'react'; import PropTypes from 'prop-types'; -import { styled } from '@mui/material/styles'; import Typography from '@mui/material/Typography'; -import KeyboardArrowDown from '@mui/icons-material/KeyboardArrowDownSharp'; -import KeyboardArrowUp from '@mui/icons-material/KeyboardArrowUpSharp'; -import MiradorMenuButton from '../containers/MiradorMenuButton'; - -const StyledContainer = styled('div')(() => ({ - alignItems: 'flex-start', - cursor: 'pointer', // This style will be applied to Typography - display: 'flex', - justifyContent: 'space-between', -})); +import Accordion from '@mui/material/Accordion'; +import AccordionDetails from '@mui/material/AccordionDetails'; +import AccordionSummary from '@mui/material/AccordionSummary'; +import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; /** * CollapsableSection ~ @@ -22,14 +15,12 @@ export class CollapsibleSection extends Component { super(props); this.state = { open: true }; - this.toggleSection = this.toggleSection.bind(this); + this.handleChange = this.handleChange.bind(this); } - /** */ - toggleSection() { - const { open } = this.state; - - this.setState({ open: !open }); + /** Control the accordion state so we can provide aria labeling */ + handleChange(event, isExpanded) { + this.setState({ open: isExpanded }); } /** @@ -42,28 +33,16 @@ export class CollapsibleSection extends Component { const { open } = this.state; return ( - <> - - + + }> + {label} - - {open ? : } - - - {open && children} - + + + {children} + + ); } } diff --git a/src/config/settings.js b/src/config/settings.js index c7f53e48a7..77f3552b39 100644 --- a/src/config/settings.js +++ b/src/config/settings.js @@ -176,6 +176,25 @@ export default { }, }, }, + MuiAccordion: { + variants: [ + { + props: { variant: 'compact' }, + style: { + '& .MuiAccordionSummary-root': { + minHeight: 'unset', + padding: 0, + }, + '& .MuiAccordionSummary-content': { + margin: 0, + }, + '& .MuiAccordionDetails-root': { + padding: 0, + }, + }, + }, + ], + }, MuiButtonBase: { defaultProps: { disableTouchRipple: true,