Skip to main content

Tabs

import { Tabs } from "@study/ui"

Result
Loading...
Live Editor
function Example() {
  const [tab, setTab] = useState("overview");
  return (
    <Tabs
      label="Areas of the course"
      active={tab}
      onSelect={setTab}
      items={[
        { id: "overview", label: "Overview" },
        { id: "documents", label: "Documents" },
        { id: "notes", label: "Notes" },
        { id: "lectures", label: "Lectures" },
        { id: "flashcards", label: "Flashcards", count: 11 },
      ]}
      trailing={<IconButton icon="more" label="More areas" />}
    />
  );
}

In the app the tabs are links, so that every area has its own address:

<Tabs label="Bereiche des Fachs" active={tab} linkAs={Link}
items={MAIN_TABS.map((t) => ({ id: t, label: de.tabs[t], href: `/faecher/${id}/${t}` }))} />

Variants and states​

Light

Dark

When to use​

  • For areas of one thing (a course, the settings) – not for the main navigation.
  • At most six visible; rare ones behind an IconButton ⋯ as trailing.
  • For choosing a value: SegmentedControl.

Props​

PropTypeDefaultMeaning
active *string–The id of the current tab.
items *TabItem[]–
label *string–What the tabs switch between, e.g. "Areas of the course".
classNamestring–
linkAsElementType–The link element for `href` tabs, e.g. react-router's `Link` (it gets `to`).
onSelect((id: string) => void)–
size"sm" | "md"md
trailingReactNode–At the end of the bar, e.g. an `IconButton` "More areas".

Accessibility​

  • A nav with a name; the active tab is aria-current.
  • Links stay links (Ctrl-click, back button); buttons stay buttons.