Tabs
Use tabs to quickly switch between different views.
import { TabGroup, Tab } from '@brainandbones/skeleton';
Examples
Content A
Content A
Books
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Usage
import { writable, type Writable } from "svelte/store";
let storeTab: Writable<string> = writable('a');
<TabGroup selected={storeTab} justify="justify-start md:justify-center" highlight="border-accent-500" color="text-accent-500">
<Tab value="a">Tab A</Tab>
<Tab value="b">
<svelte:fragment>{@html icon}</svelte:fragment>
<span>Tab B</span>
</Tab>
</TabGroup>
<!-- Conditionally display content -->
{#if $storeTab === 'a'}Content A{/if}
{#if $storeTab === 'b'}Content B{/if}
Properties
Tab Group
Prop | Type | Default | Required | Description |
---|---|---|---|---|
selected | Writable | - | ✓ | A svelte store to keep track of tab selection. |
justify | string | justify-start | - | Provide classes to set the flex justification. 'justify-start' is best small screens. |
borderWidth | string | border-b-2 | - | Provide classes to set the selected border thickness size. Shared between group and tab. |
borderColor | string | border-primary-500 | - | Provide classes to set the selected border color. |
color | string | text-primary-500 | - | Provide class to set the selected text color. |
fill | string | fill-primary-500 | - | Provide classes to set the selected SVG fill color. |
hover | string | hover:bg-surface-500/10 | - | Provide classes to set the unselected hover styles. |
rounded | string | rounded-tl-lg rounded-tr-lg | - | Provide classes to set the tab border radius styles. |
Tab
Prop | Type | Description |
---|---|---|
value | any | The value of each tab. |
Slots
Tab
Name | Description |
---|---|
lead | Provides a leading position, which can be used for icons. |
Accessibility
ARIA GuidelinesTab Group
Prop | Type | Required | Description |
---|---|---|---|
labeledby | string | - | Provide the ID of the element that describes the group. |
label | string | - | Defines a semantic label for the group. |
Tab
Prop | Type | Required | Description |
---|---|---|---|
label | string | - | Defines a semantic label for the tab. |
Keyboard Interactions
Keys | Description |
---|---|
Tab | Moves focus to the next focusable Tab. |
Shift + Tab | Moves focus to the previous focusable Tab. |
Home | Moves focus to the first tab. |
End | Moves focus to the last tab. |
Space or Enter | Activates the tab if it was not activated automatically on focus. |