diff --git a/src/components/Collapsible/Collapsible.css b/src/components/Collapsible/Collapsible.css index cacc369..3930037 100644 --- a/src/components/Collapsible/Collapsible.css +++ b/src/components/Collapsible/Collapsible.css @@ -23,18 +23,19 @@ outline-offset: 2px; } - .collapsible-content { - max-height: 0; + .collapsible .collapsible-content { overflow: hidden; - transition: max-height 0.5s ease-in-out; - background: var(--ifm-background-color); - border-top: none; - padding: 0 1rem; - } - - .collapsible-content.open { - max-height: 500px; - padding-top: 0.5rem; - padding-bottom: 1rem; - } + background: var(--ifm-background-color); + transition: max-height 0.5s ease-in-out, padding 0.5s ease-in-out; + padding: 0; + margin: 0; + display: none; +} + +.collapsible .collapsible-content.open { + display: block; + padding: 0.5rem 1rem; + max-height: auto; +} + \ No newline at end of file diff --git a/src/components/Collapsible/Collapsible.tsx b/src/components/Collapsible/Collapsible.tsx index 7941339..b0f5d41 100644 --- a/src/components/Collapsible/Collapsible.tsx +++ b/src/components/Collapsible/Collapsible.tsx @@ -1,4 +1,4 @@ -import React, { useRef, useState, useEffect } from 'react'; +import React, { useState } from 'react'; import './Collapsible.css'; export interface CollapsibleProps { @@ -8,16 +8,6 @@ export interface CollapsibleProps { const Collapsible: React.FC = ({ title, children }) => { const [isOpen, setIsOpen] = useState(false); - const contentRef = useRef(null); - const [maxHeight, setMaxHeight] = useState('0px'); - - useEffect(() => { - if (isOpen && contentRef.current) { - setMaxHeight(`${contentRef.current.scrollHeight}px`); - } else { - setMaxHeight('0px'); - } - }, [isOpen]); return (
@@ -25,11 +15,9 @@ const Collapsible: React.FC = ({ title, children }) => { {isOpen ? '▼' : '►'} {title}
- {children} + {isOpen && children}
);