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][Stack] Not accepting a React Fragment when using it with a divider #39160

Open
2 tasks done
juanialt opened this issue Sep 25, 2023 · 3 comments
Open
2 tasks done
Assignees
Labels
component: Stack The React component. package: material-ui Specific to @mui/material status: expected behavior Does not imply the behavior is intended. Just that we know about it and can't work around it waiting for 👍 Waiting for upvotes

Comments

@juanialt
Copy link

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Steps to reproduce 🕹

Link to live example:

Steps:

  1. Use the Stack component
  2. Wrap the children elements inside a React Fragment. (in my particular scenario I am sending this as a prop that is why I send it wrapped in a fragment)
  3. Add a prop to the Stack component to add "dividers" (divider={<div>xxx</div>})
  4. The component generates the spacing between each element but it doesn't add the dividers

Sandbox example:
https://codesandbox.io/s/stack-divider-fragment-bug-lnypq9

Current behavior 😯

There is no divider between each children element.

<Stack>
  <div>one</div>
  // space
  <div>two</div>
  // space
  <div>three</div>
</Stack>

Expected behavior 🤔

Should add between each children element a divider

<Stack>
  <div>one</div>
  // space
  <divider/>
  // space
  <div>two</div>
  // space
  <divider/>
  // space
  <div>three</div>
</Stack>

Context 🔦

I created an extended version of the Stack component. It's almost the same but with some additions. If you send the children elements as a React Fragment is where you get the bug. I need to accept those because it's a valid JSX code and also because my component accepts the children prop.

Your environment 🌎

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.
@juanialt juanialt added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Sep 25, 2023
@danilo-leal danilo-leal changed the title Stack component does not accept a React Fragment when using the divider [material-ui][Stack] Not accepting a React Fragment when using it with a divider Sep 25, 2023
@danilo-leal danilo-leal added package: material-ui Specific to @mui/material component: Stack The React component. labels Sep 25, 2023
@siriwatknp siriwatknp added status: expected behavior Does not imply the behavior is intended. Just that we know about it and can't work around it and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 2, 2023
@siriwatknp
Copy link
Member

I doubt if we should support React.Fragment as a child. cc @DiegoAndai

If we want to, the joinChildren has to be recursive to check if the type is Symbol(react.fragment).

@jaydenseric
Copy link
Contributor

See #38533 .

@DiegoAndai
Copy link
Member

I would agree that this is expected with the current implementation.

Supporting a Fragment as a child would be an enhancement or new feature, so we should either wait for upvotes or someone to volunteer to work on it. I'm not sure if we can make it without breaking changes.

As @jaydenseric pointed out, this issue is closely related to #38533. There's a proposal on that issue on how this can be solved.

@DiegoAndai DiegoAndai added the waiting for 👍 Waiting for upvotes label Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: Stack The React component. package: material-ui Specific to @mui/material status: expected behavior Does not imply the behavior is intended. Just that we know about it and can't work around it waiting for 👍 Waiting for upvotes
Projects
None yet
Development

No branches or pull requests

5 participants