carouselSync
Runs the Carousel it sits in from a hidden host anywhere inside the carousel root.
import { carouselSync } from "@sdxc/ui/mixins";View code
<Carousel aria-label="Rooms" style={{ "--ui-carousel-slide-size": "100%" }}>
<Carousel.Viewport id="rooms">
<Carousel.Track>
{rooms.map((room) => (
<Carousel.Slide data-carousel-slide aria-label={room.title}>…</Carousel.Slide>
))}
</Carousel.Track>
</Carousel.Viewport>
<Carousel.Controls>
<Carousel.Previous commandfor="rooms" aria-label="Previous room" />
<Carousel.Next commandfor="rooms" aria-label="Next room" />
</Carousel.Controls>
{/* One hidden host runs the whole carousel with carouselSync(). */}
<CarouselSync />
</Carousel>Usage
Runs the Carousel it sits in from a hidden host anywhere inside the carousel root, so a
server-rendered carousel gets the same command handling, arrow and dot state and n / N
counts as carouselControls without the page writing an island around its viewport.
It marks the root with CAROUSEL_READY_ATTRIBUTE while it runs.
Signature
carouselSync(): MixinDescriptor<HTMLElement>Examples
<span hidden mix={[carouselSync()]} />Used with it
The events, constants and types its module publishes, each imported from @sdxc/ui/mixins too.
CAROUSEL_SLIDE_ATTRIBUTE
Attribute every Carousel slide exposes itself on. carouselControls
queries every element carrying this attribute beneath the viewport, in
document order, to resolve the slide a --ui-goto command targets.
const CAROUSEL_SLIDE_ATTRIBUTE = "data-carousel-slide"CAROUSEL_READY_ATTRIBUTE
Set on a Carousel root once carouselSync runs it, for controls that need script.
const CAROUSEL_READY_ATTRIBUTE = "data-carousel-ready"