Skip to content

Commit 1feba3a

Browse files
authored
fix(Tabs): 修复activeKey 高亮下划线未展示问题 #709 (#716)
1 parent d34df0a commit 1feba3a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

‎packages/react-tabs/src/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export * from './Pane';
88

99
Tabs.Pane = Pane;
1010

11+
let labelWidth: number = 0;
1112
export interface TabsProps extends IProps, HTMLDivProps {
1213
prefixCls?: string;
1314
activeKey?: string;
@@ -65,12 +66,16 @@ export default function Tabs(props: TabsProps) {
6566
}
6667
}, []);
6768

68-
const divNavRef = useCallback((node, key: number) => {
69+
const divNavRef = useCallback((node, key: number, itemKey: React.Key | null) => {
6970
if (node !== null) {
7071
node.addEventListener('click', (e: any) => {
7172
activeItem.current = node;
7273
});
7374
divNavWidthChange(node.getBoundingClientRect().width, key);
75+
76+
if (itemKey === props.activeKey && type === 'line' && labelWidth === 0) {
77+
activeItem.current = node;
78+
}
7479
}
7580
}, []);
7681

@@ -103,6 +108,7 @@ export default function Tabs(props: TabsProps) {
103108

104109
function calcSlideStyle() {
105110
if (activeItem.current && type === 'line') {
111+
labelWidth = activeItem.current.clientWidth;
106112
setSlideStyle({
107113
width: activeItem.current.clientWidth,
108114
left: activeItem.current.offsetLeft,
@@ -170,7 +176,7 @@ export default function Tabs(props: TabsProps) {
170176
calcSlideStyle();
171177
};
172178
}
173-
return <div key={key} ref={(ref) => divNavRef(ref, key)} {...divProps} />;
179+
return <div key={key} ref={(ref) => divNavRef(ref, key, item.key)} {...divProps} />;
174180
});
175181
}
176182
}

0 commit comments

Comments
 (0)