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

[Button] Remove label span #26666

Merged
merged 10 commits into from
Jun 11, 2021
Merged

Conversation

siriwatknp
Copy link
Member

@siriwatknp siriwatknp commented Jun 9, 2021

BREAKING CHANGES

The span element that wraps children has been removed. label classKey is also removed.


Preview
https://deploy-preview-26666--material-ui.netlify.app/components/buttons/

Changes Summary

  • remove label classes and element from Button and LoadingButton
  • fix LoadingButton position: center styling because it rely on label before.

History

button > span > children exists as a workaround for flex container bug on button BUT not anymore, so this PR remove the span.

  • ✅ Chrome 83+ (latest 90)
  • ✅ Safari 11+ (latest 14)
  • ✅ Edge
  • ✅ Firefox 63 (latest 89)

https://github.com/philipwalton/flexbugs#flexbug-9

@siriwatknp siriwatknp added new feature New feature or request breaking change component: button This is the name of the generic UI component, not the React module! labels Jun 9, 2021
Comment on lines 56 to 58
transition: theme.transitions.create(['background-color', 'box-shadow', 'border-color'], {
duration: theme.transitions.duration.short,
}),
Copy link
Member Author

Choose a reason for hiding this comment

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

add transition (exclude color) due to this glitch.

loading-button-transition.mp4

Copy link
Member

Choose a reason for hiding this comment

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

It still looks off:

looks off

The non centered cases are worse.

@mui-pr-bot
Copy link

mui-pr-bot commented Jun 9, 2021

Details of bundle changes (experimental)

Generated by 🚫 dangerJS against 6aabb2a

Comment on lines 65 to 70
...(styleProps.loadingPosition === 'center' && {
[`&.${buttonClasses.disabled}`]: {
color: 'transparent',
},
}),
}));
Copy link
Member Author

Choose a reason for hiding this comment

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

added to fix this.

image

@@ -88,6 +89,7 @@ const LoadingButtonLoadingIndicator = styled('div', {
...(styleProps.loadingPosition === 'center' && {
left: '50%',
transform: 'translate(-50%)',
color: theme.palette.action.disabled,
Copy link
Member Author

@siriwatknp siriwatknp Jun 9, 2021

Choose a reason for hiding this comment

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

because of the above fix. color: transparent makes indicator disappear, so need to force the color same is disabled state in Button

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 could not spot any issues, we should just fix the test before merging

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.

Looks good, I could not test only Safari.

@oliviertassinari
Copy link
Member

I believe that merging these changes means closing #26412. AFAIK, the solution was depending on the span, cc @eps1lon to confirm or not.

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.

Regarding the transition when centered, the only solution I could find is adding the span back for the loading label. So it can also support more complex children


I could find one change to improve the transition for the start and end icons that works both on this PR and HEAD:

diff --git a/packages/material-ui-lab/src/LoadingButton/LoadingButton.js b/packages/material-ui-lab/src/LoadingButton/LoadingButton.js
index 03195089be..c4cc467b73 100644
--- a/packages/material-ui-lab/src/LoadingButton/LoadingButton.js
+++ b/packages/material-ui-lab/src/LoadingButton/LoadingButton.js
@@ -56,11 +56,11 @@ const LoadingButtonRoot = styled(Button, {
   transition: theme.transitions.create(['background-color', 'box-shadow', 'border-color'], {
     duration: theme.transitions.duration.short,
   }),
-  [`& .${loadingButtonClasses.startIconLoadingStart}`]: {
-    visibility: 'hidden',
-  },
-  [`& .${loadingButtonClasses.endIconLoadingEnd}`]: {
-    visibility: 'hidden',
+  [`& .${loadingButtonClasses.startIconLoadingStart}, & .${loadingButtonClasses.endIconLoadingEnd}`]: {
+    transition: theme.transitions.create(['opacity'], {
+      duration: theme.transitions.duration.short,
+    }),
+    opacity: 0,
   },
   ...(styleProps.loadingPosition === 'center' && {
     [`&.${buttonClasses.disabled}`]: {

What it does on HEAD:

smooth

Comment on lines 56 to 58
transition: theme.transitions.create(['background-color', 'box-shadow', 'border-color'], {
duration: theme.transitions.duration.short,
}),
Copy link
Member

Choose a reason for hiding this comment

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

It still looks off:

looks off

The non centered cases are worse.

@siriwatknp
Copy link
Member Author

Regarding the transition when centered, the only solution I could find is adding the span back for the loading label. So it can also support more complex children

In my opinion, adding the span back is a no go as we learned from other components that the structure should not surprise people.

Screen.Recording.2564-06-10.at.09.49.28.mov

Here, I think it is better. remove color from transition only for loadingPosition: 'center'. This way it does not affect other position.

@oliviertassinari
Copy link
Member

oliviertassinari commented Jun 10, 2021

There are two issues with the current animation: 1. the icons disappear instantly (which is quite visible), 2. the border-radius color isn't in sync with the text color. It doesn't feel as smooth as on #26666 (review). The last one can be fixed if we add a <span>.

Another issue of not using a span: this do no longer work:

      <LoadingButton
        onClick={handleClick}
        loading={loading}
        loadingIndicator="Loading..."
        variant="outlined"
      >
        Notifications <Badge>9</Badge>
      </LoadingButton>

Capture d’écran 2021-06-10 à 23 32 47

Capture d’écran 2021-06-10 à 23 35 24

is a no go as we learned from other components that the structure should not surprise people

Agree with this downside. It's definitely a tradeoff.

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 have added a new commit. Happy to moving forward as is. At least, we are conscious about the <span> tradeoff:

Cons:

  • Surprising DOM structure for new users

Pros:

  • Support any children. I think that we can expect new GitHub issues for it once this gets released. We will see if there is enough 👍 to force us to reconsider & revert.
  • A slightly better transition
  • Same DOM structure for previous users

@siriwatknp siriwatknp merged commit edfaadc into mui:next Jun 11, 2021
@siriwatknp siriwatknp deleted the fix/button-remove-label branch June 11, 2021 03:41
@oliviertassinari
Copy link
Member

@siriwatknp I have updated #20012 to check [ ] and link this PR. If you could do it for the other efforts, it will be 👌.

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

Successfully merging this pull request may close these issues.

4 participants