Skip to content

[materia-ui][StepIcon] Add SvgIconOwnProps type to StepIcon props#44337

Merged
DiegoAndai merged 13 commits intomui:masterfrom
sai6855:step-icon
Nov 14, 2024
Merged

[materia-ui][StepIcon] Add SvgIconOwnProps type to StepIcon props#44337
DiegoAndai merged 13 commits intomui:masterfrom
sai6855:step-icon

Conversation

@sai6855
Copy link
Copy Markdown
Member

@sai6855 sai6855 commented Nov 7, 2024

closes: #44328

@sai6855 sai6855 marked this pull request as draft November 7, 2024 05:15
@mui-bot
Copy link
Copy Markdown

mui-bot commented Nov 7, 2024

Netlify deploy preview

https://deploy-preview-44337--material-ui.netlify.app/

Bundle size report

No bundle size changes (Toolpad)
No bundle size changes

Generated by 🚫 dangerJS against cc53e00

@sai6855 sai6855 added type: bug It doesn't behave as expected. scope: stepper Changes related to the stepper. typescript package: material-ui labels Nov 7, 2024
describeConformance(<StepIcon icon={1} />, () => ({
classes,
inheritComponent: 'svg',
inheritComponent: SvgIcon,
Copy link
Copy Markdown
Member Author

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

export interface StepIconProps
extends StandardProps<React.HTMLAttributes<HTMLDivElement>, 'children'> {
extends StandardProps<React.HTMLAttributes<HTMLDivElement>, 'children'>,
Omit<SvgIconOwnProps, 'color' | 'children'> {
Copy link
Copy Markdown
Member Author

@sai6855 sai6855 Nov 7, 2024

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

<StepIconRoot
as={Warning}
className={className}
ref={ref}
ownerState={ownerState}
{...other}
/>

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Member Author

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

https://www.typescriptlang.org/play/?#code/JYOwLgpgTgZghgYwgAgMqQA4EkEHsQAKUuGAzshAB6QgAm5AShImAHQASAKgLIAyAgmDBRgAIwCukUgB4ufACLAAbgFEANhAC2EcAD4ANMiYsOPAUJESp01ADUA4nfvqtOsLuQBvAFDeAvkA

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 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?

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be React.HTMLAttributes?

Initially i thought of doing this, but thought it would be breaking change for users if they depend on React.HTMLAttributes<HTMLDivElement>

Anyway, i updated types here 463efe7 11a1807

@sai6855 sai6855 marked this pull request as ready for review November 7, 2024 05:52
Comment thread packages/mui-material/src/StepIcon/StepIcon.spex.tsx
@sai6855 sai6855 requested a review from DiegoAndai November 7, 2024 05:53
Copy link
Copy Markdown
Member

@DiegoAndai DiegoAndai left a 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:

export interface StepIconProps
extends StandardProps<React.HTMLAttributes<HTMLDivElement>, 'children'> {
extends StandardProps<React.HTMLAttributes<HTMLDivElement>, 'children'>,
Omit<SvgIconOwnProps, 'color' | 'children'> {
Copy link
Copy Markdown
Member

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?

Comment thread packages/mui-material/src/StepIcon/StepIcon.spex.tsx
Comment thread packages/mui-material/src/StepIcon/StepIcon.d.ts Outdated
Copy link
Copy Markdown
Member

@DiegoAndai DiegoAndai left a 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.

@sai6855
Copy link
Copy Markdown
Member Author

sai6855 commented Nov 14, 2024

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

@DiegoAndai
Copy link
Copy Markdown
Member

Thanks @sai6855!

@DiegoAndai DiegoAndai merged commit 3251c3a into mui:master Nov 14, 2024
Copy link
Copy Markdown
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice docs improvement 👍

Comment on lines +8 to +9
// TODO v7: extend React.HTMLAttributes<SVGSVGElement> as svg is root component of StepIcon not div
extends StandardProps<React.HTMLAttributes<HTMLDivElement>, 'color' | 'children'>,
Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: stepper Changes related to the stepper. type: bug It doesn't behave as expected. typescript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[material-ui][StepIcon] titleAccess not included in props type

4 participants