From 5576906914cabb83c99ec3cf3b0263acfdfa7bc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Mon, 10 Feb 2025 16:24:27 +0100 Subject: [PATCH] Fix table of content displaying arrow next to page with only hidden pages (#2825) --- .changeset/purple-gorillas-fetch.md | 5 +++++ .../TableOfContents/PageDocumentItem.tsx | 4 ++-- .../components/TableOfContents/PageGroupItem.tsx | 3 ++- packages/gitbook/src/lib/pages.ts | 15 +++++++++++++++ 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 .changeset/purple-gorillas-fetch.md diff --git a/.changeset/purple-gorillas-fetch.md b/.changeset/purple-gorillas-fetch.md new file mode 100644 index 000000000..684ab8486 --- /dev/null +++ b/.changeset/purple-gorillas-fetch.md @@ -0,0 +1,5 @@ +--- +'gitbook': patch +--- + +Fix table of content displaying arrow next to page with only hidden pages diff --git a/packages/gitbook/src/components/TableOfContents/PageDocumentItem.tsx b/packages/gitbook/src/components/TableOfContents/PageDocumentItem.tsx index 1c611d613..89b723cb1 100644 --- a/packages/gitbook/src/components/TableOfContents/PageDocumentItem.tsx +++ b/packages/gitbook/src/components/TableOfContents/PageDocumentItem.tsx @@ -6,7 +6,7 @@ import { } from '@gitbook/api'; import { getPageHref } from '@/lib/links'; -import { getPagePath } from '@/lib/pages'; +import { getPagePath, hasPageVisibleDescendant } from '@/lib/pages'; import { ContentRefContext } from '@/lib/references'; import { tcls } from '@/lib/tailwind'; @@ -39,7 +39,7 @@ export async function PageDocumentItem(props: { }, }} descendants={ - page.pages && page.pages.length ? ( + hasPageVisibleDescendant(page) ? ( {page.title} - {page.pages && page.pages.length ? ( + {hasPageVisibleDescendant(page) ? ( 0 && + page.pages.some( + (child) => + (child.type === RevisionPageType.Link || + child.type === RevisionPageType.Document) && + !child.hidden, + ) + ); +} + /** * Resolve the first page document in a list of pages. */