|
1 | | -import React, { ReactNode, type ReactElement } from 'react'; |
| 1 | +import React, { forwardRef, ReactNode, type ReactElement } from 'react'; |
2 | 2 | import styled from 'styled-components'; |
3 | 3 | import { SpaceProps, LayoutProps, PositionProps, FlexboxProps } from 'styled-system'; |
4 | 4 |
|
@@ -32,28 +32,31 @@ const DismissButton = styled(IconButton)` |
32 | 32 | padding: 0; |
33 | 33 | `; |
34 | 34 |
|
35 | | -interface SnackbarProps extends SpaceProps, LayoutProps, PositionProps, FlexboxProps { |
| 35 | +interface SnackbarProps |
| 36 | + extends SpaceProps, |
| 37 | + LayoutProps, |
| 38 | + PositionProps, |
| 39 | + FlexboxProps, |
| 40 | + React.HTMLAttributes<HTMLDivElement> { |
36 | 41 | children: ReactNode; |
37 | 42 | hasDismissButton?: boolean; |
38 | 43 | onDismiss?: () => void; |
39 | 44 | } |
40 | 45 |
|
41 | | -const Snackbar = ({ |
42 | | - children, |
43 | | - hasDismissButton = false, |
44 | | - onDismiss = null, |
45 | | - ...restProps |
46 | | -}: SnackbarProps): ReactElement => ( |
47 | | - <Container {...restProps}> |
48 | | - {children} |
49 | | - {hasDismissButton && ( |
50 | | - <DismissButton |
51 | | - data-testid="snackbar-close-icon" |
52 | | - Icon={() => <XCrossIcon size={24} color={getSemanticValue('inverse-on-surface')} />} |
53 | | - onPress={onDismiss} |
54 | | - /> |
55 | | - )} |
56 | | - </Container> |
| 46 | +const Snackbar = forwardRef<HTMLDivElement, SnackbarProps>( |
| 47 | + ({ children, hasDismissButton = false, onDismiss = null, ...restProps }, ref): ReactElement => ( |
| 48 | + <Container ref={ref} {...restProps}> |
| 49 | + {children} |
| 50 | + {hasDismissButton && ( |
| 51 | + <DismissButton |
| 52 | + data-testid="snackbar-close-icon" |
| 53 | + Icon={() => <XCrossIcon size={24} color={getSemanticValue('inverse-on-surface')} />} |
| 54 | + onPress={onDismiss} |
| 55 | + aria-label="close" |
| 56 | + /> |
| 57 | + )} |
| 58 | + </Container> |
| 59 | + ) |
57 | 60 | ); |
58 | 61 |
|
59 | 62 | export { Snackbar, SnackbarProps }; |
0 commit comments