-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[materia-ui][StepIcon] Add SvgIconOwnProps type to StepIcon props #44337
Conversation
Netlify deploy previewhttps://deploy-preview-44337--material-ui.netlify.app/ Bundle size report |
import describeConformance from '../../test/describeConformance'; | ||
|
||
describe('<StepIcon />', () => { | ||
const { render } = createRenderer(); | ||
|
||
describeConformance(<StepIcon icon={1} />, () => ({ | ||
classes, | ||
inheritComponent: 'svg', | ||
inheritComponent: SvgIcon, |
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.
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
import { Theme } from '../styles'; | ||
import { StepIconClasses } from './stepIconClasses'; | ||
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
<StepIconRoot | |
as={Warning} | |
className={className} | |
ref={ref} | |
ownerState={ownerState} | |
{...other} | |
/> |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
color
conflict?
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 omitted
color` 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
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.
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 working on this @sai6855! a couple of comments:
import { Theme } from '../styles'; | ||
import { StepIconClasses } from './stepIconClasses'; | ||
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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! |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why wait? Can't we fix this now? It's a bug fix, right?
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.
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