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

[joy-ui][ButtonGroup] Broken styles with custom button elements #39372

Open
2 tasks done
kamavingah opened this issue Oct 10, 2023 · 12 comments
Open
2 tasks done

[joy-ui][ButtonGroup] Broken styles with custom button elements #39372

kamavingah opened this issue Oct 10, 2023 · 12 comments
Assignees
Labels
bug 🐛 Something doesn't work component: button This is the name of the generic UI component, not the React module! design This is about UI or UX design, please involve a designer package: joy-ui Specific to @mui/joy

Comments

@kamavingah
Copy link

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Steps to reproduce 🕹

https://codesandbox.io/s/affectionate-wiles-xzrrzp?file=/Demo.tsx

  1. Create custom Button:
const A = () => {
  return <Button>hi</Button>;
};
  1. Use Button in ButtonGroup
<ButtonGroup>
  <A />
  <A />
</ButtonGroup>

Current behavior 😯

The borders of the ButtonGroup are not rounded.

Expected behavior 🤔

The borders of the ButtonGroup should be rounded.

Context 🔦

No response

Your environment 🌎

@mui/joy 5.0.0-beta.9

@kamavingah kamavingah added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 10, 2023
@vineetjk
Copy link
Contributor

@PhillipWinder you are correct, And one more thing I observed -> if <ButtonGroup> has only one child then the style is correct.

@vineetjk
Copy link
Contributor

if this issue is ready to take, can I work on this?

@danilo-leal danilo-leal changed the title JoyUI: ButtonGroup style not working with custom Button components [joy-ui][ButtonGroup] Broken styles with custom button elements Oct 10, 2023
@danilo-leal danilo-leal added bug 🐛 Something doesn't work component: button This is the name of the generic UI component, not the React module! design This is about UI or UX design, please involve a designer package: joy-ui Specific to @mui/joy and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 10, 2023
@danilo-leal
Copy link
Contributor

@vineetjk go for it! 🙌

@vineetjk
Copy link
Contributor

sure @danilo-leal, I will work on this

@vineetjk

This comment was marked as resolved.

@vineetjk

This comment was marked as resolved.

@vineetjk
Copy link
Contributor

vineetjk commented Oct 12, 2023

I have found the cause for this bug.. 'data-first-child' and 'data-last-child' props are not applied to the buttons which are returned by function or wrapped in <> ...</>

@ZeeshanTamboli
Copy link
Member

ZeeshanTamboli commented Oct 16, 2023

Indeed, it should function with custom buttons. You can make it work by spreading the props to the Button element using this code:

const A = (props) => {
  return <Button {...props}>hi</Button>;
};

You can see an example here: CodeSandbox Link.

I believe the solution is to utilize the React Context API instead of cloneElements for ButtonGroup. This way, the Joy UI Button component can apply the data-* attributes to the DOM even when wrapped with a custom element.

@vineetjk
Copy link
Contributor

Hi @ZeeshanTamboli,
You are correct! it works if we spread props to the Button element. But the same issue is not observed in material library
example : https://codesandbox.io/s/stupefied-montalcini-h8t9tc

@ZeeshanTamboli
Copy link
Member

But the same issue is not observed in material library
example : https://codesandbox.io/s/stupefied-montalcini-h8t9tc

Indeed, that's why I suggested using the Context API; it's what Material UI relies on internally.

@vineetjk
Copy link
Contributor

Yeah I got it, sure I will do the changes..
thanks :)

@aacevski
Copy link
Contributor

I wrote on the newer issue but just to make sure but I'll write here just in case, I have opened a PR proposal, I managed to fix it by just using CSS.

#41456

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: button This is the name of the generic UI component, not the React module! design This is about UI or UX design, please involve a designer package: joy-ui Specific to @mui/joy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants