Directory
- Welcome
Tabs Component
The Tabs component creates an interactive interface that organizes content into separate, easily accessible sections. Each tab panel displays unique content while keeping your interface clean and focused.
Key Features
-
Synchronized Groups: Link multiple tab sets together
-
Accessibility: Full ARIA support and keyboard navigation
-
Custom Styling: Extensive style customization options
Basic Usage
Create tabbed interfaces with the Tabs
and TabItem
components:
<Tabs> <TabItem label="First Tab"> Content for the first tab </TabItem> <TabItem label="Second Tab"> Content for the second tab </TabItem></Tabs>
Animation Types
The Tabs component supports two different animation types:
fade
(Default): Smoothly fades between tabsslide
: Slides between tabs
Tabs Component API
Tabs Props
Prop | Type | Default | Description |
---|---|---|---|
defaultTab | string | First tab | Label of initially active tab |
syncKey | string | Key for synchronizing multiple tab groups | |
labels | string[] | Optional array of tab labels | |
buttonProps | ButtonProps | Props passed to tab buttons |
TabItem Props
Prop | Type | Default | Description |
---|---|---|---|
label | string | Text shown in the tab button |
Synchronized Tabs
Link multiple tab groups to switch together:
<Tabs syncKey="related-content"> <TabItem label="Overview">First group content</TabItem> <TabItem label="Details">First group details</TabItem></Tabs>
<Tabs syncKey="related-content"> <TabItem label="Overview">Second group content</TabItem> <TabItem label="Details">Second group details</TabItem></Tabs>
Custom Event Listeners
The Tabs component emits a tab-change
event when selection changes:
Waiting for events to be emitted… (Click on the tabs to see the events)
// Listen for tab changesconst tabs = document.querySelector('tabs-wrapper');tabs.addEventListener(TabsEventNames.Change, (event) => { const { id, tabId, syncKey } = event.detail; console.log(`Tab: ${tabId}, Sync Key: ${syncKey}`, id);});
Limited Time Launch Sale
Get started with our AstroJS starter template and access a complete collection of pre-built components, including these versatile Tabs!
GET 60% OFF!