@@ -5,6 +5,7 @@ import { makeStyles, mergeClasses } from '@griffel/react';
5
5
import { useTabListContext_unstable } from '../TabList/TabListContext' ;
6
6
import { TabRegisterData } from '../TabList/TabList.types' ;
7
7
import { tokens } from '@fluentui/react-theme' ;
8
+ import { useAnimationFrame } from '@fluentui/react-utilities' ;
8
9
9
10
// eslint-disable-next-line @typescript-eslint/naming-convention
10
11
const tabIndicatorCssVars_unstable = {
@@ -80,11 +81,7 @@ export const useTabAnimatedIndicatorStyles_unstable = (state: TabState): TabStat
80
81
const [ animationValues , setAnimationValues ] = React . useState ( { offset : 0 , scale : 1 } ) ;
81
82
const getRegisteredTabs = useTabListContext_unstable ( ctx => ctx . getRegisteredTabs ) ;
82
83
83
- React . useEffect ( ( ) => {
84
- if ( isValueDefined ( lastAnimatedFrom ) ) {
85
- setAnimationValues ( { offset : 0 , scale : 1 } ) ;
86
- }
87
- } , [ lastAnimatedFrom ] ) ;
84
+ const [ requestAnimationFrame ] = useAnimationFrame ( ) ;
88
85
89
86
if ( selected ) {
90
87
const { previousSelectedValue, selectedValue, registeredTabs } = getRegisteredTabs ( ) ;
@@ -104,6 +101,9 @@ export const useTabAnimatedIndicatorStyles_unstable = (state: TabState): TabStat
104
101
105
102
setAnimationValues ( { offset, scale } ) ;
106
103
setLastAnimatedFrom ( previousSelectedValue ) ;
104
+
105
+ // Reset the animation values after the animation is complete
106
+ requestAnimationFrame ( ( ) => setAnimationValues ( { offset : 0 , scale : 1 } ) ) ;
107
107
}
108
108
}
109
109
} else if ( isValueDefined ( lastAnimatedFrom ) ) {
0 commit comments