Skip to content
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

Merged
merged 13 commits into from
Nov 14, 2024

Conversation

sai6855
Copy link
Contributor

@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

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 bug 🐛 Something doesn't work component: stepper This is the name of the generic UI component, not the React module! typescript package: material-ui Specific to @mui/material labels Nov 7, 2024
import describeConformance from '../../test/describeConformance';

describe('<StepIcon />', () => {
const { render } = createRenderer();

describeConformance(<StepIcon icon={1} />, () => ({
classes,
inheritComponent: 'svg',
inheritComponent: SvgIcon,
Copy link
Contributor 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

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'> {
Copy link
Contributor 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
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
Contributor 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
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
Contributor 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
Copy link
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:

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'> {
Copy link
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?

packages/mui-material/src/StepIcon/StepIcon.spex.tsx Outdated Show resolved Hide resolved
Copy link
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
Contributor 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
Member

Thanks @sai6855!

@DiegoAndai DiegoAndai merged commit 3251c3a into mui:master Nov 14, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: stepper This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material typescript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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