Skip to content

Commit

Permalink
Merge pull request #1405 from vitorRibeiro7/hotfix-game-minimun-specs…
Browse files Browse the repository at this point in the history
…-accordion

fix: fix css bug on requirements details style
  • Loading branch information
thegrannychaseroperation authored Jan 17, 2025
2 parents 9574e39 + cd871ec commit 8a30e94
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChevronDownIcon } from "@primer/octicons-react";
import { useRef, useState } from "react";
import { useEffect, useRef, useState } from "react";

import * as styles from "./sidebar-section.css";

Expand All @@ -11,6 +11,15 @@ export interface SidebarSectionProps {
export function SidebarSection({ title, children }: SidebarSectionProps) {
const content = useRef<HTMLDivElement>(null);
const [isOpen, setIsOpen] = useState(true);
const [height, setHeight] = useState(0);

useEffect(() => {
if (content.current && content.current.scrollHeight !== height) {
setHeight(isOpen ? content.current.scrollHeight : 0);
} else if (!isOpen) {
setHeight(0);
}
}, [isOpen, children, height]);

return (
<div>
Expand All @@ -26,7 +35,7 @@ export function SidebarSection({ title, children }: SidebarSectionProps) {
<div
ref={content}
style={{
maxHeight: isOpen ? `${content.current?.scrollHeight}px` : "0",
maxHeight: `${height}px`,
overflow: "hidden",
transition: "max-height 0.4s cubic-bezier(0, 1, 0, 1)",
position: "relative",
Expand Down

0 comments on commit 8a30e94

Please sign in to comment.