Skip to Content
CodeUI

Slider

@codeui/solid v0.3.0

A thumb on a track for choosing a number in a range.

When to use

Choose a numeric value in a useful range, such as background opacity.

When to choose another component

Use NumberField when you need an exact typed value. Pair a slider with a number field when both input methods are useful.

Live demo

75
Adjust the exported background.
slider/basic.tsx
import { Slider } from "@codeui/solid";
export default function Demo() {
	return (
		<Slider
			label="Background opacity"
			defaultValue={75}
			showValue
			description="Adjust the exported background."
		/>
	);
}

Anatomy

75
Applies to the exported image.

Tap a part to outline it in the demo.

  1. 01Rootsliderclasses.root
  2. 02Labelslider-labelclasses.label
  3. 03Descriptionslider-descriptionclasses.description
  4. 04ErrorMessageslider-error-messageclasses.errorMessage
  5. 05Trackslider-trackclasses.track
  6. 06Fillslider-fillclasses.fill
  7. 07Thumbslider-thumbclasses.thumb
  8. 08Inputslider-inputclasses.input
  9. 09ValueLabelslider-value-labelclasses.valueLabel
ExportRendersclasses keydata-cuiRole
Rootdivrootslidernone
Labellabellabelslider-labelnone
Descriptiondivdescriptionslider-descriptionnone
ErrorMessagediverrorMessageslider-error-messagenone
Trackdivtrackslider-tracknone
Filldivfillslider-fillnone
Thumbspanthumbslider-thumbslider
Inputinputinputslider-inputnone
ValueLabeldivvalueLabelslider-value-labelnone

Variants

75
slider/vertical.tsx
import { Slider } from "@codeui/solid";
export default function Demo() {
	return (
		<Slider
			label="Background opacity"
			defaultValue={75}
			showValue
			orientation="vertical"
		/>
	);
}
75 percent opacity
slider/value-label.tsx
import { Slider } from "@codeui/solid";
export default function Demo() {
	return (
		<Slider
			label="Background opacity"
			defaultValue={0.75}
			minValue={0}
			maxValue={1}
			step={0.01}
			showValue
			getValueLabel={({ values }) => `${Math.round(values[0] * 100)} percent opacity`}
		/>
	);
}

The track is a 2px line in --cui-border-divider with the filled part in --cui-action-brand-base. The thumb is a 12px white dot with a 1px divider border and --cui-shadow-lg, as CodeImage draws its range thumb, so it keeps an edge on a light surface. Its hit area stays 28px, 40px on a touch screen. Set data-orientation="vertical" on a custom track and fill.

States

75
Last committed value: 75
slider/controlled.tsx
import { Slider } from "@codeui/solid";
import { createSignal } from "solid-js";
export default function Demo() {
	const [value, setValue] = createSignal(75);
	const [committed, setCommitted] = createSignal(75);
	return (
		<Slider
			label="Background opacity"
			value={value()}
			onChange={setValue}
			onChangeEnd={setCommitted}
			showValue
			description={`Last committed value: ${committed()}`}
		/>
	);
}
75
slider/disabled.tsx
import { Slider } from "@codeui/solid";
export default function Demo() {
	return <Slider label="Background opacity" defaultValue={75} showValue disabled />;
}
75
slider/read-only.tsx
import { Slider } from "@codeui/solid";
export default function Demo() {
	return <Slider label="Background opacity" defaultValue={75} showValue readOnly />;
}
75
slider/required.tsx
import { Slider } from "@codeui/solid";
export default function Demo() {
	return <Slider label="Background opacity" defaultValue={75} showValue required />;
}
75
slider/invalid.tsx
import { Slider } from "@codeui/solid";
export default function Demo() {
	return (
		<Slider
			label="Background opacity"
			defaultValue={75}
			showValue
			validationState="invalid"
			errorMessage="Choose a background opacity."
		/>
	);
}

Ready API

Slider

Renders the complete field. SliderProps is the public props type.

Prop

Type

Prop

Type

Inherited behavior follows the Kobalte slider contract.

Styled parts API

Import the parts from @codeui/solid/slider/parts.

Description

Wraps Kobalte Slider.Description with kit styles.

Prop

Type

ErrorMessage

Wraps Kobalte Slider.ErrorMessage with kit styles.

Prop

Type

Fill

Wraps Kobalte Slider.Fill with kit styles.

Prop

Type

Input

Wraps Kobalte Slider.Input with kit styles.

Prop

Type

Label

Wraps Kobalte Slider.Label with kit styles.

Prop

Type

Root

Wraps Kobalte Slider.Root with kit styles.

Prop

Type

Prop

Type

Thumb

Wraps Kobalte Slider.Thumb with kit styles.

Prop

Type

Track

Wraps Kobalte Slider.Track with kit styles.

Prop

Type

useSliderContext

Reads the Kobalte context inside its Root. Call it from a descendant component. It exposes reactive field state and throws outside the provider.

ValueLabel

Wraps Kobalte Slider.ValueLabel with kit styles.

Prop

Type

Styles export

sliderStyles

sliderStyles maps each part name to a function that returns its class. Set data-orientation="vertical" on custom track and fill elements for a vertical slider. SliderStyles types the map and SliderParts exposes the Solid components.

Accessibility

Keyboard

KeyAction
TabFocus the thumb.
Right Arrow, Up ArrowIncrease by one step in the default direction.
Left Arrow, Down ArrowDecrease by one step in the default direction.
Page Up, Page DownIncrease or decrease by one tenth of the range, snapped to step and at least one step.
Shift + Arrow keyChange by the page step.
Home, EndSet the minimum or maximum value.

ARIA

The thumb has role="slider", aria-valuemin, aria-valuemax, aria-valuenow, and aria-valuetext. getValueLabel formats both the visible value and the spoken value. Orientation and direction affect arrow behavior. The ready API takes scalar numbers. Styled Root takes arrays for multiple thumbs. Description and error components associate hint text with the field. validationState="invalid" exposes invalid state. Supply a visible label or an accessible name.

Focus

These controls do not open an overlay or move focus on mount. Disabled controls cannot receive keyboard focus. Read-only controls remain focusable and do not change value.

SSR notes

The root, labels, controls, and form inputs render on the server. No part uses a portal. Keep initial values and component order stable between server and client so generated IDs hydrate consistently. Create signals per component instance.

Theming hooks

The component reads these foundation variables. Shared field labels and messages also use the field typography and validation tokens.

--cui-action-brand-base, --cui-action-brand-text, --cui-border-divider, --cui-border-width, --cui-shadow-lg, --cui-focus-color, --cui-focus-offset, --cui-focus-width, --cui-font-size-caption, --cui-font-size-xs, --cui-font-line-height-caption, --cui-font-line-height-xs, --cui-radius-full, --cui-space-0-5, --cui-space-2, --cui-space-3, --cui-space-32, --cui-text-danger, --cui-text-default, --cui-text-hint, --cui-text-label.

Composition examples

75
slider/form.tsx
import { Slider, Button } from "@codeui/solid";
import { createSignal, For } from "solid-js";
export default function Demo() {
	const [result, setResult] = createSignal("");
	return (
		<form
			onSubmit={event => {
				event.preventDefault();
				setResult(
					new FormData(event.currentTarget).get("opacity")?.toString() ?? "omitted",
				);
			}}
		>
			<Slider label="Opacity" name="opacity" defaultValue={75} showValue />
			<Button type="submit">Inspect form value</Button>
			<output>{result()}</output>
		</form>
	);
}

The form demo reads the submitted value with FormData. The named input submits the numeric value as a string.

Use NumberField when you need an exact typed value. Pair a slider with a number field when both input methods are useful. See Control helpers for custom compositions.

On this page