Skip to content

Commit 11448be

Browse files
duyetduyetbot
andauthored
fix(menu): filter out menu items with missing title or href (#543)
* fix(menu): filter out menu items with missing title or href Add defensive rendering to prevent blank menu items from appearing. Filter out any menu items that don't have both a title and href before rendering them in both navigation and dropdown menu components. This prevents runtime issues where menu items might be undefined or have missing properties, which would cause blank cards to appear in the menu grid layout. Co-Authored-By: duyetbot <[email protected]> * fix(menu): reduce menu item padding for better layout Reduce padding to improve menu layout and prevent overflow issues: - Grid container: p-4 → p-2 (16px → 8px) - Menu item cards: p-3 → p-2 (12px → 8px) This provides a more compact layout that better fits the menu content and reduces the likelihood of layout issues causing blank items. Co-Authored-By: duyetbot <[email protected]> --------- Co-authored-by: duyetbot <[email protected]>
1 parent b4b75f8 commit 11448be

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

components/menu/menu-dropdown-style.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function HasChildItems({ item }: { item: MenuItem }) {
8484
</DropdownMenuSubTrigger>
8585
<DropdownMenuPortal>
8686
<DropdownMenuSubContent>
87-
{item.items?.map((childItem) => (
87+
{item.items?.filter((childItem) => childItem.title && childItem.href).map((childItem) => (
8888
<MenuItem key={childItem.href} item={childItem} />
8989
))}
9090
</DropdownMenuSubContent>

components/menu/menu-navigation-style.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ function HasChildItems({ item }: { item: MenuItem }) {
9595
</div>
9696
</NavigationMenuTrigger>
9797
<NavigationMenuContent>
98-
<ul className="grid w-fit min-w-[400px] grid-cols-1 content-center items-stretch gap-2 p-4 md:min-w-[700px] md:grid-cols-2">
99-
{item.items?.map((childItem) => (
98+
<ul className="grid w-fit min-w-[400px] grid-cols-1 content-center items-stretch gap-2 p-2 md:min-w-[700px] md:grid-cols-2">
99+
{item.items?.filter((childItem) => childItem.title && childItem.href).map((childItem) => (
100100
<ListItem
101101
key={childItem.href}
102102
title={
@@ -153,7 +153,7 @@ function ListItem({
153153
>
154154
<div
155155
className={cn(
156-
'block space-y-1 rounded-md p-3 leading-none no-underline outline-hidden transition-colors select-none',
156+
'block space-y-1 rounded-md p-2 leading-none no-underline outline-hidden transition-colors select-none',
157157
'hover:bg-accent hover:text-accent-foreground',
158158
'focus:bg-accent focus:text-accent-foreground',
159159
className

0 commit comments

Comments
 (0)