@@ -5,6 +5,8 @@ import React, { useCallback, useMemo } from 'react';
5
5
import { useHash , useIsMounted } from '@/components/hooks' ;
6
6
import * as storage from '@/lib/local-storage' ;
7
7
import { type ClassValue , tcls } from '@/lib/tailwind' ;
8
+ import type { DocumentBlockTabs } from '@gitbook/api' ;
9
+ import { HashLinkButton , hashLinkButtonWrapperStyles } from '../HashLinkButton' ;
8
10
9
11
interface TabsState {
10
12
activeIds : {
@@ -68,9 +70,10 @@ export function DynamicTabs(
68
70
props : TabsInput & {
69
71
tabsBody : React . ReactNode [ ] ;
70
72
style : ClassValue ;
73
+ block : DocumentBlockTabs ;
71
74
}
72
75
) {
73
- const { id, tabs, tabsBody, style } = props ;
76
+ const { id, block , tabs, tabsBody, style } = props ;
74
77
75
78
const hash = useHash ( ) ;
76
79
const [ tabsState , setTabsState ] = useTabsState ( ) ;
@@ -146,8 +149,8 @@ export function DynamicTabs(
146
149
'ring-inset' ,
147
150
'ring-tint-subtle' ,
148
151
'flex' ,
149
- 'overflow-hidden' ,
150
152
'flex-col' ,
153
+ 'overflow-hidden' ,
151
154
style
152
155
) }
153
156
>
@@ -165,16 +168,14 @@ export function DynamicTabs(
165
168
) }
166
169
>
167
170
{ tabs . map ( ( tab ) => (
168
- < button
171
+ < div
169
172
key = { tab . id }
170
- role = "tab"
171
- aria-selected = { active . id === tab . id }
172
- aria-controls = { getTabPanelId ( tab . id ) }
173
- id = { getTabButtonId ( tab . id ) }
174
- onClick = { ( ) => {
175
- onSelectTab ( tab ) ;
176
- } }
177
173
className = { tcls (
174
+ hashLinkButtonWrapperStyles ,
175
+ 'flex' ,
176
+ 'items-center' ,
177
+ 'gap-3.5' ,
178
+
178
179
//prev from active-tab
179
180
'[&:has(+_.active-tab)]:rounded-br-md' ,
180
181
@@ -184,14 +185,6 @@ export function DynamicTabs(
184
185
//next from active-tab
185
186
'[.active-tab_+_:after]:rounded-br-md' ,
186
187
187
- 'inline-block' ,
188
- 'text-sm' ,
189
- 'px-3.5' ,
190
- 'py-2' ,
191
- 'transition-[color]' ,
192
- 'font-[500]' ,
193
- 'relative' ,
194
-
195
188
'after:transition-colors' ,
196
189
'after:border-r' ,
197
190
'after:absolute' ,
@@ -202,14 +195,16 @@ export function DynamicTabs(
202
195
'after:h-[70%]' ,
203
196
'after:w-[1px]' ,
204
197
198
+ 'px-3.5' ,
199
+ 'py-2' ,
200
+
205
201
'last:after:border-transparent' ,
206
202
207
203
'text-tint' ,
208
204
'bg-tint-12/1' ,
209
205
'hover:text-tint-strong' ,
210
-
211
- 'truncate' ,
212
206
'max-w-full' ,
207
+ 'truncate' ,
213
208
214
209
active . id === tab . id
215
210
? [
@@ -224,8 +219,34 @@ export function DynamicTabs(
224
219
: null
225
220
) }
226
221
>
227
- { tab . title }
228
- </ button >
222
+ < button
223
+ type = "button"
224
+ role = "tab"
225
+ aria-selected = { active . id === tab . id }
226
+ aria-controls = { getTabPanelId ( tab . id ) }
227
+ id = { getTabButtonId ( tab . id ) }
228
+ onClick = { ( ) => {
229
+ onSelectTab ( tab ) ;
230
+ } }
231
+ className = { tcls (
232
+ 'inline-block' ,
233
+ 'text-sm' ,
234
+ 'transition-[color]' ,
235
+ 'font-[500]' ,
236
+ 'relative' ,
237
+ 'max-w-full' ,
238
+ 'truncate'
239
+ ) }
240
+ >
241
+ { tab . title }
242
+ </ button >
243
+
244
+ < HashLinkButton
245
+ id = { getTabButtonId ( tab . id ) }
246
+ block = { block }
247
+ label = "Direct link to tab"
248
+ />
249
+ </ div >
229
250
) ) }
230
251
</ div >
231
252
{ tabs . map ( ( tab , index ) => (
0 commit comments