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

Commit

Permalink
Custom onclick
Browse files Browse the repository at this point in the history
  • Loading branch information
pelusanchez committed Nov 22, 2023
1 parent 43a9c41 commit 87e2ea5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/components/GenerateBlocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ const GenerateBlocks = ({
blocks: LayoutSectionBlock[] | null
markdownParsingOptions?: MarkdownToJSX.Options
}) => {

return (
<>
{blocks &&
Expand Down
18 changes: 12 additions & 6 deletions src/components/blocks/Accordion.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useMemo } from 'react'
import React, { useEffect, useState } from 'react'

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

const isHashSelected = useHashSelected(block.id)

const value = useMemo(() => {
const [open, setOpen] = useState(false)
useEffect(() => {
let opened = false
if (isHashSelected) {
return block.title
opened = true
}
return block.collapsed ? '' : block.title
opened = !block.collapsed
setOpen(opened)
}, [block.collapsed, block.title, isHashSelected])

return (<AccordionSingle
rootProps={{
value: value,
value: open ? block.title : '',
onClick: () => {
setOpen(!open)
}
}}
itemProps={{
value: block.title,
Expand Down

0 comments on commit 87e2ea5

Please sign in to comment.