@@ -18,6 +18,7 @@ import CardTitle from './CardTitle';
1818import { getCardColors } from './utils' ;
1919import { useInternalTheme } from '../../core/theming' ;
2020import type { $Omit , ThemeProp } from '../../types' ;
21+ import { forwardRef } from '../../utils/forwardRef' ;
2122import hasTouchHandler from '../../utils/hasTouchHandler' ;
2223import { splitStyles } from '../../utils/splitStyles' ;
2324import Surface from '../Surface' ;
@@ -130,23 +131,26 @@ export type Props = $Omit<React.ComponentProps<typeof Surface>, 'mode'> & {
130131 * export default MyComponent;
131132 * ```
132133 */
133- const Card = ( {
134- elevation : cardElevation = 1 ,
135- delayLongPress,
136- onPress,
137- onLongPress,
138- onPressOut,
139- onPressIn,
140- mode : cardMode = 'elevated' ,
141- children,
142- style,
143- contentStyle,
144- theme : themeOverrides ,
145- testID = 'card' ,
146- accessible,
147- disabled,
148- ...rest
149- } : ( OutlinedCardProps | ElevatedCardProps | ContainedCardProps ) & Props ) => {
134+ const CardComponent = (
135+ {
136+ elevation : cardElevation = 1 ,
137+ delayLongPress,
138+ onPress,
139+ onLongPress,
140+ onPressOut,
141+ onPressIn,
142+ mode : cardMode = 'elevated' ,
143+ children,
144+ style,
145+ contentStyle,
146+ theme : themeOverrides ,
147+ testID = 'card' ,
148+ accessible,
149+ disabled,
150+ ...rest
151+ } : ( OutlinedCardProps | ElevatedCardProps | ContainedCardProps ) & Props ,
152+ ref : React . ForwardedRef < View >
153+ ) => {
150154 const theme = useInternalTheme ( themeOverrides ) ;
151155 const isMode = React . useCallback (
152156 ( modeToCompare : Mode ) => {
@@ -274,6 +278,7 @@ const Card = ({
274278
275279 return (
276280 < Surface
281+ ref = { ref }
277282 style = { [
278283 isV3 && ! isMode ( 'elevated' ) && { backgroundColor } ,
279284 ! isV3 && isMode ( 'outlined' )
@@ -325,6 +330,16 @@ const Card = ({
325330 ) ;
326331} ;
327332
333+ const Component = forwardRef ( CardComponent ) ;
334+ Component . displayName = 'Card' ;
335+
336+ const Card = Component as typeof Component & {
337+ Content : typeof CardContent ;
338+ Actions : typeof CardActions ;
339+ Cover : typeof CardCover ;
340+ Title : typeof CardTitle ;
341+ } ;
342+
328343// @component ./CardContent.tsx
329344Card . Content = CardContent ;
330345// @component ./CardActions.tsx
0 commit comments