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

[ButtonGroup] CardActions spacing is not working #29819

Open
2 tasks done
fkorotkov opened this issue Nov 21, 2021 · 5 comments · May be fixed by #31885
Open
2 tasks done

[ButtonGroup] CardActions spacing is not working #29819

fkorotkov opened this issue Nov 21, 2021 · 5 comments · May be fixed by #31885
Assignees
Labels
component: ButtonGroup The React component. v8.x

Comments

@fkorotkov
Copy link

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

Here is a sandbox where I took SplitButton example from the documentation and added it as an action to a card.

Screen Shot 2021-11-21 at 5 08 17 PM

On v5 version spacing is not working between a Button and the ButtonGroup. With v4 everything worked fine.

Expected behavior 🤔

Expect to see a spacing between every action.

Steps to reproduce 🕹

Please check out a sandbox here: https://codesandbox.io/s/magical-robinson-cvkwt?file=/src/Demo.tsx

Context 🔦

I'm trying to upgrade from v4 to v5 and facing some issues.

Your environment 🌎

`npx @mui/envinfo`
❯ npx @mui/envinfo
Need to install the following packages:
  @mui/envinfo
Ok to proceed? (y) y

  System:
    OS: macOS 11.6
  Binaries:
    Node: 17.0.1 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 8.1.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 96.0.4664.55
    Edge: Not Found
    Firefox: 85.0.2
    Safari: 15.0
  npmPackages:
    @emotion/react: ^11.6.0 => 11.6.0 
    @emotion/styled: ^11.6.0 => 11.6.0 
    @mui/core:  5.0.0-alpha.54 
    @mui/icons-material: ^5.1.0 => 5.1.0 
    @mui/lab: ^5.0.0-alpha.54 => 5.0.0-alpha.54 
    @mui/material: ^5.1.0 => 5.1.0 
    @mui/private-theming:  5.1.0 
    @mui/styled-engine:  5.1.0 
    @mui/styles: ^5.1.0 => 5.1.0 
    @mui/system:  5.1.0 
    @mui/types:  7.1.0 
    @mui/utils:  5.1.0 
    @types/react: ^16.8.0 => 16.14.8 
    react: ^16.8.4 => 16.14.0 
    react-dom: ^16.8.4 => 16.14.0 
    typescript: ^3.9.7 => 3.9.10 
@fkorotkov fkorotkov added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Nov 21, 2021
@fkorotkov
Copy link
Author

I guess the regression might be introduced by @vicasas in #24604: 1842ce8#diff-8fd90cfbeeb4f4c26dee82bfb29db2339a9908640b9368edbffa8cf37e4ba745R43

Not sure why :not(:first-child) was changed to :not(:first-of-type). 🤔

@hbjORbj hbjORbj added bug 🐛 Something doesn't work component: ButtonGroup The React component. labels Nov 23, 2021
@hbjORbj hbjORbj changed the title CardActions spacing is not working with a ButtonGroup [ButtonGroup] CardActions spacing is not working Nov 23, 2021
@hbjORbj
Copy link
Member

hbjORbj commented Nov 23, 2021

@fkorotkov Thanks for creating the PR. I am afraid your codesandbox is empty. Would you update it? Thanks.

@hbjORbj hbjORbj removed bug 🐛 Something doesn't work status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Nov 23, 2021
@fkorotkov
Copy link
Author

@hbjORbj my bad! Just recreated it and made sure it got saved. Seems I'm to used to IntelliJ's auto-save so I didn't press Cmd+S. 🤦

@siriwatknp
Copy link
Member

siriwatknp commented Nov 24, 2021

Not sure why :not(:first-child) was changed to :not(:first-of-type)

I think it is changed due to the emotion warning to not use :first-child. The best solution I can see is to use CSS property gap but from caniuse, it is around 89%.

in v6, we will probably fix this with gap.

@isti115
Copy link

isti115 commented Nov 21, 2023

For anyone still using MUI v5 and facing this issue, you can manually override the styling when creating your theme:

createTheme({
  components: {
    MuiCardActions: {
      styleOverrides: {
        root: ({ theme }) => ({
          '& > :not(:first-of-type)': {
            marginLeft: 'unset',
          },

          gap: theme.spacing(1),
        }),
      },
    },
  },
})

Since the support for gap is now above 95%, I would suggest using that, but the same technique can also be applied if you'd like to stick with margins:

createTheme({
  components: {
    MuiCardActions: {
      styleOverrides: {
        root: ({ theme }) => ({
          '& > :not(:first-of-type)': {
            marginLeft: 'unset',
          },

          '& > :not(:first-child)': {
            marginLeft: theme.spacing(1),
          },
        }),
      },
    },
  },
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: ButtonGroup The React component. v8.x
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants