Skip to component
GGamma

Snap carousel

A scroll-snap card rail with pointer, keyboard, and dot navigation.

New
Live previewUse keyboard to interact

Implementation

1"use client";2 3import {4  useEffect,5  useRef,6  useState,7  type HTMLAttributes,8  type KeyboardEvent,9  type ReactNode,10} from "react";11import { ChevronLeft, ChevronRight } from "lucide-react";12 13export type SnapCarouselSlide = {14  id: string;15  /** Accessible name for this slide. */16  label: string;17  content: ReactNode;18};19 20export type SnapCarouselProps = Omit<21  HTMLAttributes<HTMLElement>,22  "children" | "onChange"23> & {24  slides: SnapCarouselSlide[];25  /** Accessible name for the carousel. */26  label?: string;27  index?: number;28  defaultIndex?: number;