Pick a value or a range by dragging or with the keyboard: steps, marks, a value bubble and Field-style label.
Used for
- Temperature setting
- Token limit
- Price range
- Confidence threshold
Examples
Installation
npx knowns-ui@latest add sliderFor Claude Code, Cursor or Codex: installs it and wires the props to your own data.
Paste this into your coding agent (Claude Code, Cursor, Codex). It checks your project, sets up the registry, runs the install and verifies it.
Install prompt
Install Slider from Knowns UI into this project. Work step by step, show me each change, and ask before you edit files outside this project.
Context: Knowns UI (https://ui.knowns.dev) is a shadcn registry. Items land in the project as source files. Docs: https://ui.knowns.dev/docs/slider
1. Check the project first. Stop and tell me if any of these is missing:
- React 19 and Tailwind CSS v4.
- A components.json at the project root. If there is none, ask me before running `npx knowns-ui@latest init --no-key` (it runs shadcn init when needed, then adds the registries).
2. Run:
```bash
npx knowns-ui@latest add slider
```
It writes these files:
- lib/knowns/run.ts
- lib/knowns/json.tsx
- lib/knowns/status.ts
- lib/knowns/tone.ts
- lib/knowns/types.ts
- lib/knowns/use-abortable.ts
- lib/knowns/utils.ts
- lib/knowns/motion.tsx
- lib/knowns/motion-utils.ts
- components/ui/knowns/slider.tsx
and installs these npm packages: clsx@^2.1.1, tailwind-merge@^3.7.0.
3. While it runs:
- It also adds a few @keyframes (all named kn-*) to the global CSS file (globals.css or the file components.json points at). Let it: they only add animations.
- If it asks to overwrite files under lib/knowns/: these are shared by every Knowns UI item. List them, say whether I changed them (check git), and ask me before you answer.
- If it asks to overwrite any other file, show me the diff and ask me.
4. Verify:
- Every file in the list above exists.
- The project type-checks (for example `npx tsc --noEmit`) and the dev build has no new errors.
5. Use it: follow the examples and props on https://ui.knowns.dev/docs/slider, and ask me if anything about my data is unclear.
If the Knowns UI MCP server is connected (https://ui.knowns.dev/docs/ai-and-mcp), use get_component({ name: "slider" }) or search_docs for details.
Finish with a short summary: the files you added or changed, the packages you installed, and anything I still need to do.Props
- value / defaultValue
number|[number, number]- Default
min / [min, max] - A number gives one thumb, a pair gives a range.
- onValueChange
(value) => void- Every change while dragging or pressing keys.
- onValueCommit
(value) => void- Once per gesture: on release, or after each key press. Good for saving.
- min / max / step
number- Default
0 / 100 / 1 - Values snap to the step grid that starts at min.
- largeStep
number- Default
10 × step - PageUp / PageDown jump.
- size
"sm"|"md"- Default
"md" - Track and thumb size; the hit area stays generous, more so on touch screens.
- marks
(number | { value, label? })[]- Ticks on the track; labelled ones show their label underneath.
- tooltip
boolean|"always"- Default
false - Value bubble over the thumb while dragging or focused from the keyboard, or all the time.
- formatValue
(v: number) => string- Default
String - Text for the bubble, the readout and screen readers (aria-valuetext).
- label / hint
ReactNode- Field-style label with the value on the right, and a muted line underneath.
- hideValue
boolean- Default
false - Hide the readout next to the label.
- aria-label
string- Name when there is no label.
- thumbLabels
[string, string]- Default
["Minimum", "Maximum"] - Names of the two thumbs in a range.
- name
string- Hidden inputs for forms: name, or name[0] and name[1] for a range.
- disabled
boolean- Default
false - Dims the slider and ignores input.
| Prop | Type | Default | Description |
|---|---|---|---|
| value / defaultValue | number | [number, number] | min / [min, max] | A number gives one thumb, a pair gives a range. |
| onValueChange | (value) => void | - | Every change while dragging or pressing keys. |
| onValueCommit | (value) => void | - | Once per gesture: on release, or after each key press. Good for saving. |
| min / max / step | number | 0 / 100 / 1 | Values snap to the step grid that starts at min. |
| largeStep | number | 10 × step | PageUp / PageDown jump. |
| size | "sm" | "md" | "md" | Track and thumb size; the hit area stays generous, more so on touch screens. |
| marks | (number | { value, label? })[] | - | Ticks on the track; labelled ones show their label underneath. |
| tooltip | boolean | "always" | false | Value bubble over the thumb while dragging or focused from the keyboard, or all the time. |
| formatValue | (v: number) => string | String | Text for the bubble, the readout and screen readers (aria-valuetext). |
| label / hint | ReactNode | - | Field-style label with the value on the right, and a muted line underneath. |
| hideValue | boolean | false | Hide the readout next to the label. |
| aria-label | string | - | Name when there is no label. |
| thumbLabels | [string, string] | ["Minimum", "Maximum"] | Names of the two thumbs in a range. |
| name | string | - | Hidden inputs for forms: name, or name[0] and name[1] for a range. |
| disabled | boolean | false | Dims the slider and ignores input. |
What it handles
- 01Picks one number or a from and to pair, decided by whether value or defaultValue is a number or an array, and keeps range thumbs from crossing.
- 02Snaps every value to the step grid that starts at min, so a step of 0.1 gives 0.3 and not 0.30000000000000004.
- 03Moves by pointer drag or a click on the track, picking the closest thumb, and by key: arrows one step, PageUp and PageDown by largeStep, Home and End to the ends.
- 04Calls onValueChange on every change and onValueCommit once per gesture, on release or after each key press.
- 05Shows tick marks with optional labels, a value bubble over the thumb while dragging or on keyboard focus or always, and a readout next to the label that formatValue controls.
- 06Names each range thumb for screen readers through thumbLabels, and submits one hidden input per thumb when name is set.
States
- First render
- Nothing. The fill and the thumbs paint at their values
- none
- Dragging
- The active thumb grows to 110% and rises above the other
- 120ms, ease out
- Value bubble
- The bubble fades in and rises 4px above the thumb while dragging or focused from the keyboard
- 120ms, ease out
- Value change
- The fill and the thumb follow the pointer or the key with no easing
- none, at once
- Tick marks
- A tick changes colour as the fill passes it
- 120ms, ease out
- Disabled
- The whole slider dims and takes no input
- none, at once
- Reduced motion
- The thumb scale and the bubble change at once
- 0ms
| State | What moves | Timing |
|---|---|---|
| First render | Nothing. The fill and the thumbs paint at their values | none |
| Dragging | The active thumb grows to 110% and rises above the other | 120ms, ease out |
| Value bubble | The bubble fades in and rises 4px above the thumb while dragging or focused from the keyboard | 120ms, ease out |
| Value change | The fill and the thumb follow the pointer or the key with no easing | none, at once |
| Tick marks | A tick changes colour as the fill passes it | 120ms, ease out |
| Disabled | The whole slider dims and takes no input | none, at once |
| Reduced motion | The thumb scale and the bubble change at once | 0ms |
Works with
When to use
When to use
- Choosing a value or range where the rough position matters more than the exact number.
When not to use
- Exact values such as prices or IDs: use Input.
Using with AI
Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:
- Add the Knowns UI Slider to my app and wire it to my own data.
- I need choosing a value or range where the rough position matters more than the exact number. Set that up with the Knowns UI Slider.
- Which Slider props do I need for a minimal setup? Show me a short example.
With the server connected, your assistant calls get_component({ name: "slider" }) and search_docs({ query: "slider" }).