Example
Next alarm at 06:00.
Example.tsximport { 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
Importimport { 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
| Prop | Type | Default | Description |
|---|
activationMode | ActivationMode | – | Whether a tab is activated automatically or manually.
@defaultValue automatic |
|---|
aria-label | string | – | Defines a string value that labels the current element.
@see aria-labelledby. |
|---|
asChild | boolean | – | Render the single child element instead, merging props and behaviour onto it. |
|---|
defaultValue | string | – | The value of the tab to select by default, if uncontrolled |
|---|
dir | Direction | – | The direction of navigation between toolbar items. |
|---|
id | string | – | Element id. Generated automatically when omitted. |
|---|
onValueChange | ((value: string) => void) | – | A function called when a new tab is selected |
|---|
orientation | Orientation | – | The orientation the tabs are layed out.
Mainly so arrow navigation is done accordingly (left & right vs. up & down)
@defaultValue horizontal |
|---|
value | string | – | The value for the selected tab, if controlled |
|---|
TabsList
| Prop | Type | Default | Description |
|---|
aria-label | string | – | Defines a string value that labels the current element.
@see aria-labelledby. |
|---|
asChild | boolean | – | Render the single child element instead, merging props and behaviour onto it. |
|---|
block | boolean | – | Stretch tabs to share the full width. |
|---|
id | string | – | Element id. Generated automatically when omitted. |
|---|
loop | boolean | – | Whether keyboard navigation wraps from the last item to the first. |
|---|
TabsTrigger
| Prop | Type | Default | Description |
|---|
aria-label | string | – | Defines a string value that labels the current element.
@see aria-labelledby. |
|---|
asChild | boolean | – | Render the single child element instead, merging props and behaviour onto it. |
|---|
disabled | boolean | – | Prevents interaction and dims the control. |
|---|
id | string | – | Element id. Generated automatically when omitted. |
|---|
type | "button" | "submit" | "reset" | – | Button type (defaults to "button"). |
|---|
value | string | – | The value for the selected tab, if controlled |
|---|
TabsContent
| Prop | Type | Default | Description |
|---|
aria-label | string | – | Defines a string value that labels the current element.
@see aria-labelledby. |
|---|
asChild | boolean | – | Render the single child element instead, merging props and behaviour onto it. |
|---|
forceMount | true | – | Used to force mounting when more control is needed. Useful when
controlling animation with React animation libraries. |
|---|
id | string | – | Element id. Generated automatically when omitted. |
|---|
value | string | – | 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.