carousel

onChange called 0 time(s)

import { carousel, lucide } from '@markless/ui';export default function CarouselBasic() @{	<carousel.root class="carousel" value="paris">		<carousel.title class="title">Featured destinations</carousel.title>		<div class="frame">			<carousel.backtrigger class="step">				<lucide.chevronleft class="step-icon" aria-hidden="true" />			</carousel.backtrigger>			<carousel.scrollarea class="window">				<carousel.item class="slide" value="paris">					<span class="slide-name">Paris</span>					<span class="slide-note">Cafés and long walks</span>				</carousel.item>				<carousel.item class="slide" value="oslo">					<span class="slide-name">Oslo</span>					<span class="slide-note">Fjords and wooden houses</span>				</carousel.item>				<carousel.item class="slide" value="lima">					<span class="slide-name">Lima</span>					<span class="slide-note">Cliffs above the Pacific</span>				</carousel.item>			</carousel.scrollarea>			<carousel.forwardtrigger class="step">				<lucide.chevronright class="step-icon" aria-hidden="true" />			</carousel.forwardtrigger>		</div>		<carousel.navlist class="dots" aria-label="Choose a destination">			<carousel.navtrigger class="dot" value="paris" aria-label="Paris" />			<carousel.navtrigger class="dot" value="oslo" aria-label="Oslo" />			<carousel.navtrigger class="dot" value="lima" aria-label="Lima" />		</carousel.navlist>	</carousel.root>;}

A carousel shows one slide at a time, with buttons to step through the rest. Use it for a row of featured items that share one spot on the page.

Each slide has a name, its value. The root's value names the slide that is showing. Nothing counts positions, so you always name a slide, never number it.

Anatomy

carousel anatomy
Anatomy perspectiveFlat
Layers
A few good momentsThe little thingsNextPause
carousel.root

The carousel itself; the scroll area, slides, nav list and triggers go inside it.

The back and forward triggers step one slide. Set move on the root to step more, or set move="view" to step a whole window of slides.

Add a carousel.navlist with one carousel.navtrigger per slide to get a row of slide pickers. Then the pickers are tabs and the slides are tab panels. Without the nav list, each slide is a group that screen readers call a "slide".

Keyboard

The back, forward and play triggers are plain buttons, so Tab, Enter and Space work as usual. The pickers in a nav list share one Tab stop.

Key What it does
Left or Right arrow Show the previous or next slide and focus its picker.
Up or Down arrow The same, in place of Left and Right, when orientation="vertical".
Home or End Show the first or the last slide.

Focusing a picker shows its slide. At either end the arrows stop. Set loop or rewind to make the ends come round.

Autoplay

carousel.playtrigger starts and stops the slides moving on their own. Its screen reader label says what the next press will do.

The rotation stops for good when focus moves inside the carousel. It pauses while the pointer is over the carousel and starts again when the pointer leaves. While it runs, the root sets aria-live="off", so a screen reader does not read every slide.

If the reader's system asks for reduced motion, the play trigger refuses to start. It gets aria-disabled="true" and ui-reduced-motion, so you can show why.

Styling

The family ships no CSS, so an unstyled carousel is a stack of slides. The scroll area renders two elements. The outer one gets your props, and it is the window. Give it a size and overflow: hidden. The inner one carries ui-track, and the family moves it with a transform. Give it display: flex.

A vertical carousel needs a fixed height on the window. Without one, the window grows to fit every slide, and there is nothing left to step to.

Attribute On When
ui-active item, navtrigger This slide is the one showing.
ui-value item, navtrigger Always. It holds the slide's value.
ui-vertical root, scrollarea, the track orientation="vertical".
ui-loop root loop is set. rewind does not set it.
ui-draggable scrollarea Dragging is on. It is on unless you set draggable={false}.
ui-align scrollarea Always. It holds start, center or end.
ui-track The track inside scrollarea Always.
ui-reduced-motion root, playtrigger A press on play was refused for reduced motion.

mousewheel lets the wheel step the slides. The family does not cancel the wheel event, so the page can scroll at the same time.

Prop Type What it does
value string The slide showing now, named by its value.
orientation 'horizontal' | 'vertical' The axis the slides run along. The default is horizontal.
align 'start' | 'center' | 'end' Where a slide rests in the window. The default is start.
move number | 'view' How far one back or forward press goes. The default is 1.
loop boolean Stepping past either end comes round to the other end.
rewind boolean Stepping past either end comes round to the other end. It does not set ui-loop.
draggable boolean A drag moves the slides. The default is true.
mousewheel boolean The wheel steps the slides. The default is false.
autoplay boolean The rotation state the root renders with. It starts no timer.
autoplayInterval number Milliseconds per slide while the rotation runs. The default is 3000.
sensitivity { mouse?: number; touch?: number } How far a drag moves the slides. The defaults are 1.5 and 1.25.
onChange (value: string) => void Called with the new value when the showing slide changes.

Every other prop goes on the root <div>. carousel.item and carousel.navtrigger each need a value.