Skip to content

Commit 6fa1e40

Browse files
committed
fix: ensure immediate visibility for initial mount in useMotion
1 parent b66c67c commit 6fa1e40

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

packages/@primereact/core/src/motion/useMotion.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@ export const useMotion = withHeadless({
100100
if (props.visible) {
101101
if (shouldAppear || !isInitialMount.current) {
102102
enter?.();
103+
} else if (props.cssVarPrefix) {
104+
// Initial mount with visible=true and no appear animation.
105+
// createMotion sets CSS vars to 0px, so we need to override them to auto
106+
// to ensure the content is visible immediately.
107+
const widthVar = resolveCSSVarName(props.cssVarPrefix, 'width');
108+
const heightVar = resolveCSSVarName(props.cssVarPrefix, 'height');
109+
110+
element.style.setProperty(widthVar, 'auto');
111+
element.style.setProperty(heightVar, 'auto');
103112
}
104113
} else {
105114
leave?.()?.then(() => {

0 commit comments

Comments
 (0)