question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Tabs] Improve TabPanel demos, avoid validateDOMNesting warning

See original GitHub issue
  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

New experimental Tabs API uses <Typography> as the root element for children, preventing nesting anything besides simple text without validateDOMNesting errors. See here: https://github.com/mui-org/material-ui/blob/8c2abebab524a68e97ffb5cf0c2015a915bd2e12/packages/material-ui-lab/src/TabPanel/TabPanel.js#L36

Expected Behavior 🤔

I believe that removing <Typography> completely and rendering children directly would be the best solution with maximum flexibility.

Context 🔦

Will sent a PR if you agree with the solution.

Your Environment 🌎

Tech Version
Material-UI v4.9.13
Material-UI lab v4.0.0-alpha.53
React 16.13.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:14
  • Comments:19 (7 by maintainers)

github_iconTop GitHub Comments

89reactions
VikR0001commented, Oct 20, 2020

Note: the warning appears only because the demo code has:

function TabPanel(props) {
  const { children, value, index, ...other } = props;

  return (
    <div
      role="tabpanel"
      hidden={value !== index}
      id={`simple-tabpanel-${index}`}
      aria-labelledby={`simple-tab-${index}`}
      {...other}
    >
      {value === index && (
        <Box p={3}>
          <Typography>{children}</Typography>
        </Box>
      )}
    </div>
  );
}

Changing it like this takes care of it:

function TabPanel(props) {
    const {children, value, index, classes, ...other} = props;

    return (
        <div
            role="tabpanel"
            hidden={value !== index}
            id={`simple-tabpanel-${index}`}
            aria-labelledby={`simple-tab-${index}`}
            {...other}
        >
            {value === index && (
                <Container>
                    <Box>
                        {children}
                    </Box>
                </Container>
            )}
        </div>
    );
}
7reactions
samfromawaycommented, Jul 23, 2020

Yes that fixed it for me thanks a lot. As you said the demo code should probably be updated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Tabs] Improve TabPanel demos, avoid validateDOMNesting ...
I am on v5 and still needed to tell a Typography explicitly to be a span, otherwise I got this "avoid validateDOMNesting warning"...
Read more >
<div> cannot appear as a descendant of <p> - Stack Overflow
The warning appears only because the demo code has: function TabPanel(props) { const { children, value, index, ...other } = props; ...
Read more >
validatedomnesting(...): <div> cannot appear as a descendant ...
I was applying the change in the wrong place. After adding component={"div"} in the TabPanel function, it started working as well. The working...
Read more >
<div> cannot appear as a descendant of <p>. tab panel” Code ...
Answers related to “validateDOMNesting(...): <div> cannot appear as a descendant of <p>. tab panel”. JSX element implicitly has type 'any' because no ...
Read more >
[Solved]-<div> cannot appear as a descendant of <p>-Reactjs
The warning appears only because the demo code has: function TabPanel(props) { const { children, value, index, ...other } = props; return (...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found