@@ -8,6 +8,7 @@ export * from './Pane';
8
8
9
9
Tabs . Pane = Pane ;
10
10
11
+ let labelWidth : number = 0 ;
11
12
export interface TabsProps extends IProps , HTMLDivProps {
12
13
prefixCls ?: string ;
13
14
activeKey ?: string ;
@@ -65,12 +66,16 @@ export default function Tabs(props: TabsProps) {
65
66
}
66
67
} , [ ] ) ;
67
68
68
- const divNavRef = useCallback ( ( node , key : number ) => {
69
+ const divNavRef = useCallback ( ( node , key : number , itemKey : React . Key | null ) => {
69
70
if ( node !== null ) {
70
71
node . addEventListener ( 'click' , ( e : any ) => {
71
72
activeItem . current = node ;
72
73
} ) ;
73
74
divNavWidthChange ( node . getBoundingClientRect ( ) . width , key ) ;
75
+
76
+ if ( itemKey === props . activeKey && type === 'line' && labelWidth === 0 ) {
77
+ activeItem . current = node ;
78
+ }
74
79
}
75
80
} , [ ] ) ;
76
81
@@ -103,6 +108,7 @@ export default function Tabs(props: TabsProps) {
103
108
104
109
function calcSlideStyle ( ) {
105
110
if ( activeItem . current && type === 'line' ) {
111
+ labelWidth = activeItem . current . clientWidth ;
106
112
setSlideStyle ( {
107
113
width : activeItem . current . clientWidth ,
108
114
left : activeItem . current . offsetLeft ,
@@ -170,7 +176,7 @@ export default function Tabs(props: TabsProps) {
170
176
calcSlideStyle ( ) ;
171
177
} ;
172
178
}
173
- return < div key = { key } ref = { ( ref ) => divNavRef ( ref , key ) } { ...divProps } /> ;
179
+ return < div key = { key } ref = { ( ref ) => divNavRef ( ref , key , item . key ) } { ...divProps } /> ;
174
180
} ) ;
175
181
}
176
182
}
0 commit comments