Carousel

Customizable image and content slider

A flexible and accessible Carousel component that creates responsive and customizable content sliders with various features and controls.

VersionLicenseDownloadsBundle Size (minified)Bundle Size (minified + gzip)

Overview

This comprehensive documentation provides detailed instructions on how to leverage the powerful Carousel component in your React projects. The Carousel component is a core element of the abaabil.carousel library, designed to enhance content presentation and user interactions in your user interfaces.

import Carousel from 'abaabil.carousel';

Key Features

Discover why Abaabil's Carousel component stands out:

  • Fully accessible with ARIA attributes and keyboard navigation
  • Customizable appearance with support for different orientations and slide counts
  • Auto-scrolling with pause on hover
  • Touch swipe support for mobile devices
  • Customizable controls and indicators

Usage Example

The Carousel component can be used in your JSX to create content sliders with various properties. You can customize the carousel by setting its properties such as items, direction, autoScrollInterval, infiniteLoop, slidesToShow, and more. The following example demonstrates how to use the Carousel component in your JSX-based projects.

Customization

The Carousel component offers a wide range of customization options to tailor the appearance and behavior of your content sliders. You can customize the carousel by setting its properties such as showControls, showIndicators, and more. The following example demonstrates how to customize the Carousel component in your React projects.

Vertical Carousel

The Carousel component supports both horizontal and vertical orientations. You can create a vertical carousel by setting the direction property to 'vertical'. The following example demonstrates how to create a vertical carousel in your React projects.

Multiple Slides

The Carousel component allows you to display multiple slides at once. You can set the number of slides to show using the slidesToShow property. The following example demonstrates how to display multiple slides in your content slider.

Custom Content

The Carousel component allows you to display custom content within each slide. You can pass any React element as a child to the Carousel component to create unique slide content. The following example demonstrates how to use custom content in your content slider.

Properties

The Carousel component accepts the following properties:

items

Type: Array

Description: An array of React elements to be displayed in the carousel.

direction

Type: string

Description: The orientation of the carousel. Can be 'horizontal' or 'vertical'.

autoScrollInterval

Type: number

Description: The interval (in milliseconds) between auto-scrolls. Set to 0 to disable auto-scroll.

infiniteLoop

Type: boolean

Description: Whether the carousel should loop infinitely.

slidesToShow

Type: number

Description: The number of slides to show at once.

showControls

Type: boolean

Description: Whether to show navigation controls.

showIndicators

Type: boolean

Description: Whether to show slide indicators.

Accessibility

The Carousel component is designed with accessibility as a top priority:

  • Proper ARIA attributes for roles, states, and properties
  • Keyboard navigation support for moving between slides
  • Focus management for improved user experience
  • Screen reader announcements for slide changes

Keyboard Interactions

The Carousel supports the following keyboard interactions:

  • Left Arrow / Up Arrow: Move to the previous slide
  • Right Arrow / Down Arrow: Move to the next slide
  • Home: Move to the first slide
  • End: Move to the last slide

Styling

The Carousel component comes with default styling and offers customization options:

  • Uses Tailwind CSS classes for consistent styling
  • Customizable container, controls, and indicators through className props
  • Responsive design with proper spacing and sizing
  • Support for both horizontal and vertical orientations

Best Practices

Follow these best practices when using the Carousel component:

  • Use appropriate alt text for images within carousel items
  • Avoid using too many slides, which can overwhelm users
  • Ensure that important content is not solely presented in the carousel
  • Consider using a pause button for auto-scrolling carousels

Performance Considerations

The Carousel component is optimized for performance:

  • Uses React hooks for efficient state management
  • Implements lazy rendering to avoid unnecessary DOM updates
  • Optimized touch event handling for smooth mobile interactions

Browser Compatibility

The Carousel component is compatible with modern browsers:

  • Chrome 60+
  • Firefox 55+
  • Safari 10+
  • Edge 15+
  • Opera 47+

Troubleshooting

Common issues and solutions when using the Carousel component:

  • If auto-scrolling doesn't work, check if the autoScrollInterval prop is set correctly
  • For styling issues, ensure Tailwind CSS is properly configured in your project
  • If touch interactions are not working on mobile, verify that the component is not nested inside other touch-sensitive elements

Resources

Additional resources for working with the Carousel component: