From 3e537867bc2d6141e1f80cfa491d320c10fe8551 Mon Sep 17 00:00:00 2001 From: Peter White Date: Mon, 14 Sep 2026 10:22:11 +0200 Subject: [PATCH] Hide anchor links on pages with anchors disabled in the layout --- .../DocumentView/Expandable/Expandable.tsx | 56 ++++++++++--------- .../DocumentView/HashLinkButton.tsx | 13 +++++ .../src/components/DocumentView/Heading.tsx | 37 ++++++------ 3 files changed, 65 insertions(+), 41 deletions(-) diff --git a/packages/gitbook/src/components/DocumentView/Expandable/Expandable.tsx b/packages/gitbook/src/components/DocumentView/Expandable/Expandable.tsx index 2c8e4d05c..2c3832930 100644 --- a/packages/gitbook/src/components/DocumentView/Expandable/Expandable.tsx +++ b/packages/gitbook/src/components/DocumentView/Expandable/Expandable.tsx @@ -3,6 +3,7 @@ import { Icon } from '@gitbook/icons'; import type { BlockProps } from '../Block'; import { Blocks } from '../Blocks'; +import { shouldShowHashLinks } from '../HashLinkButton'; import { Inlines } from '../Inlines'; import { Details } from './Details'; import { ToggleChevron } from '@/components/primitives'; @@ -31,6 +32,8 @@ export async function Expandable(props: BlockProps) { ? await getSpaceLanguage(context.contentContext) : defaultLanguage; + const showHashLink = shouldShowHashLinks(context); + return (
) { className={tcls( 'cursor-pointer', 'px-4', - 'pr-10', + // Reserve room for the anchor icon pinned to the right edge + showHashLink && 'pr-10', 'py-4', 'relative', 'list-none', @@ -71,32 +75,34 @@ export async function Expandable(props: BlockProps) { context={context} ancestorInlines={[]} /> - - - + > + + + ) : null} ) { ? await getSpaceLanguage(context.contentContext) : defaultLanguage; + const showHashLink = shouldShowHashLinks(context); + return ( ) { 'font-heading', 'pdf-heading', 'block', - 'pr-6', + // Reserve room for the absolutely positioned anchor icon on coarse pointers + showHashLink && 'pr-6', 'pointer-fine:flex', 'pointer-fine:items-baseline', 'pointer-fine:pr-0', @@ -63,20 +66,22 @@ export async function Heading(props: BlockProps) { - + {showHashLink ? ( + + ) : null} ); }