This commit is contained in:
egnbkts committed 2026-09-08 09:49:27 +02:00
1 parent 574e07603d
commit cc2b84dcad
27 files changed
+2214 -360

No files matched your search

+10 -3
View File
@@ -9,21 +9,28 @@ export function useHeightVar(
cssVarName: string,
mode: Mode = "scroll",
trigger?: unknown,
targetRef?: React.RefObject<HTMLElement | null>,
) {
useLayoutEffect(() => {
const el = ref.current;
if (!el) return;
const target = targetRef?.current ?? el;
const measure = () => {
const h = mode === "scroll" ? el.scrollHeight : el.offsetHeight;
el.style.setProperty(cssVarName, `${h}px`);
target.style.setProperty(cssVarName, `${h}px`);
};
measure();
// Observe el (the unclipped content), not target: if target is the
// element whose max-height is being CSS-transitioned, observing it
// directly re-triggers measure() on every layout step of the
// transition, fighting the animation (visible as stutter in Firefox).
const ro = new ResizeObserver(measure);
ro.observe(el);
return () => ro.disconnect();
}, [ref, cssVarName, mode, trigger]);
}
}, [ref, targetRef, cssVarName, mode, trigger]);
}