Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Card support tabProps #22207

Merged
merged 3 commits into from
Mar 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions components/card/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,22 @@ describe('Card', () => {
);
expect(wrapper.find('.ant-card-actions').length).toBe(0);
});

it('with tab props', () => {
const wrapper = mount(
<Card
title="Card title"
tabList={[
{
key: 'key',
tab: 'tab',
},
]}
tabProps={{ size: 'small' }}
>
<p>Card content</p>
</Card>,
);
expect(wrapper.find('Tabs').get(0).props.size).toBe('small');
});
});
1 change: 1 addition & 0 deletions components/card/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ A card can be used to display content related to a single subject. The content c
| title | Card title | string\|ReactNode | - | |
| type | Card style type, can be set to `inner` or not set | string | - | |
| onTabChange | Callback when tab is switched | (key) => void | - | |
| tabProps | [Tabs](https://ant.design/components/tabs/#Tabs) | - | - | |

### Card.Grid

Expand Down
7 changes: 5 additions & 2 deletions components/card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import classNames from 'classnames';
import omit from 'omit.js';
import Grid from './Grid';
import Meta from './Meta';
import Tabs from '../tabs';
import Tabs, { TabsProps } from '../tabs';
import Row from '../row';
import Col from '../col';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
Expand Down Expand Up @@ -54,6 +54,7 @@ export interface CardProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 't
onTabChange?: (key: string) => void;
activeTabKey?: string;
defaultActiveTabKey?: string;
tabProps?: TabsProps;
}

export default class Card extends React.Component<CardProps, {}> {
Expand Down Expand Up @@ -97,6 +98,7 @@ export default class Card extends React.Component<CardProps, {}> {
defaultActiveTabKey,
tabBarExtraContent,
hoverable,
tabProps = {},
...others
} = this.props;

Expand Down Expand Up @@ -152,6 +154,7 @@ export default class Card extends React.Component<CardProps, {}> {

const hasActiveTabKey = activeTabKey !== undefined;
const extraProps = {
...tabProps,
[hasActiveTabKey ? 'activeKey' : 'defaultActiveKey']: hasActiveTabKey
? activeTabKey
: defaultActiveTabKey,
Expand All @@ -162,9 +165,9 @@ export default class Card extends React.Component<CardProps, {}> {
const tabs =
tabList && tabList.length ? (
<Tabs
size="large"
{...extraProps}
className={`${prefixCls}-head-tabs`}
size="large"
onChange={this.onTabChange}
>
{tabList.map(item => (
Expand Down
1 change: 1 addition & 0 deletions components/card/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ cols: 1
| title | 卡片标题 | string\|ReactNode | - | |
| type | 卡片类型,可设置为 `inner` 或 不设置 | string | - | |
| onTabChange | 页签切换的回调 | (key) => void | - | |
| tabProps | [Tabs](https://ant.design/components/tabs-cn/#Tabs) | - | - | |

### Card.Grid

Expand Down