Skip to content

Commit

Permalink
fix(OptionTile): animation flicker when collapsing options tile (carb…
Browse files Browse the repository at this point in the history
  • Loading branch information
amal-k-joy authored Jun 14, 2024
1 parent 4deacf2 commit 0be8378
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/ibm-products/src/components/OptionsTile/OptionsTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ export let OptionsTile = React.forwardRef(
contentRef.current
);

const animationDuration = Number(
carbonMotion.moderate01.replace('ms', '')
);
const animation = contentRef.current.animate(
[
{
Expand All @@ -237,7 +240,7 @@ export let OptionsTile = React.forwardRef(
},
],
{
duration: Number(carbonMotion.moderate01.replace('ms', '')),
duration: animationDuration,
easing: carbonMotion.easings.entrance.productive,
}
);
Expand All @@ -247,7 +250,14 @@ export let OptionsTile = React.forwardRef(
setClosing(false);
};

animation.onfinish = callback;
//This is to fix the flicking issue while collapsing.
//root cause : after the animation is finished , isOpen is still true until onFinish callback is triggered.For that minute duration , collapsed content will again show.
// To avoid this , isOpen is set to false after the 90% of animation duration.
setTimeout(() => {
callback();
}, animationDuration * 0.9);

// animation.onfinish = callback;
animation.oncancel = callback;
} else {
// in case the ref is not set or the user prefers reduced motion, skip the animation
Expand Down

0 comments on commit 0be8378

Please sign in to comment.