Skip to content

Commit 29a0d7e

Browse files
authored
Fix sublinks display on mobile (#2620)
1 parent 1f2b7f7 commit 29a0d7e

File tree

2 files changed

+43
-24
lines changed

2 files changed

+43
-24
lines changed

packages/gitbook/src/components/Header/Dropdown.tsx

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export function Dropdown<E extends HTMLElement>(props: {
3939
aria-labelledby={dropdownId}
4040
className={tcls(
4141
'w-52',
42-
'max-h-56',
42+
'max-h-80',
4343
'flex',
4444
'absolute',
4545
'top-full',
@@ -111,31 +111,38 @@ export function DropdownMenu(props: { children: React.ReactNode }) {
111111
* Menu item in a dropdown.
112112
*/
113113
export function DropdownMenuItem(props: {
114-
href: string;
114+
href: string | null;
115115
active?: boolean;
116+
className?: ClassValue;
116117
children: React.ReactNode;
117118
}) {
118-
const { children, active = false, href } = props;
119+
const { children, active = false, href, className } = props;
120+
121+
if (href) {
122+
return (
123+
<Link
124+
href={href}
125+
prefetch={false}
126+
className={tcls(
127+
'px-3 py-1 text-sm rounded straight-corners:rounded-sm',
128+
active ? 'bg-primary/3 dark:bg-light/2 text-primary-600' : null,
129+
'hover:bg-dark/2 dark:hover:bg-light/2',
130+
className,
131+
)}
132+
>
133+
{children}
134+
</Link>
135+
);
136+
}
119137

120138
return (
121-
<Link
122-
href={href}
123-
prefetch={false}
139+
<div
124140
className={tcls(
125-
'flex',
126-
'flex-row',
127-
'items-center',
128-
'text-sm',
129-
'px-3',
130-
'py-1',
131-
'rounded',
132-
'straight-corners:rounded-sm',
133-
active
134-
? ['bg-primary/3', 'dark:bg-light/2', 'text-primary-600']
135-
: ['hover:bg-dark/2', 'dark:hover:bg-light/2'],
141+
'text-xs px-3 py-1 font-medium text-dark/8 dark:text-light/8',
142+
className,
136143
)}
137144
>
138145
{children}
139-
</Link>
146+
</div>
140147
);
141148
}

packages/gitbook/src/components/Header/HeaderLinkMore.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
CustomizationContentLink,
23
CustomizationHeaderItem,
34
CustomizationHeaderPreset,
45
CustomizationSettings,
@@ -55,14 +56,25 @@ export function HeaderLinkMore(props: {
5556
);
5657
}
5758

58-
async function MoreMenuLink(props: { context: ContentRefContext; link: CustomizationHeaderItem }) {
59+
async function MoreMenuLink(props: {
60+
context: ContentRefContext;
61+
link: CustomizationHeaderItem | CustomizationContentLink;
62+
}) {
5963
const { context, link } = props;
6064

6165
const target = link.to ? await resolveContentRef(link.to, context) : null;
6266

63-
if (!target) {
64-
return null;
65-
}
66-
67-
return <DropdownMenuItem href={target.href}>{link.title}</DropdownMenuItem>;
67+
return (
68+
<>
69+
{'links' in link && link.links.length > 0 && (
70+
<hr className="first:hidden border-t border-light-3 dark:border-dark-3 my-1 -mx-2" />
71+
)}
72+
<DropdownMenuItem href={target?.href ?? null}>{link.title}</DropdownMenuItem>
73+
{'links' in link
74+
? link.links.map((subLink, index) => (
75+
<MoreMenuLink key={index} {...props} link={subLink} />
76+
))
77+
: null}
78+
</>
79+
);
6880
}

0 commit comments

Comments
 (0)