ui: Active tab is not highlighting
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>
)
}
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 18 (1 by maintainers)
Commits related to this issue
- fix: export `TableFooter.vue` from ui/table components (#605) — committed to u007/ui by kylemilloy 2 years ago
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!
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.
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:
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:
In parent tab
Tabsin attrdefaultValueyou setup which tab item will be active:<Tabs defaultValue="valueOfTabItem">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
Propslist.You need to ensure you have CSS variables set like
--backgroundwhich is expecting an HSL value, like so:Once doing this, the highlighting worked as expected.
TabsTrigger’s hover/select effects didn’t work after upgrading from tailwind v3 to v4. I have fixed it by replacing my main css file with this one: https://github.com/shadcn-ui/ui/blob/1bd209a4dbe555eab45a47d03d3fe6c819b5e753/apps/v4/app/globals.css
and also grabbed colors from here: https://ui.shadcn.com/docs/theming#base-colors
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.
This worked bro. Thankyou