You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you use the asChild prop and pass your child to the <NavigationMenuTrigger /> component I am receiving the Next.js: Error: React.Children.only expected to receive a single React element child error even though I am only passing one child, for example, the following triggers the error (as you can see there is only one child):
I have checked the source of what is added when I run npx shadcn@latest navigation-menu and I have located the issue to be the fact that the current form of the element doesn't take take the asChild prop into account when rendering children, as you can see here:
Describe the bug
When you use the
asChild
prop and pass your child to the<NavigationMenuTrigger />
component I am receiving theNext.js: Error: React.Children.only expected to receive a single React element child
error even though I am only passing one child, for example, the following triggers the error (as you can see there is only one child):I have checked the source of what is added when I run
npx shadcn@latest navigation-menu
and I have located the issue to be the fact that the current form of the element doesn't take take theasChild
prop into account when rendering children, as you can see here:I have fixed this by conditionally rendering the chevron icon as follows:
Affected component/components
NavigationMenuTrigger
How to reproduce
<NavigationMenuItem />
component<NavigationMenuTrigger asChild>
component<NavigationMenuTrigger asChild>
component (as above)Codesandbox/StackBlitz link
No response
Logs
No response
System Info
Don't think this is relevant as the issue is pretty standard, I have a fix and will make a PR
Before submitting
The text was updated successfully, but these errors were encountered: