Skip to content
This repository was archived by the owner on Mar 4, 2024. It is now read-only.

Commit 87e2ea5

Browse files
committed
Custom onclick
1 parent 43a9c41 commit 87e2ea5

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/components/GenerateBlocks.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ const GenerateBlocks = ({
6161
blocks: LayoutSectionBlock[] | null
6262
markdownParsingOptions?: MarkdownToJSX.Options
6363
}) => {
64-
6564
return (
6665
<>
6766
{blocks &&

src/components/blocks/Accordion.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useMemo } from 'react'
1+
import React, { useEffect, useState } from 'react'
22

33
import styled from 'styled-components'
44
import { AccordionSingle } from '@ecmwf-projects/cads-ui-library'
@@ -12,16 +12,22 @@ export const Accordion = ({ block }: { block: AccordionBlock }) => {
1212

1313
const isHashSelected = useHashSelected(block.id)
1414

15-
const value = useMemo(() => {
15+
const [open, setOpen] = useState(false)
16+
useEffect(() => {
17+
let opened = false
1618
if (isHashSelected) {
17-
return block.title
19+
opened = true
1820
}
19-
return block.collapsed ? '' : block.title
21+
opened = !block.collapsed
22+
setOpen(opened)
2023
}, [block.collapsed, block.title, isHashSelected])
21-
24+
2225
return (<AccordionSingle
2326
rootProps={{
24-
value: value,
27+
value: open ? block.title : '',
28+
onClick: () => {
29+
setOpen(!open)
30+
}
2531
}}
2632
itemProps={{
2733
value: block.title,

0 commit comments

Comments
 (0)