Skip to content

Commit 9e5353b

Browse files
authored
feat: render tab bar use panes (#291)
* feat: render tab bar use panes * chore: lint * fix: lint errors * fix: quote * chore
1 parent effe5a2 commit 9e5353b

File tree

5 files changed

+66
-11
lines changed

5 files changed

+66
-11
lines changed

.eslintrc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,7 @@ module.exports = {
2222
{ devDependencies: true, optionalDependencies: false, peerDependencies: false },
2323
],
2424
'brace-style': 0,
25+
'no-unused-expressions': 0,
26+
'@typescript-eslint/no-unused-expressions': 1,
2527
},
2628
};

examples/renderTabBar-use-panes.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
import Tabs, { TabPane } from '../src';
3+
import '../assets/index.less';
4+
5+
const renderTabBar = props => {
6+
return (
7+
<div>
8+
{props.panes.map(pane => {
9+
const key = pane.key;
10+
return <span key={key}>{key}</span>;
11+
})}
12+
</div>
13+
);
14+
};
15+
16+
export default () => {
17+
return (
18+
<div style={{ height: 2000 }}>
19+
<Tabs defaultActiveKey="1" renderTabBar={renderTabBar}>
20+
<TabPane tab="Tab 1" key="1" style={{ height: 200 }}>
21+
Content of Tab Pane 1
22+
</TabPane>
23+
<TabPane tab="Tab 2" key="2">
24+
Content of Tab Pane 2
25+
</TabPane>
26+
<TabPane tab="Tab 3" key="3">
27+
Content of Tab Pane 3
28+
</TabPane>
29+
</Tabs>
30+
</div>
31+
);
32+
};

src/TabNavList/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export interface TabNavListProps {
2828
tabPosition: TabPosition;
2929
activeKey: string;
3030
rtl: boolean;
31+
panes: React.ReactNode;
3132
animated?: AnimatedConfig;
3233
extra?: React.ReactNode;
3334
editable?: EditableConfig;

src/Tabs.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ function Tabs(
201201
onTabScroll,
202202
extra: tabBarExtraContent,
203203
style: tabBarStyle,
204+
panes: children,
204205
};
205206

206207
if (renderTabBar) {

tests/index.test.tsx

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,37 @@ describe('Tabs.Basic', () => {
139139
).toEqual(33);
140140
});
141141

142-
it('tabNavBar', () => {
143-
const renderTabBar = jest.fn((props, Component) => {
144-
return (
145-
<div className="my-wrapper">
146-
<Component {...props}>{node => <span className="my-node">{node}</span>}</Component>
147-
</div>
148-
);
142+
describe('renderTabBar', () => {
143+
it('works', () => {
144+
const renderTabBar = jest.fn((props, Component) => {
145+
return (
146+
<div className="my-wrapper">
147+
<Component {...props}>{node => <span className="my-node">{node}</span>}</Component>
148+
</div>
149+
);
150+
});
151+
const wrapper = mount(getTabs({ renderTabBar }));
152+
expect(wrapper.find('.my-wrapper').length).toBeTruthy();
153+
expect(wrapper.find('.my-node').length).toBeTruthy();
154+
expect(renderTabBar).toHaveBeenCalled();
155+
});
156+
it('has panes property in props', () => {
157+
const renderTabBar = props => {
158+
return (
159+
<div>
160+
{props.panes.map(pane => (
161+
<span key={pane.key} data-key={pane.key}>
162+
tab
163+
</span>
164+
))}
165+
</div>
166+
);
167+
};
168+
const wrapper = mount(getTabs({ renderTabBar }));
169+
expect(wrapper.find('[data-key="light"]').length).toBeTruthy();
170+
expect(wrapper.find('[data-key="bamboo"]').length).toBeTruthy();
171+
expect(wrapper.find('[data-key="cute"]').length).toBeTruthy();
149172
});
150-
const wrapper = mount(getTabs({ renderTabBar }));
151-
expect(wrapper.find('.my-wrapper').length).toBeTruthy();
152-
expect(wrapper.find('.my-node').length).toBeTruthy();
153-
expect(renderTabBar).toHaveBeenCalled();
154173
});
155174

156175
it('destroyInactiveTabPane', () => {

0 commit comments

Comments
 (0)