CLI
手动安装
CLI 将组件源(及其内部依赖项)复制到您的项目中并安装任何所需的 npm 包。
npx boardui@latest add carousel使用共享 UI 包或自定义导入别名? 配置您的安装路径 在运行 CLI 之前。复制粘贴示例使用默认导入。
卡片宽度
默认情况下,每个项目都会填充轨道,因此每张幻灯片只能看到一张卡片。宽度继续存在 CarouselItem 而不是在轨道上,因此覆盖它可以看到下一张卡或一系列混合宽度。位置是从 DOM 读回的,而不是根据固定的卡片宽度计算的,因此不需要告知这些宽度何时发生变化。
{/* One card per slide is the default: items fill the track */}<CarouselItem>…</CarouselItem>
{/* Override to show a peek of the next card, or to mix widths */}<CarouselItem className="w-[85%]">…</CarouselItem><CarouselItem className="w-[220px]">…</CarouselItem>对齐和控制
align="center" 将每张卡片放置在轨道的中间而不是左边缘,这适合看到一张英雄卡片的画廊。 showArrows 和 showDots 将镀铬物剥离回裸露的可滑动轨道,并且 gap 设置像素间距。
{/* Snap each card to the middle of the track */}<Carousel aria-label="Gallery" align="center" gap={24}>…</Carousel>
{/* Bare track: no arrows, no dots, swipe only */}<Carousel aria-label="Logos" showArrows={false} showDots={false}>…</Carousel>无障碍
该地区宣称自己是一个旋转木马,并得名于 aria-label,这是必需的。每张卡片都标有其位置,因此屏幕阅读器会读取“7 中的 3”,而无需您进行任何编号。轨道是可聚焦的,因此箭头键可以滚动它,上一个/下一个按钮在末尾禁用,而不是默默地不执行任何操作。滑动尊重 prefers-reduced-motion,跳跃而不是动画。






