Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/_helpers/expand-transition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export function ExpandTransition({
const [removeElement, setRemoveElement] = useState(!show);
const expandableRef = useRef<HTMLDivElement>(null);
const isMounted = useRef(false);
const initialShow = useRef<boolean>(show === true);

function collapseElement(el: HTMLElement) {
collapse(el, () => setRemoveElement(true));
Expand Down Expand Up @@ -37,8 +38,15 @@ export function ExpandTransition({
}
}, [show]);

// Set initial style to prevent glitching bug
const initialStyle = !initialShow.current ? 'overflow-hidden h-0' : undefined;

return (
<div ref={expandableRef} aria-hidden={!show ? true : undefined}>
<div
className={initialStyle}
ref={expandableRef}
aria-hidden={!show ? true : undefined}
>
{removeElement ? null : children}
</div>
);
Expand Down
8 changes: 8 additions & 0 deletions packages/expandable/stories/Expandable.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ export const Animated = () => {
);
};

export const AnimatedExpanded = () => {
return (
<Expandable title="Animated box" expanded box info animated>
<h1>I am expandable</h1>
</Expandable>
);
};

export const Heading = () => {
return (
<Expandable title="I'm also a heading" headingLevel={1}>
Expand Down