[materia-ui][StepIcon] Add SvgIconOwnProps type to StepIcon props#44337
[materia-ui][StepIcon] Add SvgIconOwnProps type to StepIcon props#44337DiegoAndai merged 13 commits intomui:masterfrom
Conversation
Netlify deploy previewhttps://deploy-preview-44337--material-ui.netlify.app/ Bundle size report |
| describeConformance(<StepIcon icon={1} />, () => ({ | ||
| classes, | ||
| inheritComponent: 'svg', | ||
| inheritComponent: SvgIcon, |
There was a problem hiding this comment.
this change is to display Props of the SvgIcon component are also available. in props table.
https://deploy-preview-44337--material-ui.netlify.app/material-ui/api/step-icon/#props
| export interface StepIconProps | ||
| extends StandardProps<React.HTMLAttributes<HTMLDivElement>, 'children'> { | ||
| extends StandardProps<React.HTMLAttributes<HTMLDivElement>, 'children'>, | ||
| Omit<SvgIconOwnProps, 'color' | 'children'> { |
There was a problem hiding this comment.
All the props which are passed to StepIcon except StepIconProps are passed to StepIconRoot which is inherited from SvgIcon. so extending SvgIconOwnProps here seemed obvious.
Omitted color due to conflicting types
material-ui/packages/mui-material/src/StepIcon/StepIcon.js
Lines 79 to 85 in 412dcbf
There was a problem hiding this comment.
I think we should use SvgIconProps instead of SvgIconOwnProps, or is there a reason to use the later?
What is the color conflict?
There was a problem hiding this comment.
I think we should use SvgIconProps instead of SvgIconOwnProps, or is there a reason to use the later?
Reason i went for SvgIconOwnProps instead of SvgIconProps is due to conflicting event handler types. For example type of onClick event handler is different in React.HTMLAttributes<HTMLDivElement> and SvgIconProps, since both are different types, typescript is unable to extend both types. Attached playground which explains the issue better
What is the
colorconflict?
type of color in React.HTMLAttributes<HTMLDivElement> is string | undefined where as type of color in ` color?: OverridableStringUnion<
| 'inherit'
| 'action'
| 'disabled'
| 'primary'
| 'secondary'
| 'error'
| 'info'
| 'success'
| 'warning',
SvgIconPropsColorOverrides
;
due to this conflict i've omittedcolor` type
Now that i think about this, since color prop passed to StepIcon gets passed to SvgIcon i think we should omit color from React.HTMLAttributes<HTMLDivElement> not from SvgIconOwnProps. what do you think? If we make color type more strict, would it be breaking change for users who didn't typed properply?
There was a problem hiding this comment.
Reason i went for SvgIconOwnProps instead of SvgIconProps is due to conflicting event handler types.
I see. And is React.HTMLAttributes<HTMLDivElement> used correctly here? Shouldn't it be React.HTMLAttributes<SVGSVGElement>? The root is an SVG, right?
type of color in React.HTMLAttributes is string | undefined
Same question that the one above. Did string work? Or do only the SvgIconOwnProps.color values work?
DiegoAndai
left a comment
There was a problem hiding this comment.
Thanks for working on this @sai6855! a couple of comments:
| export interface StepIconProps | ||
| extends StandardProps<React.HTMLAttributes<HTMLDivElement>, 'children'> { | ||
| extends StandardProps<React.HTMLAttributes<HTMLDivElement>, 'children'>, | ||
| Omit<SvgIconOwnProps, 'color' | 'children'> { |
There was a problem hiding this comment.
I think we should use SvgIconProps instead of SvgIconOwnProps, or is there a reason to use the later?
What is the color conflict?
There was a problem hiding this comment.
Hey @sai6855! Thanks for implementing the feedback.
Initially i thought of doing this, but thought it would be breaking change for users if they depend on React.HTMLAttributes
I think you're correct. I didn't consider this. Considering it, your initial approach of using SvgIconOwnProps looks like the correct solution. May I ask you to go back to that solution using SvgIconOwnProps? Let's keep the changes to a minimum to avoid breaking changes.
I'm sorry for making you redo this 😓, my bad.
No issues :) , i've redid changes here 71c19e9 and added comment in this commit 923297e |
|
Thanks @sai6855! |
oliviertassinari
left a comment
There was a problem hiding this comment.
Nice docs improvement 👍
| // TODO v7: extend React.HTMLAttributes<SVGSVGElement> as svg is root component of StepIcon not div | ||
| extends StandardProps<React.HTMLAttributes<HTMLDivElement>, 'color' | 'children'>, |
There was a problem hiding this comment.
Why wait? Can't we fix this now? It's a bug fix, right?
There was a problem hiding this comment.
I agree with it being bug, but I'm expecting there will be considerable amount of users who are rely on wrong types.
So I wasn't sure if we could fix this between major releases.
closes: #44328