-
-
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
[material-ui][Dialog] Add slots and slotProps #44792
Conversation
Netlify deploy previewhttps://deploy-preview-44792--material-ui.netlify.app/ @material-ui/core: parsed: +0.10% , gzip: +0.10% Bundle size reportDetails of bundle changes (Toolpad) |
In Dialog BackDropComponent
PaperComponent
Should i deprecate these or leave as it is similarly to |
@sai6855, I think:
Please test this though, as I haven't. |
…into dialog-slots
@sai6855 Is this PR ready for review? if yes, please switch from "draft" to "ready". |
Migratio guide is pending, I'll add it mark it ready for review |
I'm facing few issues while deprecating PaperComponent, will try to find solution and update |
|
||
export interface DialogProps extends StandardProps<ModalProps, 'children'> { | ||
export interface DialogSlots { |
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.
Missing root
, backdrop
, container
, and paper
slots.
…into dialog-slots
@siriwatknp PR is ready for review now, I haven't deprecated check the demo here: https://stackblitz.com/edit/react-mlv38cpv?file=Demo.tsx, |
@@ -1,12 +1,96 @@ | |||
import * as React from 'react'; | |||
import { SxProps, Breakpoint } from '@mui/system'; | |||
import { InternalStandardProps as StandardProps, Theme } from '..'; | |||
import { BackdropProps, InternalStandardProps as StandardProps, Theme } from '..'; |
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.
import { BackdropProps, InternalStandardProps as StandardProps, Theme } from '..'; | |
import { InternalStandardProps as StandardProps, Theme } from '..'; | |
import { BackdropProps } from '../Backdrop'; |
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.
fixed here 4c61efb
transition?: React.JSXElementConstructor< | ||
TransitionProps & { children?: React.ReactElement<any, any> } | ||
>; |
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.
transition?: React.JSXElementConstructor< | |
TransitionProps & { children?: React.ReactElement<any, any> } | |
>; | |
transition?: React.ElementType |
Is there a blocker using React.ElementType
? The reason to use it is to widening the type so user can pass their custom component.
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.
not really, i used previous type. updated here 6ae70b7
* By default, the avaible props are based on a div element. | ||
*/ | ||
container: SlotProps< | ||
React.ElementType<React.HTMLAttributes<HTMLDivElement>>, |
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.
React.ElementType<React.HTMLAttributes<HTMLDivElement>>, | |
'div', |
I found that this is simpler.
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.
fixed 79e8ea6
@@ -125,3 +212,5 @@ export interface DialogProps extends StandardProps<ModalProps, 'children'> { | |||
* - inherits [Modal API](https://mui.com/material-ui/api/modal/) | |||
*/ | |||
export default function Dialog(props: DialogProps): React.JSX.Element; | |||
|
|||
export interface DialogOwnerState extends DialogProps {} |
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.
export interface DialogOwnerState extends DialogProps {} | |
export interface DialogOwnerState extends Omit<DialogProps, 'slots' | 'slotProps'> {} |
to prevent recursive types.
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.
fixed 12c6f4f
slotProps: backwardCompatibleSlotProps, | ||
}; | ||
|
||
const [RootSlot, rootSlotProps] = useSlot('root', { |
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.
const [RootSlot, rootSlotProps] = useSlot('root', { | |
const [RootSlot, rootSlotProps] = useSlot('root', { | |
shouldForwardComponentProp: true, |
If the elementType is a styled component of another styled component, this prop should be set to true, so that slotProps.root.component
does not replace the inner styled component.
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.
got it added here 51ca92b.
If the elementType is a styled component of another styled component, this prop should be set to true, so that slotProps.root.component does not replace the inner styled component.
Does that mean, shouldForwardComponent:true
is missing here? given TableSortLabelRoot
is of another styled component (ButtonBase)
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.
Yes, that's right.
const [BackdropSlot, { as: backdropComponent, ...backdropSlotProps }] = useSlot('backdrop', { | ||
elementType: DialogBackdrop, | ||
externalForwardedProps, | ||
ownerState, | ||
}); |
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.
const [BackdropSlot, { as: backdropComponent, ...backdropSlotProps }] = useSlot('backdrop', { | |
elementType: DialogBackdrop, | |
externalForwardedProps, | |
ownerState, | |
}); | |
const [BackdropSlot, backdropSlotProps] = useSlot('backdrop', { | |
shouldForwardComponentProp: true, | |
elementType: DialogBackdrop, | |
externalForwardedProps, | |
ownerState, | |
}); |
With shouldForwardComponentProp: true
, the backdropSlotProps
will not produce as
prop.
Part of #41281