Skip to content

Commit b0febf1

Browse files
Zhou-BillzombieJ
andauthored
fix: 根据activeKey显示额外内容导致最后一个tab点击失效 (#662)
* fix: 根据activeKey显示额外内容导致最后一个tab点击失效 * fix: 添加动态extra demo * chore: back of origin resize --------- Co-authored-by: Bill <[email protected]> Co-authored-by: 二货机器人 <[email protected]>
1 parent 0bce955 commit b0febf1

File tree

3 files changed

+60
-12
lines changed

3 files changed

+60
-12
lines changed

docs/demo/dynamic-extra.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: dynamic-extra
3+
nav:
4+
title: Demo
5+
path: /demo
6+
---
7+
8+
<code src="../examples/dynamic-extra.tsx"></code>

docs/examples/dynamic-extra.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React from 'react';
2+
import Tabs from '../../src';
3+
import type { TabsProps } from '../../src';
4+
import '../../assets/index.less';
5+
6+
const items: TabsProps['items'] = [];
7+
for (let i = 0; i < 50; i += 1) {
8+
items.push({
9+
key: String(i),
10+
label: `Tab ${i}`,
11+
children: `Content of ${i}`,
12+
});
13+
}
14+
export default () => {
15+
const [key, setKey] = React.useState('0');
16+
17+
const extra = React.useMemo(() => {
18+
if (key === '0') {
19+
return (
20+
<div>额外内容</div>
21+
)
22+
}
23+
return null
24+
}, [key])
25+
26+
return (
27+
<div style={{ maxWidth: 550 }}>
28+
<Tabs
29+
activeKey={key}
30+
onChange={(curKey) => setKey(curKey)}
31+
tabBarExtraContent={extra}
32+
defaultActiveKey="8"
33+
moreIcon="..."
34+
items={items}
35+
/>
36+
</div>
37+
);
38+
};

src/TabNavList/index.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -426,16 +426,17 @@ function TabNavList(props: TabNavListProps, ref: React.Ref<HTMLDivElement>) {
426426
>
427427
<ExtraContent ref={extraLeftRef} position="left" extra={extra} prefixCls={prefixCls} />
428428

429-
<div
430-
className={classNames(wrapPrefix, {
431-
[`${wrapPrefix}-ping-left`]: pingLeft,
432-
[`${wrapPrefix}-ping-right`]: pingRight,
433-
[`${wrapPrefix}-ping-top`]: pingTop,
434-
[`${wrapPrefix}-ping-bottom`]: pingBottom,
435-
})}
436-
ref={tabsWrapperRef}
437-
>
438-
<ResizeObserver onResize={onListHolderResize}>
429+
<ResizeObserver onResize={onListHolderResize}>
430+
<div
431+
className={classNames(wrapPrefix, {
432+
[`${wrapPrefix}-ping-left`]: pingLeft,
433+
[`${wrapPrefix}-ping-right`]: pingRight,
434+
[`${wrapPrefix}-ping-top`]: pingTop,
435+
[`${wrapPrefix}-ping-bottom`]: pingBottom,
436+
})}
437+
ref={tabsWrapperRef}
438+
>
439+
<ResizeObserver onResize={onListHolderResize}>
439440
<div
440441
ref={tabListRef}
441442
className={`${prefixCls}-nav-list`}
@@ -463,8 +464,9 @@ function TabNavList(props: TabNavListProps, ref: React.Ref<HTMLDivElement>) {
463464
style={indicatorStyle}
464465
/>
465466
</div>
466-
</ResizeObserver>
467-
</div>
467+
</ResizeObserver>
468+
</div>
469+
</ResizeObserver>
468470

469471
<OperationNode
470472
{...props}

0 commit comments

Comments
 (0)