Skip to content

Commit ca8a22d

Browse files
authored
fix: Tabs position calculation (#595)
* chore: init * fix: active switch * chore: refactor * fix: Calculation logic * chore: unique logic * refactor: Move into arr * chore: sync container size * refactor: outer get value * refactor: Replace with value * refactor: RM size code * chore: move scroll * chore: clean up * chore: code back * test: fix test case * test: back of all test case * chore: clean up
1 parent 2f4af9b commit ca8a22d

File tree

9 files changed

+307
-242
lines changed

9 files changed

+307
-242
lines changed

docs/examples/overflow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import '../../assets/index.less';
55

66
const items: TabsProps['items'] = [];
77

8-
for (let i = 0; i < 200; i += 1) {
8+
for (let i = 0; i < 12; i += 1) {
99
items.push({ key: String(i), label: `Tab ${i}`, children: `Content of ${i}` });
1010
}
1111

src/TabNavList/ExtraContent.tsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import * as React from 'react';
2+
import type { TabBarExtraPosition, TabBarExtraContent, TabBarExtraMap } from '../interface';
3+
4+
interface ExtraContentProps {
5+
position: TabBarExtraPosition;
6+
prefixCls: string;
7+
extra?: TabBarExtraContent;
8+
}
9+
10+
const ExtraContent = React.forwardRef<HTMLDivElement, ExtraContentProps>(
11+
({ position, prefixCls, extra }, ref) => {
12+
if (!extra) return null;
13+
14+
let content: React.ReactNode;
15+
16+
// Parse extra
17+
let assertExtra: TabBarExtraMap = {};
18+
if (typeof extra === 'object' && !React.isValidElement(extra)) {
19+
assertExtra = extra as TabBarExtraMap;
20+
} else {
21+
assertExtra.right = extra;
22+
}
23+
24+
if (position === 'right') {
25+
content = assertExtra.right;
26+
}
27+
28+
if (position === 'left') {
29+
content = assertExtra.left;
30+
}
31+
32+
return content ? (
33+
<div className={`${prefixCls}-extra-content`} ref={ref}>
34+
{content}
35+
</div>
36+
) : null;
37+
},
38+
);
39+
40+
if (process.env.NODE_ENV !== 'production') {
41+
ExtraContent.displayName = 'ExtraContent';
42+
}
43+
44+
export default ExtraContent;

0 commit comments

Comments
 (0)