From e59fc34bf67a8af29c73298b6df4aaf392ecb332 Mon Sep 17 00:00:00 2001 From: Ian Jones <51156018+ianjon3s@users.noreply.github.com> Date: Fri, 17 May 2024 10:18:21 +0100 Subject: [PATCH] a11y: Result accordions non-expanding option (#3150) --- .../components/Result/Public/ResultReason.tsx | 91 ++++++++++++------- 1 file changed, 57 insertions(+), 34 deletions(-) diff --git a/editor.planx.uk/src/@planx/components/Result/Public/ResultReason.tsx b/editor.planx.uk/src/@planx/components/Result/Public/ResultReason.tsx index 653ed776e8..6cd4782813 100644 --- a/editor.planx.uk/src/@planx/components/Result/Public/ResultReason.tsx +++ b/editor.planx.uk/src/@planx/components/Result/Public/ResultReason.tsx @@ -36,6 +36,9 @@ const Root = styled(Box)(({ theme }) => ({ margin: "0", marginRight: theme.spacing(8), position: "relative", + [`& > div.${accordionClasses.root}.Mui-expanded`]: { + margin: "0", + }, })); const ChangeLink = styled(Box)(({ theme }) => ({ @@ -120,6 +123,15 @@ const StyledAccordion = styled(Accordion)(({ theme }) => ({ }, })); +const NonExpandingSummary = styled(Box)(({ theme }) => ({ + display: "flex", + alignItems: "center", + padding: theme.spacing(2, 0, 2, 3), + borderBottom: `1px solid ${theme.palette.border.main}`, + width: "100%", + zIndex: 2, +})); + const ResultReason: React.FC = ({ id, question, @@ -128,16 +140,16 @@ const ResultReason: React.FC = ({ flagColor, }) => { const changeAnswer = useStore((state) => state.changeAnswer); - const accordionSummaryRef = useRef(null); - const [accordionSummaryHeight, setAccordionSummaryHeight] = useState(0); + const summaryRef = useRef(null); + const [summaryHeight, setSummaryHeight] = useState(0); // Match height of closed accordion to ChangeLink useLayoutEffect(() => { - if (accordionSummaryRef.current) { - const height = accordionSummaryRef.current.clientHeight; - setAccordionSummaryHeight(height); + if (summaryRef.current) { + const height = summaryRef.current.clientHeight; + setSummaryHeight(height); } - }, [accordionSummaryRef]); + }, [summaryRef]); const hasMoreInfo = question.data.info ?? question.data.policyRef; @@ -161,34 +173,34 @@ const ResultReason: React.FC = ({ return ( - - : null} - aria-label={ariaLabel} - aria-controls={`group-${id}-content`} - id={`group-${id}-header`} - ref={accordionSummaryRef} + {hasMoreInfo ? ( + - } + aria-label={ariaLabel} + aria-controls={`group-${id}-content`} + id={`group-${id}-header`} + ref={summaryRef} > - - {question.data.text}
- {response} -
-
-
- {hasMoreInfo && ( + + {question.data.text}
+ {response} +
+ + {question.data.info && ( @@ -205,9 +217,20 @@ const ResultReason: React.FC = ({ )} - )} -
- + + ) : ( + + + {question.data.text}
+ {response} +
+
+ )} + {showChangeButton && (