SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

carouselSync

Runs the Carousel it sits in from a hidden host anywhere inside the carousel root.

tsx
import { carouselSync } from "@sdxc/ui/mixins";
View code
tsx
<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

typescript
carouselSync(): MixinDescriptor<HTMLElement>

Examples

tsx
<span hidden mix={[carouselSync()]} />

The events, constants and types its module publishes, each imported from @sdxc/ui/mixins too.

Constant

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.

typescript
const CAROUSEL_SLIDE_ATTRIBUTE = "data-carousel-slide"
Constant

Set on a Carousel root once carouselSync runs it, for controls that need script.

typescript
const CAROUSEL_READY_ATTRIBUTE = "data-carousel-ready"
@sdxc/ui

Can’t find it? Contact us