Skip to content

Commit 5576906

Browse files
authored
Fix table of content displaying arrow next to page with only hidden pages (#2825)
1 parent d5aaccd commit 5576906

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

.changeset/purple-gorillas-fetch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'gitbook': patch
3+
---
4+
5+
Fix table of content displaying arrow next to page with only hidden pages

packages/gitbook/src/components/TableOfContents/PageDocumentItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from '@gitbook/api';
77

88
import { getPageHref } from '@/lib/links';
9-
import { getPagePath } from '@/lib/pages';
9+
import { getPagePath, hasPageVisibleDescendant } from '@/lib/pages';
1010
import { ContentRefContext } from '@/lib/references';
1111
import { tcls } from '@/lib/tailwind';
1212

@@ -39,7 +39,7 @@ export async function PageDocumentItem(props: {
3939
},
4040
}}
4141
descendants={
42-
page.pages && page.pages.length ? (
42+
hasPageVisibleDescendant(page) ? (
4343
<PagesList
4444
rootPages={rootPages}
4545
pages={page.pages}

packages/gitbook/src/components/TableOfContents/PageGroupItem.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { RevisionPage, RevisionPageDocument, RevisionPageGroup } from '@gitbook/api';
22

3+
import { hasPageVisibleDescendant } from '@/lib/pages';
34
import { ContentRefContext } from '@/lib/references';
45
import { tcls } from '@/lib/tailwind';
56

@@ -47,7 +48,7 @@ export function PageGroupItem(props: {
4748
<TOCPageIcon page={page} />
4849
{page.title}
4950
</div>
50-
{page.pages && page.pages.length ? (
51+
{hasPageVisibleDescendant(page) ? (
5152
<PagesList
5253
rootPages={rootPages}
5354
pages={page.pages}

packages/gitbook/src/lib/pages.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,21 @@ export function getPagePath(
121121
return page.path;
122122
}
123123

124+
/**
125+
* Test if a page has at least one descendant.
126+
*/
127+
export function hasPageVisibleDescendant(page: RevisionPageGroup | RevisionPageDocument): boolean {
128+
return (
129+
page.pages.length > 0 &&
130+
page.pages.some(
131+
(child) =>
132+
(child.type === RevisionPageType.Link ||
133+
child.type === RevisionPageType.Document) &&
134+
!child.hidden,
135+
)
136+
);
137+
}
138+
124139
/**
125140
* Resolve the first page document in a list of pages.
126141
*/

0 commit comments

Comments
 (0)