Interactive Tabs Component
A fully accessible, customizable tabs component with smooth animations and keyboard navigation
Default Style Tabs
Interactive Tabs Component
This is a fully accessible tabs component built with modern web standards. It includes:
- Full keyboard navigation
- ARIA compliance
- Smooth animations
- Multiple style variants
- Responsive design
Key Features
🎯 Accessibility First
Built with WCAG 2.1 guidelines in mind, including proper ARIA attributes and keyboard navigation.
⚡ Performance Optimized
Lightweight implementation with efficient event handling and minimal DOM manipulation.
🎨 Customizable
Multiple style variants and easy theming with CSS custom properties.
📱 Responsive
Works seamlessly across all device sizes and orientations.
Usage Example
---
import TabsComponent from '../components/TabsComponent.astro';
const tabs = [
{
id: 'tab1',
label: 'First Tab',
content: '<p>Content for first tab</p>'
},
{
id: 'tab2',
label: 'Second Tab',
content: '<p>Content for second tab</p>'
}
];
---
<TabsComponent
tabs={tabs}
variant="pills"
orientation="horizontal"
/>
The component automatically handles all accessibility features, keyboard navigation, and state management.
Component API
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| tabs | Tab[] | required | Array of tab objects |
| variant | 'default' | 'pills' | 'underline' | 'default' | Visual style variant |
| orientation | 'horizontal' | 'vertical' | 'horizontal' | Tab layout orientation |
| defaultTab | string | first tab id | Initially active tab |
Methods
activateTabById(tabId: string): boolean
Programmatically activate a tab
disableTab(tabId: string): void
Disable a specific tab
enableTab(tabId: string): void
Enable a specific tab
Pills Style Tabs
Design Principles
The pills variant provides a modern, button-like appearance that works well in compact spaces.
Visual Hierarchy
Clear distinction between active and inactive states
User Experience
Intuitive interaction patterns
Technical Implementation
Built with semantic HTML and progressive enhancement in mind.
- ✅ Works without JavaScript
- ✅ Enhanced with smooth transitions
- ✅ Keyboard accessible
- ✅ Screen reader friendly
Accessibility Testing
Thoroughly tested with various assistive technologies and automated tools.
Vertical Orientation
Vertical Layout
Perfect for forms, settings panels, or when you have many tabs to display. The vertical orientation provides better space utilization on wider screens.
Responsive Behavior
The vertical layout automatically adapts to different screen sizes:
- 📱 Collapses to horizontal on mobile
- 💻 Maintains vertical layout on tablets
- 🖥️ Full vertical layout on desktops
Key Features & Benefits
Accessibility First
Full WCAG 2.1 compliance with proper ARIA attributes and keyboard navigation
High Performance
Lightweight implementation with smooth CSS transitions and minimal JavaScript
Fully Customizable
Multiple style variants and easy theming with CSS custom properties
Responsive Design
Works seamlessly across all device sizes and orientations
Developer Friendly
Simple API with TypeScript support and comprehensive documentation
Progressive Enhancement
Works without JavaScript and enhances with smooth interactions
How to Use
Quick Start
- Import the TabsComponent into your Astro page
- Define your tabs data with id, label, and content
- Add the component with your preferred variant and orientation
- Customize the styling to match your design system
Keyboard Navigation
The component supports full keyboard navigation:
- Arrow Keys: Navigate between tabs
- Enter/Space: Activate focused tab
- Home/End: Jump to first/last tab
- Tab: Move focus to tab panel content