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
2 changes: 1 addition & 1 deletion docs/pages/material-ui/api/step-icon.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"muiName": "MuiStepIcon",
"forwardsRefTo": "SVGSVGElement",
"filename": "/packages/mui-material/src/StepIcon/StepIcon.js",
"inheritance": null,
"inheritance": { "component": "SvgIcon", "pathname": "/material-ui/api/svg-icon/" },
"demos": "<ul><li><a href=\"/material-ui/react-stepper/\">Stepper</a></li></ul>",
"cssComponent": false
}
6 changes: 4 additions & 2 deletions packages/mui-material/src/StepIcon/StepIcon.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as React from 'react';
import { SxProps } from '@mui/system';
import { InternalStandardProps as StandardProps } from '..';
import { InternalStandardProps as StandardProps, SvgIconOwnProps } from '..';
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

/**
* Whether this step is active.
* @default false
Expand Down Expand Up @@ -46,5 +47,6 @@ export type StepIconClasskey = keyof NonNullable<StepIconProps['classes']>;
* API:
*
* - [StepIcon API](https://mui.com/material-ui/api/step-icon/)
* - inherits [SvgIcon API](https://mui.com/material-ui/api/svg-icon/)
*/
export default function StepIcon(props: StepIconProps): React.JSX.Element;
5 changes: 5 additions & 0 deletions packages/mui-material/src/StepIcon/StepIcon.spex.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as React from 'react';
import StepIcon from '@mui/material/StepIcon';

<StepIcon icon={<div>icon</div>} />;
<StepIcon icon={<div>icon</div>} titleAccess="title" />;
DiegoAndai marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 2 additions & 1 deletion packages/mui-material/src/StepIcon/StepIcon.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import * as React from 'react';
import { expect } from 'chai';
import { createRenderer } from '@mui/internal-test-utils';
import StepIcon, { stepIconClasses as classes } from '@mui/material/StepIcon';
import SvgIcon from '@mui/material/SvgIcon';
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

render,
muiName: 'MuiStepIcon',
testVariantProps: { completed: true },
Expand Down