From 29a0d7ea02c87b3d3c515e400e22e68c0dd0aa2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Berg=C3=A9?= Date: Wed, 11 Dec 2024 18:57:55 +0100 Subject: [PATCH] Fix sublinks display on mobile (#2620) --- .../src/components/Header/Dropdown.tsx | 43 +++++++++++-------- .../src/components/Header/HeaderLinkMore.tsx | 24 ++++++++--- 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/packages/gitbook/src/components/Header/Dropdown.tsx b/packages/gitbook/src/components/Header/Dropdown.tsx index 598cf064f..73ef1bee3 100644 --- a/packages/gitbook/src/components/Header/Dropdown.tsx +++ b/packages/gitbook/src/components/Header/Dropdown.tsx @@ -39,7 +39,7 @@ export function Dropdown(props: { aria-labelledby={dropdownId} className={tcls( 'w-52', - 'max-h-56', + 'max-h-80', 'flex', 'absolute', 'top-full', @@ -111,31 +111,38 @@ export function DropdownMenu(props: { children: React.ReactNode }) { * Menu item in a dropdown. */ export function DropdownMenuItem(props: { - href: string; + href: string | null; active?: boolean; + className?: ClassValue; children: React.ReactNode; }) { - const { children, active = false, href } = props; + const { children, active = false, href, className } = props; + + if (href) { + return ( + + {children} + + ); + } return ( - {children} - + ); } diff --git a/packages/gitbook/src/components/Header/HeaderLinkMore.tsx b/packages/gitbook/src/components/Header/HeaderLinkMore.tsx index 132a1cac5..f5c80d09a 100644 --- a/packages/gitbook/src/components/Header/HeaderLinkMore.tsx +++ b/packages/gitbook/src/components/Header/HeaderLinkMore.tsx @@ -1,4 +1,5 @@ import { + CustomizationContentLink, CustomizationHeaderItem, CustomizationHeaderPreset, CustomizationSettings, @@ -55,14 +56,25 @@ export function HeaderLinkMore(props: { ); } -async function MoreMenuLink(props: { context: ContentRefContext; link: CustomizationHeaderItem }) { +async function MoreMenuLink(props: { + context: ContentRefContext; + link: CustomizationHeaderItem | CustomizationContentLink; +}) { const { context, link } = props; const target = link.to ? await resolveContentRef(link.to, context) : null; - if (!target) { - return null; - } - - return {link.title}; + return ( + <> + {'links' in link && link.links.length > 0 && ( +
+ )} + {link.title} + {'links' in link + ? link.links.map((subLink, index) => ( + + )) + : null} + + ); }