-
-
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][Checkbox] Add slots and slotProps #44974
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ import memoTheme from '../utils/memoTheme'; | |
import createSimplePaletteValueFilter from '../utils/createSimplePaletteValueFilter'; | ||
|
||
import { useDefaultProps } from '../DefaultPropsProvider'; | ||
import useSlot from '../utils/useSlot'; | ||
|
||
const useUtilityClasses = (ownerState) => { | ||
const { classes, indeterminate, color, size } = ownerState; | ||
|
@@ -123,6 +124,8 @@ const Checkbox = React.forwardRef(function Checkbox(inProps, ref) { | |
size = 'medium', | ||
disableRipple = false, | ||
className, | ||
slots = {}, | ||
slotProps = {}, | ||
...other | ||
} = props; | ||
|
||
|
@@ -139,8 +142,22 @@ const Checkbox = React.forwardRef(function Checkbox(inProps, ref) { | |
|
||
const classes = useUtilityClasses(ownerState); | ||
|
||
const externalForwardedProps = { | ||
...other, | ||
slots, | ||
slotProps, | ||
}; | ||
|
||
const [RootSlot, rootProps] = useSlot('root', { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the runtime cost of this for the component? |
||
elementType: CheckboxRoot, | ||
ref, | ||
className: clsx(classes.root, className), | ||
ownerState, | ||
externalForwardedProps, | ||
}); | ||
|
||
return ( | ||
<CheckboxRoot | ||
<RootSlot | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it make sense to deprecate I mean deprecate the |
||
type="checkbox" | ||
inputProps={{ | ||
'data-indeterminate': indeterminate, | ||
|
@@ -152,11 +169,8 @@ const Checkbox = React.forwardRef(function Checkbox(inProps, ref) { | |
checkedIcon={React.cloneElement(indeterminateIcon, { | ||
fontSize: indeterminateIcon.props.fontSize ?? size, | ||
})} | ||
ownerState={ownerState} | ||
ref={ref} | ||
className={clsx(classes.root, className)} | ||
disableRipple={disableRipple} | ||
{...other} | ||
{...rootProps} | ||
classes={classes} | ||
/> | ||
); | ||
|
@@ -259,6 +273,20 @@ Checkbox.propTypes /* remove-proptypes */ = { | |
PropTypes.oneOf(['medium', 'small']), | ||
PropTypes.string, | ||
]), | ||
/** | ||
* The props used for each slot inside. | ||
* @default {} | ||
*/ | ||
slotProps: PropTypes.shape({ | ||
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), | ||
}), | ||
/** | ||
* The components used for each slot inside. | ||
* @default {} | ||
*/ | ||
slots: PropTypes.shape({ | ||
root: PropTypes.elementType, | ||
}), | ||
/** | ||
* The system prop that allows defining system overrides as well as additional CSS styles. | ||
*/ | ||
|
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.
The checkbox should have
slots.input
too. If you track back to SwitchBase, it hasSwitchBaseRoot
andSwitchBaseInput
.User should be able to do this:
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.
@siriwatknp I'm bit confused on how to handle
slots.input
here, sinceinput
slot is not passed toSwitchBase
fromCheckbox
but onlyinputProps
are passed.