Skip to content

Commit 9250e34

Browse files
authored
fix(react-tabs): fix active tab indicator animation (#34060)
1 parent 5898a32 commit 9250e34

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "fix: fix active tab indicator animation",
4+
"packageName": "@fluentui/react-tabs",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/react-components/react-tabs/library/src/components/Tab/useTabAnimatedIndicator.styles.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { makeStyles, mergeClasses } from '@griffel/react';
55
import { useTabListContext_unstable } from '../TabList/TabListContext';
66
import { TabRegisterData } from '../TabList/TabList.types';
77
import { tokens } from '@fluentui/react-theme';
8+
import { useAnimationFrame } from '@fluentui/react-utilities';
89

910
// eslint-disable-next-line @typescript-eslint/naming-convention
1011
const tabIndicatorCssVars_unstable = {
@@ -80,11 +81,7 @@ export const useTabAnimatedIndicatorStyles_unstable = (state: TabState): TabStat
8081
const [animationValues, setAnimationValues] = React.useState({ offset: 0, scale: 1 });
8182
const getRegisteredTabs = useTabListContext_unstable(ctx => ctx.getRegisteredTabs);
8283

83-
React.useEffect(() => {
84-
if (isValueDefined(lastAnimatedFrom)) {
85-
setAnimationValues({ offset: 0, scale: 1 });
86-
}
87-
}, [lastAnimatedFrom]);
84+
const [requestAnimationFrame] = useAnimationFrame();
8885

8986
if (selected) {
9087
const { previousSelectedValue, selectedValue, registeredTabs } = getRegisteredTabs();
@@ -104,6 +101,9 @@ export const useTabAnimatedIndicatorStyles_unstable = (state: TabState): TabStat
104101

105102
setAnimationValues({ offset, scale });
106103
setLastAnimatedFrom(previousSelectedValue);
104+
105+
// Reset the animation values after the animation is complete
106+
requestAnimationFrame(() => setAnimationValues({ offset: 0, scale: 1 }));
107107
}
108108
}
109109
} else if (isValueDefined(lastAnimatedFrom)) {

0 commit comments

Comments
 (0)