Fix mega menu layout: keep panel in header container and show childless categories in one row.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Alireza Hassani
2026-09-04 15:10:24 +03:30
co-authored by Cursor
parent cfabf3e327
commit aa0e21d2ce
2 changed files with 101 additions and 20 deletions
+23 -3
View File
@@ -11,6 +11,8 @@ export function ProductsMegaMenu({ categories }: { categories: Category[] }) {
const tree = buildCategoryTree(categories).filter( const tree = buildCategoryTree(categories).filter(
(node) => node.children.length > 0 || !node.parentId, (node) => node.children.length > 0 || !node.parentId,
); );
const withChildren = tree.filter((node) => node.children.length > 0);
const leafParents = tree.filter((node) => node.children.length === 0);
return ( return (
<div <div
@@ -47,8 +49,9 @@ export function ProductsMegaMenu({ categories }: { categories: Category[] }) {
{tree.length === 0 ? ( {tree.length === 0 ? (
<p className="empty-note">دسته‌بندی‌ای برای نمایش وجود ندارد.</p> <p className="empty-note">دسته‌بندی‌ای برای نمایش وجود ندارد.</p>
) : ( ) : (
<>
<div className="mega-menu-grid"> <div className="mega-menu-grid">
{tree.map((parent) => ( {withChildren.map((parent) => (
<div key={parent.id} className="mega-menu-column"> <div key={parent.id} className="mega-menu-column">
<Link <Link
href={storeCategoryHref(parent.id, categoryLabel(parent))} href={storeCategoryHref(parent.id, categoryLabel(parent))}
@@ -57,7 +60,6 @@ export function ProductsMegaMenu({ categories }: { categories: Category[] }) {
> >
{categoryLabel(parent)} {categoryLabel(parent)}
</Link> </Link>
{parent.children.length > 0 ? (
<ul className="mega-menu-children"> <ul className="mega-menu-children">
{parent.children.map((child) => ( {parent.children.map((child) => (
<li key={child.id}> <li key={child.id}>
@@ -71,10 +73,28 @@ export function ProductsMegaMenu({ categories }: { categories: Category[] }) {
</li> </li>
))} ))}
</ul> </ul>
) : null}
</div> </div>
))} ))}
</div> </div>
{leafParents.length > 0 ? (
<div className="mega-menu-leaf-row">
<p className="mega-menu-leaf-label">More</p>
<ul className="mega-menu-leaf-list">
{leafParents.map((parent) => (
<li key={parent.id}>
<Link
href={storeCategoryHref(parent.id, categoryLabel(parent))}
className="mega-menu-parent-leaf"
onClick={() => setOpen(false)}
>
{categoryLabel(parent)}
</Link>
</li>
))}
</ul>
</div>
) : null}
</>
)} )}
</div> </div>
) : null} ) : null}
+67 -6
View File
@@ -71,6 +71,7 @@ textarea {
} }
.header-inner { .header-inner {
position: relative;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
@@ -1802,7 +1803,7 @@ a.article-card:hover .article-media img {
} }
.mega-menu { .mega-menu {
position: relative; position: static;
} }
.mega-menu-trigger { .mega-menu-trigger {
@@ -1825,22 +1826,34 @@ a.article-card:hover .article-media img {
position: absolute; position: absolute;
top: calc(100% + 14px); top: calc(100% + 14px);
right: 0; right: 0;
width: min(760px, 70vw); left: 0;
padding: 18px; width: auto;
max-width: none;
padding: 20px 22px;
border-radius: 22px; border-radius: 22px;
background: rgba(255, 255, 255, 0.97); background: rgba(255, 255, 255, 0.97);
box-shadow: var(--shadow); box-shadow: var(--shadow);
z-index: 35; z-index: 35;
} }
.mega-menu-panel::before {
content: "";
position: absolute;
top: -18px;
right: 0;
left: 0;
height: 18px;
}
.mega-menu-grid { .mega-menu-grid {
display: grid; display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 16px; gap: 18px 22px;
} }
.mega-menu-column { .mega-menu-column {
padding: 4px 2px 8px; padding: 4px 2px 8px;
min-width: 0;
} }
.mega-menu-parent { .mega-menu-parent {
@@ -1879,6 +1892,52 @@ a.article-card:hover .article-media img {
color: var(--secondary); color: var(--secondary);
} }
.mega-menu-leaf-row {
margin-top: 18px;
padding-top: 16px;
border-top: 1px solid rgba(0, 35, 75, 0.08);
}
.mega-menu-leaf-label {
margin: 0 0 12px;
color: var(--secondary);
font-family: var(--font-en-title);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.mega-menu-leaf-list {
display: flex;
flex-wrap: wrap;
gap: 8px 10px;
margin: 0;
padding: 0;
list-style: none;
}
.mega-menu-parent-leaf {
display: inline-flex;
align-items: center;
padding: 8px 14px;
border: 1px solid rgba(0, 35, 75, 0.1);
border-radius: 999px;
color: var(--primary);
background: rgba(248, 243, 236, 0.7);
font-size: 13px;
font-weight: 700;
line-height: 1.4;
text-decoration: none;
transition: border-color 180ms ease, color 180ms ease, background 180ms ease;
}
.mega-menu-parent-leaf:hover {
border-color: rgba(204, 153, 102, 0.5);
color: var(--secondary);
background: rgba(255, 255, 255, 0.95);
}
.cart-drawer-root { .cart-drawer-root {
position: fixed; position: fixed;
inset: 0; inset: 0;
@@ -2250,7 +2309,9 @@ a.article-card:hover .article-media img {
} }
.mega-menu-panel { .mega-menu-panel {
width: min(92vw, 520px); width: auto;
left: 0;
right: 0;
} }
} }