Forms & Input
Slider
Slider lets users pick numeric values from a range with modern visual feedback. Make the expected input clear before someone interacts, and keep the current value, help text and validation feedback connected. Import it from @/components/kamod-ui/slider.
Source · Design reference · API reference · Theming · Styles
Interactive preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthInstallation
Import Slider from @/components/kamod-ui/slider. The live preview below matches the kitchen sink default (single thumb, shadcn-style array defaultValue).
pnpm add @kamod-ch/uiCopy an example with @kamod-ch/ui or the matching @kamod-ch/ui/… subpath. The code block switches between those two installs. Connect The Global Theme CSS and Tailwind Source Detection before your first render.
Interactive preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthUsage
Pass defaultValue or value as a number or array (one thumb per entry). Use onValueChange for controlled updates.
import { Slider } from "@kamod-ch/ui";Choose a complete composition from the examples below; required child components and props vary by pattern.
Component Examples & Variants
Explore Slider in Different Contexts, from the starting pattern to the compositions below. Begin with Basic (Shadcn-Style Array), then compare the examples that match your content, state and layout. These are working patterns to adapt, not a list of interchangeable variant values: check the API Reference before using a prop or combining behaviors. Look at the surrounding labels, supporting text and spacing as well as the component itself.
Read the Result and Its Implementation Together. Use each showcase’s Code view to inspect imports and composition, or its Prompt view to prepare a setup or adaptation brief. Try the narrow preview and local theme controls before connecting real data, and use Reset to return an example to its initial state. Keep layout changes in class utilities where appropriate; follow the Component Styles Guide for hierarchy and the Theming Guide for shared surfaces and colors. The Accessibility Notes explain what to preserve when making those changes.
Basic (Shadcn-Style Array)
Expose a Value that Users Can Understand. Use an array containing one number for a single-thumb Slider, such as defaultValue={[50]}. The shared array-based value model also supports range and multi-thumb examples, so the control's data shape stays consistent as the pattern grows.
Provide an accessible name and a visible value with units, and choose bounds that match the actual setting rather than the demonstration's arbitrary scale.
import { Slider } from "@kamod-ch/ui";
export const Example = () => (
<div class="docs-slider-demo !p-3 w-full max-w-md">
<p class="docs-slider-demo-label !mb-2">Basic</p>
<Slider defaultValue={[33]} max={100} step={1} class="w-full" />
</div>
);Range
Explain the Lower and Upper Bounds Separately. Pass two values to represent the lower and upper bounds of a range. The filled track between the thumbs visualizes that interval, while nearby labels should explain the units and the meaning of both boundaries.
Give each endpoint a meaningful name, show the current interval in text and decide how the application handles adjacent or equal values before connecting the control to filtering or pricing logic.
Interactive preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthMultiple Thumbs
Use Several Handles Only When Their Roles Are Clear. Supply three or more values when the task needs several positions on one scale. Each thumb represents an entry in the array, so the surrounding explanation must distinguish their roles instead of presenting an ambiguous collection of handles.
Label the values distinctly, keep the ordering rules explicit and offer another input method when precise adjustments become difficult.
Interactive preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthStepped
Make Each Increment Meaningful. Set step to restrict the slider to meaningful increments rather than every possible point on the scale. Align the step with the units shown to users so the displayed value and allowed adjustments describe the same precision.
Show the current value, check the relationship between minimum, maximum and step, and verify keyboard adjustments alongside pointer dragging.
Interactive preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthControlled (Single)
Keep the Setting Synchronized with External State. Pass a state-backed value array and update it through onValueChange for a controlled slider. Even one thumb produces a number[], allowing another control or readout to share exactly the same selected value.
Avoid firing expensive work for every drag update without considering the workflow, and distinguish live preview from committing a persisted preference.
Interactive preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthControlled (Range)
Keep Fractional Endpoints Readable. Control both range values in parent state and choose a fractional step when the measurement requires finer precision. The two thumbs describe one interval, so supporting readouts should use the same units and rounding conventions.
Test the smallest and largest permitted intervals, including adjustments made with the keyboard. Check the submitted numbers against the displayed endpoints so formatting does not silently change the measurement the user chose.
Interactive preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthDisabled
Explain Why the Value Cannot Change. Set disabled on a single or range slider when its value is temporarily unavailable for editing. Keep the current position and explanation visible so the interface communicates the setting even while interaction is blocked.
Place prerequisites outside the control and restore the appropriate state when they are met; disabled appearance should not be the only explanation.
Interactive preview
Preact example Local preview theme · Responsive styles follow the preview widthFull widthProps and Data
Configure Slider using the contracts below. Read the documented options alongside the Source Definitions to understand which values your application supplies and which details the component owns. Start with a prop or helper, then follow its type link to inspect the declaration without leaving the page.
Props, slots and variants for this component.
Type cards are extracted from this checkout’s TypeScript source at build time. Props inherited through HTMLAttributes, Omit or variant helpers remain references in those declarations; their fields are not flattened here. Match the reference to your installed version, and check a package’s exports before writing an import type. A type exported by a source file is not necessarily re-exported by @kamod-ch/ui.
Component Props
? means a field can be omitted; it does not promise a fallback value. Existing documented defaults remain alongside the descriptions. For callbacks, check the argument and return types before connecting your own state or services.Slider
SliderProps
| Prop / type | Description |
|---|---|
class | Configure
|
defaultValue | Configure
|
disabled | Configure
|
id | Configure
|
max | Configure
|
min | Configure
|
onChange | Configure
|
onInput | Configure
|
onPointerDown | Configure
|
onValueChange | Called with the current thumb values (always a sorted array, length ≥ 1). Matches shadcn/Radix-style callbacks.
|
onValueCommit | Fires when the user finishes a drag or commits via keyboard (native `change` event). Matches Radix `onValueCommit`.
|
orientation | Configure
|
step | Configure
|
style | Configure
|
value | Configure
|
Data Type Reference
Expand a card to inspect and copy the exact declaration. The code header identifies its repository file; follow imported or inherited types in the Implementation Source when you need the complete dependency chain. Required-field summaries cover fields declared directly in that type. Source-only helpers and inferred schema outputs describe the local implementation, not additional props you can pass to every component.
SliderPrimitiveValue
DeclarationSliderPrimitiveValueSlider.tsx. Referenced types retain their original names; inspect that file for imports and supporting definitions. Inspect the Complete Definition of SliderPrimitiveValue before adapting it.Slider Props
6 declared fieldsSliderPropsSlider.tsx. Referenced types retain their original names; inspect that file for imports and supporting definitions. Inspect the Complete Definition of SliderProps before adapting it.Accessibility
Build the Complete Interaction, Including the Parts Outside Slider. The notes below distinguish the current implementation from the labels, content and behavior your application supplies. Start with the Live Preview, check the Props and Data Reference, and test the finished composition with real content rather than assuming that an unchanged visual example covers every use case.
Built-in Behavior and Defaults
Slider uses native range inputs. A range configuration renders multiple inputs with generated names such as Value 1 of 2. In the multi-thumb path, extra input attributes are spread only onto the first thumb; generic defaults are not meaningful minimum/maximum labels.
Labels and Relationships
For a single slider, prefer a visible label referenced with aria-labelledby. Explain units and the permitted range beside it. Inspect the generated inputs when using multiple thumbs: a label on the root group does not individually name the lower and upper bounds.
Keyboard and Focus
Retain native range keyboard operation and test step, bounds and orientation in supported browsers. Offer a numeric input alternative when precise values matter. Do not make dragging the only practical way to reach a permitted value.
States and Integration Details
The current multi-thumb implementation has limited per-thumb attribute customization, and its generated aria-label follows the spread attributes. Do not assume an aria-label prop renames every thumb. Verify or extend the implementation before using ambiguous bounds in production.
Verify the Complete Interaction
Check Behavior as Well as Markup. Work through these scenarios in the application where the component will be used. Automated checks can help find structural problems; also review the reading experience with a screen reader, keyboard focus and the actual feedback from your application.
- Adjust each thumb without a pointer and confirm its value and units are understandable.
- Try minimum, maximum and adjacent values; verify that constraints are explained rather than silently surprising.
- Inspect focus visibility and each thumb's computed name after applying custom classes or orientation.
Recheck the result after changing Theme Tokens, translations or class overrides. Include text enlargement, narrow layouts and reduced-motion settings where animation is present. Inspect the Component Source when a behavior differs from your expectation; a role or state attribute does not implement keyboard interaction by itself.
For background, read the WAI-ARIA Authoring Guidance and Keyboard Interface Guidance. These explain the patterns; verify browser and assistive-technology behavior for the implementation and audience you actually support.
You have the pieces. Put them into one real interaction, keep its state in one place, and check the result with the content your application will actually show.
Connect the Foundation
Return to Choose and Compose Components to connect this reference to a working screen. Keep global CSS in one entrypoint and import only the components that screen needs.
Build the Surrounding Screen
Find a neighboring interaction in the Component Library, or start with a complete Block. Replace sample content and destinations before refining the layout; a local class change can stay with the composition.
Make the Result Hold Up
Use shared theme roles for changes that belong everywhere. Then review the whole journey: keyboard focus, long labels, narrow screens and a clear way to recover when something fails.
Keep a link to the source and note your intentional changes. Your next edit should begin with a clear decision, not another search.