@@ -48,25 +48,38 @@ export function TOC({ toc, filePath }: TOCProps): ReactElement {
48
48
behavior : 'smooth' ,
49
49
block : 'center' ,
50
50
inline : 'center' ,
51
- scrollMode : 'always ' ,
52
- boundary : tocRef . current ! . parentElement
51
+ scrollMode : 'if-needed ' ,
52
+ boundary : tocRef . current
53
53
} )
54
54
}
55
55
} , [ activeSlug ] )
56
56
57
57
return (
58
58
< div
59
59
className = { cn (
60
- 'nextra-scrollbar _sticky _top-16 _overflow-y-auto _px-4 _pt-6 _text-sm [hyphens:auto]' ,
61
- '_max-h-[calc(100vh-var(--nextra-navbar-height)-env(safe-area-inset-bottom))]'
60
+ hasHeadings && '_grid _grid-rows-[min-content_1fr_min-content]' , // 1fr: toc headings, min-content: title/footer
61
+ '_sticky _top-[--nextra-navbar-height] _pt-6 _text-sm' ,
62
+ '_max-h-[calc(100vh-var(--nextra-navbar-height))]'
62
63
) }
63
64
>
64
65
{ hasHeadings && (
65
66
< >
66
- < p className = "_mb-4 _font-semibold _tracking-tight" >
67
+ < p
68
+ className = { cn (
69
+ '_mx-4' , // use margin instead padding to not have shadow on scrollbar
70
+ '_font-semibold _tracking-tight' ,
71
+ '_pb-2 _shadow-[0_12px_16px_rgb(var(--nextra-bg))] contrast-more:_shadow-none _z-[1]'
72
+ ) }
73
+ >
67
74
{ renderComponent ( themeConfig . toc . title ) }
68
75
</ p >
69
- < ul ref = { tocRef } >
76
+ < ul
77
+ ref = { tocRef }
78
+ className = { cn (
79
+ '_px-4 nextra-scrollbar _overscroll-y-contain _overflow-y-auto _hyphens-auto' ,
80
+ '_py-1.5' // for title/footer shadow
81
+ ) }
82
+ >
70
83
{ toc . map ( ( { id, value, depth } ) => (
71
84
< li className = "_my-2 _scroll-my-6 _scroll-py-6" key = { id } >
72
85
< a
@@ -75,10 +88,10 @@ export function TOC({ toc, filePath }: TOCProps): ReactElement {
75
88
'nextra-focus' ,
76
89
{
77
90
2 : '_font-semibold' ,
78
- 3 : 'ltr:_ml-4 rtl:_mr -4' ,
79
- 4 : 'ltr:_ml-8 rtl:_mr -8' ,
80
- 5 : 'ltr:_ml-12 rtl:_mr -12' ,
81
- 6 : 'ltr:_ml-16 rtl:_mr -16'
91
+ 3 : '_ms -4' ,
92
+ 4 : '_ms -8' ,
93
+ 5 : '_ms -12' ,
94
+ 6 : '_ms -16'
82
95
} [ depth ] ,
83
96
'_block _transition-colors _subpixel-antialiased' ,
84
97
activeAnchor [ id ] ?. isActive
@@ -98,9 +111,9 @@ export function TOC({ toc, filePath }: TOCProps): ReactElement {
98
111
{ hasMetaInfo && (
99
112
< div
100
113
className = { cn (
101
- hasHeadings && 'nextra-toc-footer _mt-8 _pt-8 ' ,
102
- '_sticky _bottom-0 _flex _flex-col _items-start _gap-2 _pb-8 ' ,
103
- '_-mx-1 _px-1 ' // to hide focused toc links
114
+ hasHeadings && 'nextra-toc-footer _pt-4 ' ,
115
+ '_flex _flex-col _items-start _gap-2 _pb-4 ' ,
116
+ '_mx-4 ' // for border top width
104
117
) }
105
118
>
106
119
{ themeConfig . feedback . content ? (
0 commit comments