-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
MUI: The value
provided to the Tabs component is invalid....
#32749
Comments
Note that on the example that you linked the |
So below is my exact code. I assume the enum is converting to being a number but I'm still getting the above error
|
this is a bug |
Is this a bug with my code or a MUI? If it's MUI is there somewhere better to follow this? |
any updates? |
I encountered this bug 4 months ago and now it's happening again even after the latest updates. |
Any solution? |
you need to: <Tabs ---> value={false} <--- /> |
Yes Sir! You are right. In fact, for me the problem came from const [value, setValue] = useState(0) If you do so the error appears. Guess TabPanel is not already created or recognized on first render but ... const [value, setValue] = useState(false) works like a charm as 0 should point to a tabpanel id but false means no id value at all. Thank you very much @skrimusss |
I encountered this on page load when a suspended component was rendering next to the tabs. Putting |
For some reason I am getting
|
I have tried everything, approximately 46 hours trying to figure out a workaround for this error. But no-way. It's obviously a bug. And it has to be fixed. I was able to complete my entire project peacefully, the only part left for me is this error. But it's okay for now, the project still can survive with that. |
Same as me. |
Same as me |
Same here. I have the exact same problem as @samislam |
same here |
1 similar comment
same here |
+1 |
Same as me...... |
+1 |
same thing here |
+1 |
@samislam I realize that you are using labs components. I am not. Maybe this is something to check. |
+1 |
1 similar comment
+1 |
i previously added display:none in sm device then i removed this , now its working properly |
+1 |
Please reopen the issue its still a problem. |
+1 |
2 similar comments
+1 |
+1 |
本人已收到您的邮件,辛苦了!如有重要事情,看到后,将尽快给你回复。。。
|
@mnajdova Please re-open this issue |
+1 |
1 similar comment
+1 |
Similar circumstance although in my case the suspended element was a child of the first visible tab panel. |
+1 |
const [value, setValue] = useState(false); useEffect(() => { |
I can re-open it if someone shares a sandbox with a reproduction. I've responded what is the problem with the initially created sandbox. Adding a "+1" and "same here" is not helpful without a reproduction that we can look into. |
Hey friends, The test shows no errors at all, I have tried to use I wasn't able to reproduce the problem, so everyone, please fork this project, and try to cause the error message to show up: Sandbox (Stack Blitz): Click me |
I think the issue here is that MUI checks if the immediate children have a Whether or not this is a bug, I'm not sure. But it does seem like this use case should be supported. |
Hi, I think I have a reproduction here, at least for the edge-case that I'm running into. It seems to happen when the component that is rendering the Here's my sample repo that shows the error: https://github.com/rossipedia/mui-tabs-invalid-value-repro 1: I think this is an optimization on React's part for Suspended trees, since I would've assumed that the 2: Relevant MUI source: material-ui/packages/mui-material/src/Tabs/Tabs.js Lines 361 to 371 in 2093d62
|
I have faced this issue in my React app with Ionic. The issue appears because initially selected tab button has It turned out that in my case MUI Tabs were trying to render before Ionic page loaded completely which made selected tab button having This MUI tabs code was triggering this error: material-ui/packages/mui-material/src/Tabs/Tabs.js Lines 357 to 374 in 2093d62
And what was failing for me is width / height zero check. I have found 2 workarounds to fix this issue in my case: 1) Use
I did not particularly liked this solution because I don't like using setTimeouts to fix issues like that since it does not seem too reliable 2) Use Ionic's
I preferred this workaround as it seems to be more reliable as it reacts only when selected tab button is fully rendered. I still have a question to devs of MUI Tabs - why do you need this width / height check here? material-ui/packages/mui-material/src/Tabs/Tabs.js Lines 357 to 374 in 2093d62
It is not obvious it is a requirement, as well as it seems to create problems for any kind of lazy loading or hidden elements and etc. which I don't think it was supposed to. @mnajdova , as you are the one who closed the issue, could you clarify why should an error be shown when selected tab button has zero width / height? |
@mracette the @rossipedia @Alena-Levina can you please create separate issues? Although the error shown is the same, it seems to be related to different topics. @Alena-Levina it would help if you could share sandbox/repository with minimal reproduction on the new issue. From what I can see, it may be related to #33606 (the whole tabs are not visible, so the error shouldn't be shown at all). @rossipedia @Alena-Levina would be great if you can check if #34026 (review) fixes the issues you have. You can use the build packages from the PR: |
+1 |
I have been wrestling with this problem for about a month now in a project that was started a few months ago with MUI v5.10.9 and I have tried every trick that I could scrape off the Internet (not many though), but nothing worked for me until I upgraded to v5.11.4 just moments ago and that ugly console error is no more there! 🤩 Hurray! Probably they have fixed it in recent updates. Sheesh! It has been driving me nuts for the last month. Tons of thanks to the MUI guys 👍 for fixing this and allowing my subconscious to have some peace finally 😮💨 So, folks, just upgrade your MUI dependency version. |
I have handled it. import { useLocation } from "react-router-dom";
export const useRouteMatch = (patterns: string[]) => {
const { pathname } = useLocation();
if (pathname === "/") return "/";
const path = "/" + pathname.split("/")[1];
if (patterns.includes(path)) return path;
return false;
}; export const Navigation = () => {
const { auth } = useAuth();
const availableLinks = links.filter(({ allowedRoles }) =>
isRoleAllowed(allowedRoles, auth?.role)
);
const currentTab = useRouteMatch(availableLinks.map(({ url }) => url));
return (
<nav className={classes.Navigation}>
<Tabs
value={currentTab}
variant="scrollable"
scrollButtons="auto"
allowScrollButtonsMobile
selectionFollowsFocus
className={classes.tabs}
>
{availableLinks.map(({ url, name, icon, allowedRoles }) => (
<Tab
value={url}
key={name}
label={name}
icon={icon}
iconPosition="start"
component={Link}
to={url}
/>
))}
</Tabs>
</nav>
);
}; |
<Tabs |
Still have this issue, and if I add <Tabs value={value || false} i can't see the selected tab on the tabs menu. |
I had the same error when displayed tabs only on mobile. I just exported import { useMediaQuery } from '@mui/material'
// ...
const isMobile = useMediaQuery('(max-width: 768px)')
if (!isMobile) return null
return (
<TabContext value={value}>
// ...
</TabContext>
) I don't think this is a good solution, but it helped me so far |
How and why is this marked as "Closed" the problem still exist |
In my case I was indeed using style={{ display: 'none' }} so I replaced it with style={{ visibility: 'hidden' }} |
I have same problem, but i use TabList - it doesn't have value prop at all. |
I have added |
I was trying to make a wrapper for MUI's components. It turns out you must use the prop name For example, this will not work: const MyTab = ({ foo }) => <Tab value={foo} />
<Tabs>
<MyTab foo={...} />
<MyTab foo={...} />
<MyTab foo={...} />
</Tabs> I believe that when |
Duplicates
Latest version
Current behavior 😯
When using the tabs component I get,
Tabs.js:366 MUI: The
value
provided to the Tabs component is invalid.The Tab with this
value
("0") is not part of the document layout.Make sure the tab item is present in the document or that it's not
display: none
.This occurs both in my own code, and when I copy examples from https://mui.com/material-ui/react-tabs/#experimental-api
There is some stack overflow questions but no solutions
https://stackoverflow.com/questions/72085892/mui-the-value-provided-to-the-tabs-component-is-invalid-the-tab-with-this-v
https://stackoverflow.com/questions/71613867/mui-nested-tabs-error-the-value-provided-to-the-tabs-component-is-invalid
Expected behavior 🤔
No response
Steps to reproduce 🕹
Steps:
Context 🔦
No response
Your environment 🌎
`npx @mui/envinfo`
The text was updated successfully, but these errors were encountered: