Skip to content

Carousel

A swipeable content strip for featured cards, media, and step-through content. RNUI Carousel defaults to snap scrolling, edge fades, and navigation controls so the interaction remains obvious on touch devices.

import { Carousel } from '@truongdq01/ui';
import { Carousel } from '@truongdq01/ui';
const slides = [
{ id: '1', title: 'Slide One' },
{ id: '2', title: 'Slide Two' },
{ id: '3', title: 'Slide Three' },
];
export function MyCarousel() {
return (
<Carousel
data={slides}
accessibilityLabel="Featured stories"
renderItem={(item) => <MySlideCard title={item.title} />}
/>
);
}
PropTypeDefaultDescription
dataT[]requiredArray of slide data
renderItem(item: T, index: number) => ReactNoderequiredRender function for each slide
accessibilityLabelstring—Describe the carousel content for screen readers
itemWidthnumberviewportWidth of each slide
gapnumber0Space between slides
heightnumber200Carousel viewport height (ignored when autoHeight)
autoHeightbooleanfalseSize the viewport to the tallest slide (for variable-length text). Avoid percentage heights inside slides.
showPaginationbooleantrueShow pagination dots
showNavigationbooleantrueShow previous and next icon buttons
fadeEdgesbooleantrueGradient edge fades (auto-hidden in full-bleed / paged mode)
edgeColorstringsurfaceColor the edge fades blend into (match the parent background)
snapbooleantrueEnable snap offsets for slide-by-slide paging
loopbooleanfalseLoop back to the first slide
onIndexChange(index: number) => void—Called when the active slide changes after momentum stops
autoPlaybooleanfalseAuto-advance slides. Available for compatibility, discouraged by default
autoPlayIntervalnumber3000Interval in ms when autoPlay is enabled
keyExtractor(item: T, index: number) => stringindexStable React key per slide
accessibilityHintstring—Extra context for assistive technologies
<Carousel
data={stories}
accessibilityLabel="Featured stories"
renderItem={(story) => <StoryCard story={story} />}
/>
<Carousel
data={products}
accessibilityLabel="Recommended products"
itemWidth={280}
gap={16}
snap={false}
showPagination={false}
renderItem={(product) => <ProductCard product={product} />}
/>
  • Always provide accessibilityLabel because the carousel itself is an interactive region.
  • Keep snap enabled for hero or step-by-step content where one slide should be read at a time.
  • Turn snap off for lighter horizontal rails that behave more like scannable lists.
  • For a card rail, set itemWidth smaller than the viewport so the next card peeks and slides snap to center.
  • Navigation buttons and edge fades auto-hide at the first and last slide (opacity only — layout never shifts).
  • Set edgeColor to match the surface behind the carousel so fades blend seamlessly.
  • Pagination dots are tappable; users can jump straight to a slide.
  • Use autoPlay sparingly. Astryx guidance prefers user-controlled movement by default.