{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"underline-tabs-with-sliding-indicator","type":"registry:component","title":"Underline Tabs With Sliding Indicator","description":"Free React tab component in Tailwind with an HTML version: a blue underline glides to the chosen tab, with arrow keys, Home and End and full tab roles.","dependencies":[],"files":[{"path":"components/we-inc/underline-tabs-with-sliding-indicator.tsx","type":"registry:component","content":"import { useEffect, useRef, useState, type KeyboardEvent } from \"react\";\n\n// Tabs and their panels. Edit labels and content here.\nconst tabs = [\n  { id: \"overview\", label: \"Overview\", title: \"A quiet room above the harbour\", body: \"Twelve desks, two phone booths and a meeting room for six, a short walk from the ferry terminal. Open from 7am to 9pm on weekdays.\" },\n  { id: \"amenities\", label: \"Amenities\", title: \"What is included\", body: \"Fibre broadband, a kitchen with proper coffee, lockers, printing, showers and secure bike storage in the courtyard.\" },\n  { id: \"pricing\", label: \"Pricing\", title: \"From $240 a month\", body: \"Flexible desks are $240, a fixed desk is $360 and a day pass is $28. No setup fee and one month's notice.\" },\n  { id: \"location\", label: \"Location\", title: \"4 Wharf Lane, upstairs\", body: \"Two minutes from the ferry, five from the main bus stops. Street parking after 6pm and a loading bay for deliveries.\" },\n];\n\nexport default function UnderlineTabsWithSlidingIndicator() {\n  const [active, setActive] = useState(0);\n  const refs = useRef<(HTMLButtonElement | null)[]>([]);\n  const list = useRef<HTMLDivElement>(null);\n  const [bar, setBar] = useState({ x: 0, w: 0 });\n\n  useEffect(() => {\n    const measure = () => {\n      const el = refs.current[active];\n      if (el) setBar({ x: el.offsetLeft, w: el.offsetWidth });\n    };\n    measure();\n    const ro = new ResizeObserver(measure);\n    if (list.current) ro.observe(list.current);\n    return () => ro.disconnect();\n  }, [active]);\n\n  // Keep the chosen tab visible when the row scrolls sideways on phones (not on first render).\n  const first = useRef(true);\n  useEffect(() => {\n    if (first.current) { first.current = false; return; }\n    refs.current[active]?.scrollIntoView({ block: \"nearest\", inline: \"nearest\" });\n  }, [active]);\n\n  const onKey = (e: KeyboardEvent<HTMLDivElement>) => {\n    const last = tabs.length - 1;\n    const next = { ArrowRight: active === last ? 0 : active + 1, ArrowLeft: active === 0 ? last : active - 1, Home: 0, End: last }[e.key];\n    if (next === undefined) return;\n    e.preventDefault();\n    setActive(next);\n    refs.current[next]?.focus();\n  };\n\n  return (\n    <div className=\"bg-white px-4 py-12 sm:px-8\">\n      <div className=\"mx-auto max-w-2xl\">\n        <div className=\"relative overflow-x-auto\">\n          <div ref={list} role=\"tablist\" aria-label=\"Harbour Loft workspace\" onKeyDown={onKey} className=\"relative flex gap-6 border-b border-slate-200\">\n            {tabs.map((t, i) => (\n              <button\n                key={t.id}\n                ref={(el) => { refs.current[i] = el; }}\n                id={`ust-tab-${t.id}`}\n                role=\"tab\"\n                type=\"button\"\n                aria-selected={i === active}\n                aria-controls={`ust-panel-${t.id}`}\n                tabIndex={i === active ? 0 : -1}\n                onClick={() => setActive(i)}\n                className={`h-12 whitespace-nowrap rounded-t px-1 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-600 ${i === active ? \"text-slate-900\" : \"text-slate-600 hover:text-slate-900\"}`}\n              >\n                {t.label}\n              </button>\n            ))}\n            <span\n              aria-hidden=\"true\"\n              className=\"absolute bottom-[-1px] left-0 h-0.5 w-[100px] origin-left rounded-full bg-blue-600 transition-transform duration-300 ease-out motion-reduce:transition-none\"\n              style={{ transform: `translateX(${bar.x}px) scaleX(${bar.w / 100})` }}\n            />\n          </div>\n        </div>\n        {tabs.map((t, i) => (\n          <div key={t.id} id={`ust-panel-${t.id}`} role=\"tabpanel\" aria-labelledby={`ust-tab-${t.id}`} tabIndex={0} hidden={i !== active} className=\"rounded-lg pt-8 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-600\">\n            <h3 className=\"text-2xl font-semibold tracking-tight text-slate-900\">{t.title}</h3>\n            <p className=\"mt-3 max-w-prose leading-7 text-slate-600\">{t.body}</p>\n          </div>\n        ))}\n      </div>\n    </div>\n  );\n}\n"}]}
