Skip to content
Porcelana

Tabs

Tabbed panels with arrow-key navigation.

Example

Next alarm at 06:00.
Example.tsx
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@porcelana/ui";

export default function Example() {
  return (
    <Tabs defaultValue="alarm">
      <TabsList aria-label="Schedule">
        <TabsTrigger value="alarm">Alarm</TabsTrigger>
        <TabsTrigger value="timer">Timer</TabsTrigger>
        <TabsTrigger value="sleep">Sleep</TabsTrigger>
      </TabsList>
      <TabsContent value="alarm">Next alarm at 06:00.</TabsContent>
      <TabsContent value="timer">No timers running.</TabsContent>
      <TabsContent value="sleep">7 h 30 min average this week.</TabsContent>
    </Tabs>
  );
}

Import

Import
import { Tabs, TabsList, TabsTrigger, TabsContent } from "@porcelana/ui";
import "@porcelana/ui/styles.css"; // once, at your app root

Props

Generated from the TypeScript types. Standard HTML attributes are passed through and not listed.

Tabs

PropTypeDefaultDescription
activationModeActivationMode–Whether a tab is activated automatically or manually. @defaultValue automatic
aria-labelstring–Defines a string value that labels the current element. @see aria-labelledby.
asChildboolean–Render the single child element instead, merging props and behaviour onto it.
defaultValuestring–The value of the tab to select by default, if uncontrolled
dirDirection–The direction of navigation between toolbar items.
idstring–Element id. Generated automatically when omitted.
onValueChange((value: string) => void)–A function called when a new tab is selected
orientationOrientation–The orientation the tabs are layed out. Mainly so arrow navigation is done accordingly (left & right vs. up & down) @defaultValue horizontal
valuestring–The value for the selected tab, if controlled

TabsList

PropTypeDefaultDescription
aria-labelstring–Defines a string value that labels the current element. @see aria-labelledby.
asChildboolean–Render the single child element instead, merging props and behaviour onto it.
blockboolean–Stretch tabs to share the full width.
idstring–Element id. Generated automatically when omitted.
loopboolean–Whether keyboard navigation wraps from the last item to the first.

TabsTrigger

PropTypeDefaultDescription
aria-labelstring–Defines a string value that labels the current element. @see aria-labelledby.
asChildboolean–Render the single child element instead, merging props and behaviour onto it.
disabledboolean–Prevents interaction and dims the control.
idstring–Element id. Generated automatically when omitted.
type"button" | "submit" | "reset"–Button type (defaults to "button").
valuestring–The value for the selected tab, if controlled

TabsContent

PropTypeDefaultDescription
aria-labelstring–Defines a string value that labels the current element. @see aria-labelledby.
asChildboolean–Render the single child element instead, merging props and behaviour onto it.
forceMounttrue–Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries.
idstring–Element id. Generated automatically when omitted.
valuestring–The value for the selected tab, if controlled

Accessibility

  • Tab list, tabs and panels are linked with ARIA; arrows move between tabs.
  • Name the list with aria-label.

Mobile

  • The tab list scrolls sideways when it doesn't fit; block makes tabs share the width equally.