Examples
Single value
Use the thumb, keyboard, or track to select a bounded value.
Volume slider
import { Slider } from "@phuctech/ui/components/slider";
export function Example() {
return <Slider label="Volume" min={0} max={100} step={5} defaultValue={40} />;
}
Range with marks
Two thumbs keep a selected interval; labels name each endpoint for assistive technology.
Price range slider with marks
import { Slider } from "@phuctech/ui/components/slider";
export function Example() {
return (
<Slider
label="Price range"
min={0}
max={500}
step={25}
defaultValue={[100, 350]}
marks={[{ value: 0, label: "$0" }, { value: 250, label: "$250" }, { value: 500, label: "$500" }]}
thumbLabels={["Minimum price", "Maximum price"]}
/>
);
}
Disabled slider
Keep a fixed value visible when the feature does not allow adjustment.
Disabled allocation slider
import { Slider } from "@phuctech/ui/components/slider";
export function Example() {
return <Slider label="Locked allocation" min={0} max={100} value={65} disabled />;
}
Try the slider
Adjust the value and compare its disabled state; the marks remain tied to the same range.
Slider property playground
import { Slider } from "@phuctech/ui/components/slider";
const opacityMarks = [
{ value: 0, label: "0%" },
{ value: 50, label: "50%" },
{ value: 100, label: "100%" },
];
export function Example() {
return <Slider label="Opacity" min={0} max={100} step={5} defaultValue={65} marks={opacityMarks} disabled={false} />;
}
When to use
Use Slider when the user can choose an approximate point or interval within a known numeric range. Use InputNumber when an exact value is easier to type.
Usage
import { Slider } from "@phuctech/ui/components/slider";
<Slider label="Price range" min={0} max={500} step={25} defaultValue={[100, 350]} thumbLabels={["Minimum price", "Maximum price"]} />Behavior
- A number value creates one thumb; a two-number array creates a range with two thumbs.
- Arrow keys adjust the focused thumb by
step; Page Up/Down use the underlying slider's larger step behavior. marksare decorative reference points and do not snap or change the allowed values.- All value changes are reported to the feature; Slider performs no formatting or business validation beyond native range constraints.
API
Tokens
Accessibility
The visible label names the slider. A range uses thumbLabels to distinguish endpoints. Keyboard users can focus each thumb and adjust it with arrow keys. Marks are decorative; the current value is rendered as an output next to the label.
Do and don’t
Show the current value and provide an InputNumber alternative when exact entry matters.
Use marks as if they were selectable stops unless the configured step actually matches them.
Related
- InputNumber accepts precise numeric entry.
- RadioGroup selects one of a few discrete alternatives.
- Field provides supporting labels and validation.