Fumadocs

Tabs

A Tabs component built with Radix UI, with additional features such as persistent and shared value.

Hello World in Javascript
Value is shared! Try refresh and see if the value is persisted

Usage

Import it in your MDX documents.

import { Tab, Tabs } from 'fumadocs-ui/components/tabs';
 
<Tabs items={['Javascript', 'Rust']}>
  <Tab value="Javascript">Javascript is weird</Tab>
  <Tab value="Rust">Rust is fast</Tab>
</Tabs>

Shared Value

By passing an id property, you can share a value across all tabs with the same id.

<Tabs groupId="language" items={['Javascript', 'Rust']}>
  <Tab value="Javascript">Javascript is weird</Tab>
  <Tab value="Rust">Rust is fast</Tab>
</Tabs>

Persistent

You can enable persistent by passing a persist property. The value will be stored in localStorage, with its id as the key.

<Tabs groupId="language" items={['Javascript', 'Rust']} persist>
  <Tab value="Javascript">Javascript is weird</Tab>
  <Tab value="Rust">Rust is fast</Tab>
</Tabs>

Persistent only works if you have passed an id.

Default Value

Set a default value by passing defaultIndex.

<Tabs
  items={['Javascript', 'Rust']}
  defaultIndex={1}
>...</Tab>

Advanced

You can use the styled Radix UI primitive directly from exported Primitive.

import { Primitive } from 'fumadocs-ui/components/tabs';
 
<Primitive.Tabs>
  <Primitive.TabsList>
    <Primitive.TabsTrigger />
  </Primitive.TabsList>
  <Primitive.TabsContent />
</Primitive.Tabs>

Last updated on

On this page

Edit on Github