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][Checkbox] Add slots and slotProps #44974

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sai6855
Copy link
Contributor

@sai6855 sai6855 commented Jan 8, 2025

part of #41281

This PR adds missing root slot

@sai6855 sai6855 changed the title [material-ui][SCheckbox] Add slots and slotProps [material-ui][Checkbox] Add slots and slotProps Jan 8, 2025
@sai6855 sai6855 added component: checkbox This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material labels Jan 8, 2025
@mui-bot
Copy link

mui-bot commented Jan 8, 2025

Netlify deploy preview

https://deploy-preview-44974--material-ui.netlify.app/

Checkbox: parsed: +1.98% , gzip: +1.85%

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against 4a3ca79

@sai6855 sai6855 requested a review from siriwatknp January 8, 2025 11:10
Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not following, what's the use case to have?

  slotProps: PropTypes.shape({
    root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
  }),

slotProps,
};

const [RootSlot, rootProps] = useSlot('root', {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the runtime cost of this for the component?

@sai6855
Copy link
Contributor Author

sai6855 commented Jan 9, 2025

I'm not following, what's the use case to have?

  slotProps: PropTypes.shape({
    root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
  }),

I'm not entirely sure about adding slots and SlotProps if a component only has a root slot; maybe it's just for consistency.

@siriwatknp is my understanding correct?

Comment on lines +19 to +25
export interface CheckboxSlots {
/**
* The component that renders the root slot.
* @default SwitchBase
*/
root: React.ElementType;
}
Copy link
Member

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 has SwitchBaseRoot and SwitchBaseInput.

User should be able to do this:

<Checkbox slotProps={{
  root: { className: '...' },
  input: { className: '...' },
}} />

Copy link
Contributor Author

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, since input slot is not passed to SwitchBase from Checkbox but only inputProps are passed.

return (
<CheckboxRoot
<RootSlot
Copy link
Member

@siriwatknp siriwatknp Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to deprecate inputProps in favor of slotProps.input? cc @DiegoAndai

I mean deprecate the inputProps of Checkbox, but still passing slotProps.input to <RootSlot inputProps={slotPropss.input} /> because SwitchBase is an internal component, no need to update it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: checkbox This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants