Skip to content

Commit a2e5647

Browse files
authored
Fix the styling of site section tabs on smaller screens. (#2565)
1 parent 54a797a commit a2e5647

File tree

3 files changed

+22
-26
lines changed

3 files changed

+22
-26
lines changed

.changeset/weak-swans-battle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'gitbook': minor
3+
---
4+
5+
Fix the styling of site section tabs on smaller screens.

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ export function Header(props: {
2626
context: ContentRefContext;
2727
customization: CustomizationSettings | SiteCustomizationSettings;
2828
withTopHeader?: boolean;
29-
children?: React.ReactNode;
3029
}) {
31-
const { children, context, space, site, spaces, sections, customization, withTopHeader } =
32-
props;
30+
const { context, space, site, spaces, sections, customization, withTopHeader } = props;
3331
const isCustomizationDefault =
3432
customization.header.preset === CustomizationHeaderPreset.Default;
3533
const hasSiteSections = sections && sections.list.length > 1;
@@ -145,11 +143,11 @@ export function Header(props: {
145143
<div
146144
className={tcls(
147145
'w-full shadow-thintop dark:shadow-light/1 bg-light dark:bg-dark z-[9] mt-0.5',
146+
// Handle long section tabs, particularly on smaller screens.
147+
'overflow-x-auto hide-scroll',
148148
)}
149149
>
150-
<div className={tcls(CONTAINER_STYLE)}>
151-
<SiteSectionTabs {...sections} />
152-
</div>
150+
<SiteSectionTabs {...sections} />
153151
</div>
154152
) : null}
155153
</header>

packages/gitbook/src/components/SiteSectionTabs/SiteSectionTabs.tsx

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
'use client';
22
import { SiteSection } from '@gitbook/api';
3-
import { Icon } from '@gitbook/icons';
43
import React from 'react';
54

65
import { tcls } from '@/lib/tailwind';
76

8-
import { Button, Link } from '../primitives';
7+
import { Link } from '../primitives';
98

109
/**
1110
* A set of navigational tabs representing site sections for multi-section sites
@@ -35,7 +34,11 @@ export function SiteSectionTabs(props: {
3534
if (currentTabRef.current && navRef.current) {
3635
const rect = currentTabRef.current.getBoundingClientRect();
3736
const navRect = navRef.current.getBoundingClientRect();
38-
setTabDimensions({ left: rect.left - navRect.left, width: rect.width });
37+
38+
setTabDimensions({
39+
left: rect.left - navRect.left,
40+
width: rect.width,
41+
});
3942
}
4043
}, []);
4144

@@ -56,13 +59,11 @@ export function SiteSectionTabs(props: {
5659
const scale = (tabDimensions?.width ?? 0) * 0.01;
5760
const startPos = `${tabDimensions?.left ?? 0}px`;
5861

59-
const hasMoreSections = false; /** TODO: determine whether we need to show the more button */
60-
6162
return tabs.length > 0 ? (
6263
<nav
6364
aria-label="Sections"
6465
ref={navRef}
65-
className="flex flex-nowrap items-center max-w-screen mb-px"
66+
className="flex flex-nowrap items-center mb-px"
6667
style={
6768
{
6869
'--tab-opacity': `${opacity}`,
@@ -77,6 +78,12 @@ export function SiteSectionTabs(props: {
7778
'flex',
7879
'gap-2',
7980
'bg-transparent',
81+
82+
// Horizontal padding, which is the layout padding minus the padding of the tabs themselves.
83+
'px-1',
84+
'sm:px-3',
85+
'md:px-5',
86+
8087
/* add a pseudo element for active tab indicator */
8188
'after:block',
8289
"after:content-['']",
@@ -107,7 +114,6 @@ export function SiteSectionTabs(props: {
107114
/>
108115
))}
109116
</div>
110-
{hasMoreSections ? <MoreSectionsButton /> : null}
111117
</nav>
112118
) : null;
113119
}
@@ -136,16 +142,3 @@ const Tab = React.forwardRef<HTMLSpanElement, { active: boolean; href: string; l
136142
);
137143
},
138144
);
139-
140-
/**
141-
* Dropdown trigger for when there are too many sections to show them all
142-
*/
143-
function MoreSectionsButton() {
144-
return (
145-
<div>
146-
<Button variant="secondary" size="small">
147-
<Icon icon="ellipsis-h" size={12} />
148-
</Button>
149-
</div>
150-
);
151-
}

0 commit comments

Comments
 (0)