Skip to main content

Carousel

Horizontal carousel: touch drag (offset / velocity thresholds), autoplay (paused during hover and dragging), loop wrapping and clamped boundary modes, dots indicator (bottom / overlay) and desktop arrows. Page math fully consumes @lh-ui/share/core/carousel.

Basic usage​

Basic usage

非循环受控当前页:0(方向键 ←/→ 也可翻页)

import { LhCarousel } from '@lh-ui/react'

export default function Demo() {
return <LhCarousel items={[<div>Page 1</div>, <div>Page 2</div>]} autoplay={3000} height={160} />
}
PropDescriptionTypeOptionsDefault
valueCurrent page index (controlled; uncontrolled self-driving when omitted)number——
autoplayAutoplay interval ms (0 / omitted = off)number—0
loopWrap-aroundboolean—true
indicatorIndicator form'dots' | 'none'—'dots'
indicatorPositionIndicator position'bottom' | 'overlay'—'bottom'
heightHeight pxnumber—200
showArrowShow prev/next arrows (desktop)boolean—false
disabledDisabledboolean—false
ariaLabelAccessible name (falls back to page announcement)string——
itemsPage content array (one element per page)ReactNode[]——
onChangePage changed(value: number) => void——
sxShorthand layout propsSxProps——

Ref (LhCarouselInstance)​

MethodDescription
prev() / next()Previous / next page
goTo(index)Jump to page
Gesture thresholds

Dragging past 20% of page width or a velocity above 0.5px/ms flips the page; autoplay pauses during drag and hover, and self-stops at the last page in non-loop mode.

Accessibility

Root element role="region" + aria-roledescription="carousel", arrow keys ←/→ flip pages, non-current pages are aria-hidden; dots are buttons inside role="tablist".

Styles​

import '@lh-ui/react/style/carousel'