diff --git a/components/card/__tests__/index.test.js b/components/card/__tests__/index.test.js index 8e1cade399..da9a0979c0 100644 --- a/components/card/__tests__/index.test.js +++ b/components/card/__tests__/index.test.js @@ -82,4 +82,22 @@ describe('Card', () => { ); expect(wrapper.find('Tabs').get(0).props.size).toBe('small'); }); + + it('get ref of card', () => { + class WrapperComponent extends React.Component { + render() { + return ( + + Card content + + ); + } + } + const wrapper = mount(); + expect(wrapper.ref('firstRef').className.includes('ant-card')).toBe(true); + }); }); diff --git a/components/card/index.tsx b/components/card/index.tsx index 983eb92c89..b4b39ac0db 100644 --- a/components/card/index.tsx +++ b/components/card/index.tsx @@ -56,12 +56,12 @@ export interface CardProps extends Omit, 't tabProps?: TabsProps; } -export interface CardInterface extends React.FC { +export interface CardInterface extends React.ForwardRefExoticComponent { Grid: typeof Grid; Meta: typeof Meta; } -const Card: CardInterface = props => { +const Card = React.forwardRef((props: CardProps, ref: React.Ref) => { const { getPrefixCls, direction } = React.useContext(ConfigContext); const size = React.useContext(SizeContext); @@ -196,14 +196,14 @@ const Card: CardInterface = props => { ); return ( - + {head} {coverDom} {body} {actionDom} ); -}; +}) as CardInterface; Card.Grid = Grid; Card.Meta = Meta;
Card content