Skip to content

Commit

Permalink
fix: Panel extra use 0 (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
xrkffgg authored Sep 1, 2021
1 parent 98af802 commit 99b2f9b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import classNames from 'classnames';
import CSSMotion from 'rc-motion';
import shallowEqual from 'shallowequal';
import PanelContent from './PanelContent';
import { CollapsePanelProps } from './interface';
import type { CollapsePanelProps } from './interface';

class CollapsePanel extends React.Component<CollapsePanelProps, any> {
static defaultProps = {
Expand Down Expand Up @@ -73,6 +73,8 @@ class CollapsePanel extends React.Component<CollapsePanelProps, any> {
icon = expandIcon(this.props);
}

const ifExtraExist = extra !== null && extra !== undefined && typeof extra !== 'boolean';

return (
<div className={itemCls} style={style} id={id}>
<div
Expand All @@ -91,7 +93,7 @@ class CollapsePanel extends React.Component<CollapsePanelProps, any> {
) : (
header
)}
{extra && <div className={`${prefixCls}-extra`}>{extra}</div>}
{ifExtraExist && <div className={`${prefixCls}-extra`}>{extra}</div>}
</div>
<CSSMotion
visible={isActive}
Expand Down
15 changes: 15 additions & 0 deletions tests/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,21 @@ describe('collapse', () => {

runNormalTest(element);
});

describe('it shoule support extra whit number 0', () => {
const collapse = mount(
<Collapse onChange={onChange} activeKey={0}>
<Panel header="collapse 0" key={0} extra={0}>
zero
</Panel>
</Collapse>,
);

const extraNodes = collapse.find('.rc-collapse-extra');
expect(extraNodes.length).toBe(1);
expect(extraNodes.at(0).getDOMNode().innerHTML).toBe('0');
});

describe('it should support activeKey number 0', () => {
const collapse = mount(
<Collapse onChange={onChange} activeKey={0}>
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
"rc-collapse": ["src/index.tsx"]
}
}
}
}

1 comment on commit 99b2f9b

@vercel
Copy link

@vercel vercel bot commented on 99b2f9b Sep 1, 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.