feat(layout): disable transition when promoted attributes are shown by default

This commit is contained in:
Elian Doran
2025-12-15 12:14:44 +02:00
parent 455dc5dc11
commit ad8e52f744
2 changed files with 19 additions and 3 deletions

View File

@@ -17,7 +17,6 @@
.collapsible-body { .collapsible-body {
height: 0; height: 0;
overflow: hidden; overflow: hidden;
transition: height 250ms ease-in;
} }
.collapsible-inner-body { .collapsible-inner-body {
@@ -29,4 +28,10 @@
transform: rotate(90deg); transform: rotate(90deg);
} }
} }
&.with-transition {
.collapsible-body {
transition: height 250ms ease-in;
}
}
} }

View File

@@ -2,7 +2,7 @@ import "./Collapsible.css";
import clsx from "clsx"; import clsx from "clsx";
import { ComponentChildren, HTMLAttributes } from "preact"; import { ComponentChildren, HTMLAttributes } from "preact";
import { useRef, useState } from "preact/hooks"; import { useEffect, useRef, useState } from "preact/hooks";
import { useElementSize, useUniqueName } from "./hooks"; import { useElementSize, useUniqueName } from "./hooks";
import Icon from "./Icon"; import Icon from "./Icon";
@@ -26,9 +26,20 @@ export function ExternallyControlledCollapsible({ title, children, className, ex
const innerRef = useRef<HTMLDivElement>(null); const innerRef = useRef<HTMLDivElement>(null);
const { height } = useElementSize(innerRef) ?? {}; const { height } = useElementSize(innerRef) ?? {};
const contentId = useUniqueName(); const contentId = useUniqueName();
const [ transitionEnabled, setTransitionEnabled ] = useState(false);
useEffect(() => {
const timeout = setTimeout(() => {
setTransitionEnabled(true);
}, 200);
return () => clearTimeout(timeout);
}, []);
return ( return (
<div className={clsx("collapsible", className, expanded && "expanded")}> <div className={clsx("collapsible", className, {
expanded,
"with-transition": transitionEnabled
})}>
<button <button
className="collapsible-title" className="collapsible-title"
onClick={() => setExpanded(!expanded)} onClick={() => setExpanded(!expanded)}