This repository was archived by the owner on May 20, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,9 @@ export interface TabItemProps extends PropsWithChildren {
20
20
label : string
21
21
}
22
22
23
+ // for a11y, remove spaces from the tab label
24
+ const removeSpaces = ( str : string ) => str . replace ( / \s / g, '' )
25
+
23
26
export const Tabs : React . FC < TabProps > = ( {
24
27
children,
25
28
value,
@@ -33,16 +36,16 @@ export const Tabs: React.FC<TabProps> = ({
33
36
34
37
return (
35
38
< BaseTabs
36
- defaultValue = { tabs [ 0 ] ? tabs [ 0 ] . props . label : undefined }
39
+ defaultValue = { tabs [ 0 ] ? removeSpaces ( tabs [ 0 ] . props . label ) : undefined }
37
40
value = { syncKey ? get ( syncKey ) : value }
38
41
onValueChange = { syncKey ? ( value ) => set ( syncKey , value ) : onValueChange }
39
42
ref = { ref }
40
43
>
41
44
< TabsList className = "relative mx-0 mb-2 mt-auto h-12 w-full rounded-b-none bg-transparent p-0" >
42
45
{ tabs . map ( ( tab ) => (
43
46
< TabsTrigger
44
- value = { tab . props . label }
45
- key = { tab . props . label }
47
+ value = { removeSpaces ( tab . props . label ) }
48
+ key = { removeSpaces ( tab . props . label ) }
46
49
className = "group/tab relative h-12 hover:text-zinc-600 data-[state=active]:bg-transparent data-[state=active]:text-primary data-[state=active]:shadow-none dark:hover:text-zinc-200 dark:data-[state=active]:text-primary-300"
47
50
>
48
51
{ tab . props . label }
@@ -57,5 +60,5 @@ export const Tabs: React.FC<TabProps> = ({
57
60
}
58
61
59
62
export const TabItem : React . FC < TabItemProps > = ( { children, label } ) => {
60
- return < TabsContent value = { label } > { children } </ TabsContent >
63
+ return < TabsContent value = { removeSpaces ( label ) } > { children } </ TabsContent >
61
64
}
You can’t perform that action at this time.
0 commit comments