Accordion
A collapsible content component with hand-drawn styling, supporting controlled/uncontrolled modes, multiple selection, and comprehensive accessibility features.
Accordion
The Accordion component provides a beautifully crafted collapsible content interface with hand-drawn styling. It supports both controlled and uncontrolled modes, multiple selection, smooth animations, and comprehensive accessibility features, making it perfect for organizing content in an elegant and user-friendly way.
Features
- 🎨 Hand-drawn aesthetic - Unique visual style with slight rotations, shadows, and organic feel
- 🎛️ Flexible modes - Both controlled and uncontrolled operation
- 🔢 Multiple selection - Allow single or multiple panels to be open simultaneously
- ♿ Accessibility first - Full ARIA support and keyboard navigation
- 🎬 Smooth animations - React Spring powered expand/collapse transitions
- 🎨 Customizable styling - Multiple variants, colors, and sizes
- 📱 Responsive design - Works seamlessly across all device sizes
Installation
Usage
Colors
Accordions come in various color themes to match your design system and convey different meanings.
Sizes
Accordions are available in different sizes to fit various UI contexts and content density requirements.
Small Size
Medium Size (Default)
Large Size
Variants
The Accordion component offers multiple visual variants to suit different design contexts and aesthetic preferences.
Controlled Mode
Use controlled mode when you need to manage the accordion state externally or synchronize with other components.
Current state: none
Multiple Selection
Enable multiple accordion items to be open simultaneously for better content comparison and navigation.
Disabled States
Disable accordion items or the entire accordion to prevent interaction when needed.
Individual Item Disabled
Entire Accordion Disabled
Custom Styles
Apply custom styles using Tailwind CSS classes to create unique accordion appearances that match your design system.
Gradient Background
Heavy Shadow Effect
Custom Rotation
Accessibility
The Accordion component is built with accessibility as a first-class citizen, ensuring it works seamlessly with assistive technologies.
♿ Accessibility Features
- • ARIA Support: Full ARIA attributes for screen readers
- • Keyboard Navigation: Tab, Enter, and Space key support
- • Focus Management: Proper focus indicators and flow
- • Screen Reader: Announces state changes and content
Smooth Animations
Experience the React Spring powered animations that make the accordion feel alive and responsive.
🎬 Animation Features
- • Height Transitions: Smooth expand/collapse with measured heights
- • Opacity Fading: Content fades in and out gracefully
- • Transform Effects: Subtle scale and translate animations
- • Hardware Acceleration: GPU-optimized for smooth performance
Dark Mode Support
Accordions automatically adapt to dark mode environments with appropriate styling adjustments while maintaining the hand-drawn aesthetic.
Dark Mode Accordion Examples
Implementation Notes
- The Accordion component uses React Spring for smooth, hardware-accelerated animations
- Hand-drawn aesthetic is consistently applied across all variants and states
- All components are fully accessible with keyboard navigation and screen reader support
- The component automatically handles height measurements for smooth animations
- Custom styling can be applied while preserving the core functionality
API Reference
Accordion
The main container component that manages state and provides context to child components.
Prop | Type | Default | Description |
---|---|---|---|
value | string | string[] | undefined | Controlled value of expanded items |
defaultValue | string | string[] | undefined | Default value for uncontrolled mode |
onValueChange | (value: string | string[]) => void | undefined | Callback when value changes |
allowMultiple | boolean | false | Allow multiple items to be expanded |
isDisabled | boolean | false | Disable all accordion interactions |
color | 'primary' | 'secondary' | 'success' | 'warning' | 'danger' | 'info' | 'primary' | Color theme |
size | 'sm' | 'md' | 'lg' | 'md' | Size variant |
variant | 'solid' | 'outline' | 'ghost' | 'light' | 'flat' | 'sketchy' | 'solid' | Visual variant |
customStyles | string | undefined | Additional CSS classes |
className | string | undefined | CSS class name |
AccordionItem
Individual accordion item container.
Prop | Type | Default | Description |
---|---|---|---|
value | string | required | Unique identifier for the item |
isDisabled | boolean | false | Disable this specific item |
customStyles | string | undefined | Additional CSS classes |
className | string | undefined | CSS class name |
AccordionHeader
Clickable header that triggers expand/collapse.
Prop | Type | Default | Description |
---|---|---|---|
value | string | required | Must match parent AccordionItem value |
customStyles | string | undefined | Additional CSS classes |
className | string | undefined | CSS class name |
onClick | React.MouseEventHandler | undefined | Additional click handler |
onKeyDown | React.KeyboardEventHandler | undefined | Additional keydown handler |
AccordionContent
Collapsible content area with smooth animations.
Prop | Type | Default | Description |
---|---|---|---|
value | string | required | Must match parent AccordionItem value |
customStyles | string | undefined | Additional CSS classes |
className | string | undefined | CSS class name |
Accessibility Guidelines
ARIA Attributes
aria-expanded
: Indicates whether the accordion panel is expandedaria-controls
: Links the header to its corresponding content panelaria-labelledby
: Links the content panel to its headerrole="region"
: Identifies the content area as a landmark region
Keyboard Navigation
Key | Action |
---|---|
Tab | Move focus between accordion headers |
Enter | Toggle the focused accordion panel |
Space | Toggle the focused accordion panel |
Shift + Tab | Move focus backwards |
Best Practices
- Content Organization: Group related content logically and use clear, descriptive headers
- Performance: Consider lazy loading heavy content within accordion panels
- Responsive Design: Test accordion behavior across different screen sizes
- Content Length: Avoid extremely long content that might cause performance issues
- State Management: Use controlled mode when accordion state needs to sync with other components