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
import { Slider } from "@codeui/solid";
export default function Demo() {
return (
<Slider
label="Background opacity"
defaultValue={75}
showValue
description="Adjust the exported background."
/>
);
}Anatomy
Tap a part to outline it in the demo.
- 01Root
sliderclasses.root - 02Label
slider-labelclasses.label - 03Description
slider-descriptionclasses.description - 04ErrorMessage
slider-error-messageclasses.errorMessage - 05Track
slider-trackclasses.track - 06Fill
slider-fillclasses.fill - 07Thumb
slider-thumbclasses.thumb - 08Input
slider-inputclasses.input - 09ValueLabel
slider-value-labelclasses.valueLabel
| Export | Renders | classes key | data-cui | Role |
|---|---|---|---|---|
Root | div | root | slider | none |
Label | label | label | slider-label | none |
Description | div | description | slider-description | none |
ErrorMessage | div | errorMessage | slider-error-message | none |
Track | div | track | slider-track | none |
Fill | div | fill | slider-fill | none |
Thumb | span | thumb | slider-thumb | slider |
Input | input | input | slider-input | none |
ValueLabel | div | valueLabel | slider-value-label | none |
Variants
import { Slider } from "@codeui/solid";
export default function Demo() {
return (
<Slider
label="Background opacity"
defaultValue={75}
showValue
orientation="vertical"
/>
);
}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
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()}`}
/>
);
}import { Slider } from "@codeui/solid";
export default function Demo() {
return <Slider label="Background opacity" defaultValue={75} showValue disabled />;
}import { Slider } from "@codeui/solid";
export default function Demo() {
return <Slider label="Background opacity" defaultValue={75} showValue readOnly />;
}import { Slider } from "@codeui/solid";
export default function Demo() {
return <Slider label="Background opacity" defaultValue={75} showValue required />;
}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
| Key | Action |
|---|---|
| Tab | Focus the thumb. |
| Right Arrow, Up Arrow | Increase by one step in the default direction. |
| Left Arrow, Down Arrow | Decrease by one step in the default direction. |
| Page Up, Page Down | Increase or decrease by one tenth of the range, snapped to step and at least one step. |
| Shift + Arrow key | Change by the page step. |
| Home, End | Set 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
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.
Related
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.