ui: orientation="vertical" seems ignored on navigation menu
According to the Radix UI API documentation and Navigation Menu’s Typescript, there’s an orientation prop that can be used to change the menu to "vertical". However, adding that option doesn’t change anything.
<NavigationMenu orientation="vertical">
<NavigationMenuList>
<NavigationMenuItem>
<NavigationMenuTrigger>Item One</NavigationMenuTrigger>
<NavigationMenuContent>
<NavigationMenuLink>Link</NavigationMenuLink>
</NavigationMenuContent>
</NavigationMenuItem>
<NavigationMenuItem>
<NavigationMenuTrigger>Item One</NavigationMenuTrigger>
<NavigationMenuContent>
<NavigationMenuLink>Link</NavigationMenuLink>
</NavigationMenuContent>
</NavigationMenuItem>
<NavigationMenuItem>
<NavigationMenuTrigger>Item One</NavigationMenuTrigger>
<NavigationMenuContent>
<NavigationMenuLink>Link</NavigationMenuLink>
</NavigationMenuContent>
</NavigationMenuItem>
</NavigationMenuList>
</NavigationMenu>
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 24
- Comments: 15 (2 by maintainers)
If anyone came here looking for a vertical tab component here it is.
adding this class might be the quickest solution
As @heripurnama commented, adding ‘flex-col’ and ‘items-start’ helps. But, a least for me, I also had to include ‘space-x-0’ to remove a 4px margin left of all items except the first one.
Or even create a
For those who want a vertical menu, viewport displayed on the right, the following steps can be done with minimal code editing: For vertical menu:
<NavigationMenuList className="flex-col items-start space-x-0">For viewports:
Example image:
This is great, but bringing this into the core Tabs component as per @arunavo4’s implementation would be great. 👏🏼
Ah, I do see the data attribute change to vertical for the children elements in the HTML. But yes, simply switching to
flex-colwould be good.Based on the entire discution, I ended up with a more flexible solution Update your
navigation-menu.tsxshadcn file as followingNow you can pass the
orientationprop to the<NavigationMenu />component, and the menu will reflect as intended.While you can add your own classes to the TabsList component when calling it, altering the tabs component directly is a more elegant solution, utilizing the [data-orientation] data attribute from Radix UI, e.g.
I think the
orientationprop changes the ‘functional’ orientation, not the ‘visual’ one (i.e. if up/down arrows or left/right arrows will navigate within the component). At least this is what I understand from https://github.com/radix-ui/website/pull/512 (another component, but I guess the idea is the same).