Skip to content

Commit

Permalink
fix: 根据activeKey显示额外内容导致最后一个tab点击失效 (#662)
Browse files Browse the repository at this point in the history
* fix: 根据activeKey显示额外内容导致最后一个tab点击失效

* fix: 添加动态extra demo

* chore: back of origin resize

---------

Co-authored-by: Bill <[email protected]>
Co-authored-by: 二货机器人 <[email protected]>
  • Loading branch information
3 people authored Sep 6, 2023
1 parent 0bce955 commit b0febf1
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 12 deletions.
8 changes: 8 additions & 0 deletions docs/demo/dynamic-extra.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: dynamic-extra
nav:
title: Demo
path: /demo
---

<code src="../examples/dynamic-extra.tsx"></code>
38 changes: 38 additions & 0 deletions docs/examples/dynamic-extra.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react';
import Tabs from '../../src';
import type { TabsProps } from '../../src';
import '../../assets/index.less';

const items: TabsProps['items'] = [];
for (let i = 0; i < 50; i += 1) {
items.push({
key: String(i),
label: `Tab ${i}`,
children: `Content of ${i}`,
});
}
export default () => {
const [key, setKey] = React.useState('0');

const extra = React.useMemo(() => {
if (key === '0') {
return (
<div>额外内容</div>
)
}
return null
}, [key])

return (
<div style={{ maxWidth: 550 }}>
<Tabs
activeKey={key}
onChange={(curKey) => setKey(curKey)}
tabBarExtraContent={extra}
defaultActiveKey="8"
moreIcon="..."
items={items}
/>
</div>
);
};
26 changes: 14 additions & 12 deletions src/TabNavList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -426,16 +426,17 @@ function TabNavList(props: TabNavListProps, ref: React.Ref<HTMLDivElement>) {
>
<ExtraContent ref={extraLeftRef} position="left" extra={extra} prefixCls={prefixCls} />

<div
className={classNames(wrapPrefix, {
[`${wrapPrefix}-ping-left`]: pingLeft,
[`${wrapPrefix}-ping-right`]: pingRight,
[`${wrapPrefix}-ping-top`]: pingTop,
[`${wrapPrefix}-ping-bottom`]: pingBottom,
})}
ref={tabsWrapperRef}
>
<ResizeObserver onResize={onListHolderResize}>
<ResizeObserver onResize={onListHolderResize}>
<div
className={classNames(wrapPrefix, {
[`${wrapPrefix}-ping-left`]: pingLeft,
[`${wrapPrefix}-ping-right`]: pingRight,
[`${wrapPrefix}-ping-top`]: pingTop,
[`${wrapPrefix}-ping-bottom`]: pingBottom,
})}
ref={tabsWrapperRef}
>
<ResizeObserver onResize={onListHolderResize}>
<div
ref={tabListRef}
className={`${prefixCls}-nav-list`}
Expand Down Expand Up @@ -463,8 +464,9 @@ function TabNavList(props: TabNavListProps, ref: React.Ref<HTMLDivElement>) {
style={indicatorStyle}
/>
</div>
</ResizeObserver>
</div>
</ResizeObserver>
</div>
</ResizeObserver>

<OperationNode
{...props}
Expand Down

1 comment on commit b0febf1

@vercel
Copy link

@vercel vercel bot commented on b0febf1 Sep 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

tabs – ./

tabs-react-component.vercel.app
tabs-git-master-react-component.vercel.app

Please sign in to comment.