/Navigation
Navigation • React
Sliding Content Tabs
A compact tab switcher with a sliding active surface and content transition.
1,284 people are in your audience.
Installation
Requires lucide-react for its icons. The shadcn CLI installs it for you; copying the code by hand means installing it yourself.
Terminal
npx shadcn@latest add https://microkit.co/r/sliding-content-tabs.jsonCode
1"use client";23import { useState } from "react";4import { Star, ThumbsUp, Users } from "lucide-react";56const tabs = [7{ label: "Audience", content: "1,284 people are in your audience.", Icon: Users },8{ label: "Reactions", content: "68 people reacted to your latest post.", Icon: ThumbsUp },9{ label: "Saved", content: "12 items are saved for later.", Icon: Star },10];1112export function SlidingContentTabs() {13const [active, setActive] = useState(0);14const activeTab = tabs[active];1516return (17<section className="w-full max-w-[288px] rounded-[10px] border border-[#30343a] bg-[#101216] p-[5px]">18<div className="relative grid grid-cols-3" role="tablist" aria-label="Activity">19{tabs.map(({ label, Icon }, index) => (20<button21key={label}22id={`sliding-tab-${index}`}23type="button"24role="tab"25aria-selected={active === index}26className={`relative z-10 inline-flex min-w-0 items-center justify-center gap-1.5 rounded-md border-0 bg-transparent px-1.5 py-[9px] text-[11px] transition-colors duration-300 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-[#f97316] ${active === index ? "text-white" : "text-[#858c96]"}`}27onClick={() => setActive(index)}28>29<Icon size={15} strokeWidth={1.8} aria-hidden="true" />30<span>{label}</span>31</button>32))}33<span34className="pointer-events-none absolute inset-y-0 left-0 w-1/3 rounded-md bg-[#f97316] shadow-[0_1px_2px_#0005] transition-transform duration-[750ms] ease-[cubic-bezier(.22,1,.36,1)]"35style={{ transform: `translateX(${active * 100}%)` }}36aria-hidden="true"37/>38</div>39<p key={active} className="m-0 px-2 pb-[7px] pt-[14px] text-[11px] leading-[1.4] text-[#a9afb8]">40{activeTab.content}41</p>42</section>43);44}