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

[SwitchBase] Replace IconButton with ButtonBase #26460

Merged
merged 9 commits into from Jun 1, 2021

Conversation

siriwatknp
Copy link
Member

@siriwatknp siriwatknp commented May 26, 2021

closes #21503, #23945

the changes affect these components

  • Switch
  • Checkbox
  • Radio

The final UI looks the same but I consider this as breaking change because of html change.

Before

  • Switch => SwitchBase => IconButton => ButtonBase
  • Checkbox => SwitchBase => IconButton => ButtonBase
  • Radio => SwitchBase => IconButton => ButtonBase

SwitchBase is internal component, can not be theme.

<IconButton root>
  <IconButton label>
    <SwitchBase>

New

  • Switch => SwitchBase => ButtonBase
  • Checkbox => SwitchBase => ButtonBase
  • Radio => SwitchBase => ButtonBase
<ButtonBase>
  <SwitchBase>

There is no label from IconButton anymore, so 1 level of DOM reduced.

Preview: https://deploy-preview-26460--material-ui.netlify.app/components/switches/

@siriwatknp siriwatknp added breaking change component: checkbox This is the name of the generic UI component, not the React module! component: switch This is the name of the generic UI component, not the React module! component: radio This is the name of the generic UI component, not the React module! labels May 26, 2021
@mui-pr-bot
Copy link

mui-pr-bot commented May 26, 2021

Details of bundle changes (experimental)

@material-ui/core: parsed: +0.12% , gzip: +0.09%

Generated by 🚫 dangerJS against 916f702

@siriwatknp siriwatknp force-pushed the fix/switch-base-inheritance branch from 0ad225a to eb2a388 Compare May 26, 2021 09:04
@oliviertassinari
Copy link
Member

oliviertassinari commented May 26, 2021

Note that #26303 works on a close problem.

@DanielBretzigheimer
Copy link
Contributor

Looks like a more simple solution with less breaking changes compared to #26303. But as you said, the structure has one theoretically unnecessary DOM element (ButtonBase).

One thing that's missing in this PR is the focus indicator.

@siriwatknp
Copy link
Member Author

siriwatknp commented May 27, 2021

Looks like a more simple solution with less breaking changes compared to #26303. But as you said, the structure has one theoretically unnecessary DOM element (ButtonBase).

One thing that's missing in this PR is the focus indicator.

Are you saying that the span.ButtonBase-root should be removed?

image

Should it be

<span class="Switch-root">
  <span class="Switch-input">
  <span class="Switch-thumb">
  <span class="Switch-track">
</span>

@DanielBretzigheimer
Copy link
Contributor

Are you saying that the span.ButtonBase-root should be removed?
When only looking for the DOM structure → Yes, I think this would be the ideal solution.

But as I have seen in the PR #26303 this causes many other problems and redundant code. So my conclusion is to stick with the ButtonBase to improve maintainability and keep the changes as few as possible. All the Issues should be solved with this solution.

But keep in mind, that currently the focus indicator is not working. If you want I will look into it :)

@siriwatknp
Copy link
Member Author

But as I have seen in the PR #26303 this causes many other problems and redundant code. So my conclusion is to stick with the ButtonBase to improve maintainability and keep the changes as few as possible. All the Issues should be solved with this solution.

But keep in mind, that currently the focus indicator is not working. If you want I will look into it :)

Sounds good!

@@ -606,6 +606,10 @@ You can use the [`moved-lab-modules` codemod](https://github.com/mui-org/materia

You can use the [`chip-variant-prop` codemod](https://github.com/mui-org/material-ui/tree/HEAD/packages/material-ui-codemod#chip-variant-prop) for automatic migration.

### Checkbox

- The className does not have `.MuiIconButton-root` and `.MuiIconButton-label` anymore, target `.MuiButtonBase-root` instead.
Copy link
Member

Choose a reason for hiding this comment

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

Would propose showing a diff with the changes.

/* Styles applied to the root element. */
padding: 9,
});
borderRadius: '50%',
Copy link
Member

Choose a reason for hiding this comment

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

It's funny that this was the only thing required from the IconButton :)

Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

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

I would propose going with this set of changes at the start. It's clear improvement, and it is much easier to follow what is changed. We can then on top of these changes try to apply the changes from #26303

@siriwatknp siriwatknp requested a review from mnajdova May 31, 2021 02:40
Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

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

I've pushed minor changes on the migration-v4.md, looks good otherwise.

@siriwatknp siriwatknp merged commit 8fc684f into mui:next Jun 1, 2021
@siriwatknp siriwatknp deleted the fix/switch-base-inheritance branch June 1, 2021 03:26
@oliviertassinari oliviertassinari changed the title [SwitchBase] replace IconButton with ButtonBase [SwitchBase] Replace IconButton with ButtonBase Jun 6, 2021
@oliviertassinari
Copy link
Member

oliviertassinari commented Jun 6, 2021

closes #21503, #23945

@siriwatknp Didn't you mean to close the second issue too? You needed to add the magic keyword for each issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change component: checkbox This is the name of the generic UI component, not the React module! component: radio This is the name of the generic UI component, not the React module! component: switch This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't override IconButton styles in theme without affecting Checkbox and Switch
5 participants