Skip to content

Commit

Permalink
apply suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp committed Jan 10, 2025
1 parent bb813d4 commit 0e09474
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
7 changes: 5 additions & 2 deletions packages/mui-material/src/Alert/Alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ const Alert = React.forwardRef(function Alert(inProps, ref) {
const classes = useUtilityClasses(ownerState);

const externalForwardedProps = {
...other,
slots: {
closeButton: components.CloseButton,
closeIcon: components.CloseIcon,
Expand All @@ -205,9 +204,13 @@ const Alert = React.forwardRef(function Alert(inProps, ref) {

const [RootSlot, rootSlotProps] = useSlot('root', {
ref,
shouldForwardComponentProp: true,
className: clsx(classes.root, className),
elementType: AlertRoot,
externalForwardedProps,
externalForwardedProps: {
...externalForwardedProps,
...other,
},
ownerState,
additionalProps: {
role,
Expand Down
20 changes: 17 additions & 3 deletions packages/mui-material/src/utils/useSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ export default function useSlot<
* e.g. Autocomplete's listbox uses Popper + StyledComponent
*/
internalForwardedProps?: any;
/**
* Set to true if the `elementType` is a styled component of another Material UI component.
*
* For example, the AlertRoot is a styled component of the Paper component.
* This flag is used to forward the `component` and `slotProps.root.component` to the Paper component.
* Otherwise, the `component` prop will be converted to `as` prop which replaces the Paper component (the paper styles are gone).
*/
shouldForwardComponentProp?: boolean;
},
) {
const {
Expand All @@ -90,6 +98,7 @@ export default function useSlot<
ownerState,
externalForwardedProps,
internalForwardedProps,
shouldForwardComponentProp = false,
...useSlotPropsParams
} = parameters;
const {
Expand Down Expand Up @@ -127,9 +136,14 @@ export default function useSlot<
...(name === 'root' && !rootComponent && !slots[name] && internalForwardedProps),
...(name !== 'root' && !slots[name] && internalForwardedProps),
...mergedProps,
...(LeafComponent && {
as: LeafComponent,
}),
...(LeafComponent &&
!shouldForwardComponentProp && {
as: LeafComponent,
}),
...(LeafComponent &&
shouldForwardComponentProp && {
component: LeafComponent,
}),
ref,
},
ownerState,
Expand Down

0 comments on commit 0e09474

Please sign in to comment.