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
[TypeScript] Update SnackbarContent type def to accept action prop as array #12595
[TypeScript] Update SnackbarContent type def to accept action prop as array #12595
Conversation
@@ -3,7 +3,7 @@ import { StandardProps } from '..'; | |||
import { PaperProps } from '../Paper'; | |||
|
|||
export interface SnackbarContentProps extends StandardProps<PaperProps, SnackbarContentClassKey> { | |||
action?: React.ReactElement<any>; | |||
action?: React.ReactElement<any> | React.ReactElement<any>[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tried React.ReactNode
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick feedback!
I tried that just now, replacing the entire union with React.ReactNode
, and it does resolve the issue. If that's the more appropriate/idiomatic fix, would it make sense to apply the same change to the Snackbar
interface?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and we can update message
definition too.
@@ -13,12 +13,12 @@ export interface SnackbarProps | |||
React.HTMLAttributes<HTMLDivElement> & Partial<TransitionHandlerProps>, | |||
SnackbarClassKey | |||
> { | |||
action?: React.ReactElement<any> | React.ReactElement<any>[]; | |||
action?: React.ReactNode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this property is passed to SnackBarContent
it should explicitly reference that type like SnackBarContentProps['action']
. Same for message
.
853c67b
to
0c6397e
Compare
@cngraf It's a great first pull request on Material-UI 👌🏻. Thank you for giving it a shot! |
Thanks for making it easy to contribute, @oliviertassinari and @eps1lon! Everything is so organized and well-documented, it's approachable even for a React newcomer like myself. |
Closes #12594
This PR alters the
SnackbarContentProps
interface. I've updated theaction
prop to a type union that accepts both a single element and an array of elements. TheSnackbar
component already uses the same union type for its action prop (source), and I couldn't find any documentation suggestingSnackbarContent
should behave any differently.I've also added a test to confirm the existing expected behavior, outside the type defs.