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

[material-ui][SpeedDial] Add missing root slot #45541

Merged
merged 3 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions docs/pages/material-ui/api/speed-dial.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@
"open": { "type": { "name": "bool" } },
"openIcon": { "type": { "name": "node" } },
"slotProps": {
"type": { "name": "shape", "description": "{ transition?: func<br>&#124;&nbsp;object }" },
"type": {
"name": "shape",
"description": "{ root?: func<br>&#124;&nbsp;object, transition?: func<br>&#124;&nbsp;object }"
},
"default": "{}"
},
"slots": {
"type": { "name": "shape", "description": "{ transition?: elementType }" },
"type": {
"name": "shape",
"description": "{ root?: elementType, transition?: elementType }"
},
"default": "{}"
},
"sx": {
Expand Down Expand Up @@ -69,6 +75,12 @@
"import { SpeedDial } from '@mui/material';"
],
"slots": [
{
"name": "root",
"description": "The component that renders the root slot.",
"default": "'div'",
"class": "MuiSpeedDial-root"
},
{
"name": "transition",
"description": "The component that renders the transition.\n[Follow this guide](https://mui.com/material-ui/transitions/#transitioncomponent-prop) to learn more about the requirements for this component.",
Expand Down Expand Up @@ -118,12 +130,6 @@
"className": "MuiSpeedDial-fab",
"description": "Styles applied to the Fab component.",
"isGlobal": false
},
{
"key": "root",
"className": "MuiSpeedDial-root",
"description": "Styles applied to the root element.",
"isGlobal": false
}
],
"spread": true,
Expand Down
4 changes: 2 additions & 2 deletions docs/translations/api-docs/speed-dial/speed-dial.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@
"directionUp": {
"description": "Styles applied to the root element if direction=&quot;up&quot;"
},
"fab": { "description": "Styles applied to {{nodeName}}.", "nodeName": "the Fab component" },
"root": { "description": "Styles applied to the root element." }
"fab": { "description": "Styles applied to {{nodeName}}.", "nodeName": "the Fab component" }
},
"slotDescriptions": {
"root": "The component that renders the root slot.",
"transition": "The component that renders the transition. <a href=\"https://mui.com/material-ui/transitions/#transitioncomponent-prop\">Follow this guide</a> to learn more about the requirements for this component."
}
}
10 changes: 10 additions & 0 deletions packages/mui-material/src/SpeedDial/SpeedDial.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export type CloseReason = 'toggle' | 'blur' | 'mouseLeave' | 'escapeKeyDown';
export type OpenReason = 'toggle' | 'focus' | 'mouseEnter';

export interface SpeedDialSlots {
/**
* The component that renders the root slot.
* @default 'div'
*/
root: React.ElementType;
/**
* The component that renders the transition.
* [Follow this guide](https://mui.com/material-ui/transitions/#transitioncomponent-prop) to learn more about the requirements for this component.
Expand All @@ -22,6 +27,11 @@ export interface SpeedDialSlots {
export type SpeedDialSlotsAndSlotProps = CreateSlotsAndSlotProps<
SpeedDialSlots,
{
/**
* Props forwarded to the root slot.
* By default, the avaible props are based on div element.
*/
root: SlotComponentProps<'div', React.HTMLAttributes<HTMLDivElement>, SpeedDialOwnerState>;
/**
* Props forwarded to the transition slot.
* By default, the avaible props are based on the [Zoom](https://mui.com/material-ui/api/zoom/#props) component.
Expand Down
54 changes: 41 additions & 13 deletions packages/mui-material/src/SpeedDial/SpeedDial.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,25 +395,51 @@ const SpeedDial = React.forwardRef(function SpeedDial(inProps, ref) {
slotProps: backwardCompatibleSlotProps,
};

const [RootSlot, rootSlotProps] = useSlot('root', {
elementType: SpeedDialRoot,
externalForwardedProps: {
...externalForwardedProps,
...other,
},
ownerState,
ref,
className: clsx(classes.root, className),
additionalProps: {
role: 'presentation',
},
getSlotProps: (handlers) => ({
...handlers,
onKeyDown: (event) => {
handlers.onKeyDown?.(event);
handleKeyDown(event);
},
onBlur: (event) => {
handlers.onBlur?.(event);
handleClose(event);
},
onFocus: (event) => {
handlers.onFocus?.(event);
handleOpen(event);
},
onMouseEnter: (event) => {
handlers.onMouseEnter?.(event);
handleOpen(event);
},
onMouseLeave: (event) => {
handlers.onMouseLeave?.(event);
handleClose(event);
},
}),
});

const [TransitionSlot, transitionProps] = useSlot('transition', {
elementType: Zoom,
externalForwardedProps,
ownerState,
});

return (
<SpeedDialRoot
className={clsx(classes.root, className)}
ref={ref}
role="presentation"
onKeyDown={handleKeyDown}
onBlur={handleClose}
onFocus={handleOpen}
onMouseEnter={handleOpen}
onMouseLeave={handleClose}
ownerState={ownerState}
{...other}
>
<RootSlot {...rootSlotProps}>
<TransitionSlot in={!hidden} timeout={transitionDuration} unmountOnExit {...transitionProps}>
<SpeedDialFab
color="primary"
Expand Down Expand Up @@ -441,7 +467,7 @@ const SpeedDial = React.forwardRef(function SpeedDial(inProps, ref) {
>
{children}
</SpeedDialActions>
</SpeedDialRoot>
</RootSlot>
);
});

Expand Down Expand Up @@ -534,13 +560,15 @@ SpeedDial.propTypes /* remove-proptypes */ = {
* @default {}
*/
slotProps: PropTypes.shape({
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
transition: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
}),
/**
* The components used for each slot inside.
* @default {}
*/
slots: PropTypes.shape({
root: PropTypes.elementType,
transition: PropTypes.elementType,
}),
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/SpeedDial/SpeedDial.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('<SpeedDial />', () => {
refInstanceof: window.HTMLDivElement,
muiName: 'MuiSpeedDial',
testVariantProps: { direction: 'right' },
slots: { transition: { testWithElement: null } },
slots: { transition: { testWithElement: null }, root: { expectedClassName: classes.root } },
skip: [
'componentProp', // react-transition-group issue
'componentsProp',
Expand Down