ui icon indicating copy to clipboard operation
ui copied to clipboard

Active tab is not highlighting

Open kibria-shaped opened this issue 2 years ago • 13 comments

Basically I copied whole Tab example, but Active tabs not highlighted

import { Button } from "@/components/ui/button"
import {
  Card,
  CardContent,
  CardDescription,
  CardFooter,
  CardHeader,
  CardTitle,
} from "@/components/ui/card"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"

export function TabsDemo() {
  return (
    <Tabs defaultValue="account" className="w-[400px]">
      <TabsList className="grid w-full grid-cols-2">
        <TabsTrigger value="account">Account</TabsTrigger>
        <TabsTrigger value="password">Password</TabsTrigger>
      </TabsList>
      <TabsContent value="account">
        <Card>
          <CardHeader>
            <CardTitle>Account</CardTitle>
            <CardDescription>
              Make changes to your account here. Click save when you're done.
            </CardDescription>
          </CardHeader>
          <CardContent className="space-y-2">
            <div className="space-y-1">
              <Label htmlFor="name">Name</Label>
              <Input id="name" defaultValue="Pedro Duarte" />
            </div>
            <div className="space-y-1">
              <Label htmlFor="username">Username</Label>
              <Input id="username" defaultValue="@peduarte" />
            </div>
          </CardContent>
          <CardFooter>
            <Button>Save changes</Button>
          </CardFooter>
        </Card>
      </TabsContent>
      <TabsContent value="password">
        <Card>
          <CardHeader>
            <CardTitle>Password</CardTitle>
            <CardDescription>
              Change your password here. After saving, you'll be logged out.
            </CardDescription>
          </CardHeader>
          <CardContent className="space-y-2">
            <div className="space-y-1">
              <Label htmlFor="current">Current password</Label>
              <Input id="current" type="password" />
            </div>
            <div className="space-y-1">
              <Label htmlFor="new">New password</Label>
              <Input id="new" type="password" />
            </div>
          </CardContent>
          <CardFooter>
            <Button>Save password</Button>
          </CardFooter>
        </Card>
      </TabsContent>
    </Tabs>
  )
}

Screenshot 2023-06-17 013316

kibria-shaped avatar Jun 16 '23 19:06 kibria-shaped

We need more info too understand your problem, can you provide a working example were the problem occurs?

dan5py avatar Jun 17 '23 12:06 dan5py

Any luck fixing this ??? im running into this issue too

poipiii avatar Jun 27 '23 02:06 poipiii

I'm also running into this issue

BaileySimrell avatar Jun 30 '23 22:06 BaileySimrell

I'm also running into this issue

OK, I found a way to get things working by editing the base tabs.tsx code to use Tailwind instead of data-state attributes to handle color. I figure this is some sort of bug/conflict with @radix-ui/react-tabs, but I'm. not sure.

Below is a screenshot of my workaround diff in Fork:

Screenshot 2023-06-30 at 6 59 02 PM

Most likely due to existing conflicts with @radix-ui/react-tabs and Tailwind in the code, I still couldn't get the empty state working without adding some custom css:

Screenshot 2023-06-30 at 7 10 43 PM

BaileySimrell avatar Jun 30 '23 23:06 BaileySimrell

i have same problem i just add active color manually, create useState like this and add condition to classname

mahamaad avatar Aug 09 '23 14:08 mahamaad

So i had this problem, but for me, I had accidentally imported TabsTrigger from radix instead of from the new component. I kind if wish other names were used as there are a LOT of component names that match radix and by default my editor wants to import them it seems.

schmoli avatar Aug 22 '23 18:08 schmoli

You need to ensure you have CSS variables set like --background which is expecting an HSL value, like so:

:root {
  --background: 217.78, 19.71%, 26.86%;
}

Once doing this, the highlighting worked as expected.

grafficmedia avatar Oct 05 '23 15:10 grafficmedia

I will say that the documentation of ShadCN definitely needs to be improved to highlight this requirement. Also it would be extremely helpful if each component page had a Props list.

grafficmedia avatar Oct 05 '23 15:10 grafficmedia

I've managed to make this work by adding className="data-[state=active]:bg-white" to the <TabsTrigger.

🤔 I'm not sure why this fixes the issue, but also toggles the shadow correctly!

<TabsTrigger className="data-[state=active]:bg-white" value="raw">
  Edit
</TabsTrigger>
<TabsTrigger
  className="data-[state=active]:bg-white"
  value="formatted"
>
  Formatted
</TabsTrigger>

sanchezfdezjavier avatar Dec 12 '23 00:12 sanchezfdezjavier

For anyone struggling with this too, for me it turned out to be my version of Tailwind. I was on something like 3.1 and I upgraded to latest 3.4 and it now works fine. So if the data attribute is being set correctly but the class isn't applying it's likely it's just that Tailwind isn't handling that. HTH.

marcwickenden avatar Dec 20 '23 10:12 marcwickenden

I had the same issue, but simply updating my tailwind-css solved it!

tanifort avatar Feb 24 '24 10:02 tanifort

In parent tab Tabs in attr defaultValue you setup which tab item will be active: <Tabs defaultValue="valueOfTabItem">

crowscript avatar May 27 '24 19:05 crowscript

I've managed to make this work by adding className="data-[state=active]:bg-white" to the <TabsTrigger.

🤔 I'm not sure why this fixes the issue, but also toggles the shadow correctly!

<TabsTrigger className="data-[state=active]:bg-white" value="raw">
  Edit
</TabsTrigger>
<TabsTrigger
  className="data-[state=active]:bg-white"
  value="formatted"
>
  Formatted
</TabsTrigger>

This worked bro. Thankyou

pramodpurushan77 avatar Jun 11 '24 17:06 pramodpurushan77

This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you.

shadcn avatar Jul 03 '24 23:07 shadcn