Skip to content

Commit

Permalink
fix: Not break if tabBarExtraContent is empty object (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ authored Jul 29, 2021
1 parent 0e9f8ab commit 48afe60
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/TabNavList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,20 @@ const ExtraContent = ({ position, prefixCls, extra }: ExtraContentProps) => {

let content: React.ReactNode;

const assertExtra = extra as TabBarExtraMap;
// Parse extra
let assertExtra: TabBarExtraMap = {};
if (extra && typeof extra === 'object' && !React.isValidElement(extra)) {
assertExtra = extra as TabBarExtraMap;
} else {
assertExtra.right = extra;
}

if (position === 'right') {
content = assertExtra.right || (!assertExtra.left && assertExtra) || null;
content = assertExtra.right;
}

if (position === 'left') {
content = assertExtra.left || null;
content = assertExtra.left;
}

return content ? <div className={`${prefixCls}-extra-content`}>{content}</div> : null;
Expand Down
6 changes: 5 additions & 1 deletion tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ describe('Tabs.Basic', () => {
expect(wrapper.find('.rc-tabs-extra-content').text()).toEqual('Bamboo');
});

it('extra positon', () => {
it('extra position', () => {
const wrapper = mount(
getTabs({ tabBarExtraContent: { left: 'Left Bamboo', right: 'Right Bamboo' } }),
);
Expand All @@ -249,6 +249,10 @@ describe('Tabs.Basic', () => {
expect(wrapper.find('.rc-tabs-extra-content').at(1).text()).toEqual('Right Bamboo');
});

it('no break of empty object', () => {
mount(getTabs({ tabBarExtraContent: {} }));
});

describe('animated', () => {
it('false', () => {
const wrapper = mount(getTabs({ animated: false }));
Expand Down

1 comment on commit 48afe60

@vercel
Copy link

@vercel vercel bot commented on 48afe60 Jul 29, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.