Components
Slider
Select a numeric value with a native range input.
Example
Requires React 18.2+ or 19 and shared styles. See setup.
Default
Loading preview…
Code
'use client';
import { useState } from 'react';
import { Slider } from '@swiftuijs/ui';
import { VStack } from '@swiftuijs/ui';
import { Text } from '@swiftuijs/ui';
const ControlledSliderDemo = () => {
const [value, setValue] = useState(50);
return (<VStack spacing={16}>
<Text>Controlled value: {value}</Text>
<Slider aria-label="Controlled slider" value={value} onValueChange={setValue} min={0} max={100}/>
</VStack>);
};
export default function Example() {
return (<ControlledSliderDemo />);
}Uncontrolled Usage
Use defaultValue when the browser should own the current value after mount.
Usage and limitations
- Controlled:
value/onValueChange; uncontrolled:defaultValue.onChangealso receives the native event. - Set
min,max, andstepfor the required range/granularity; supportsdisabledand native form submission. - Provide
aria-label,aria-labelledby, or an associated label, and display the current value when it matters. Check keyboard and touch interaction.
More examples
Uncontrolled Usage
Disabled State
API reference
| Prop | Type | Required | Description |
|---|---|---|---|
value | number | No | The current value of the slider. |
defaultValue | number | No | The initial value of the slider when uncontrolled. |
onValueChange | (value: number) => void | No | Callback fired when the value changes. |
onChange | (event: ChangeEvent<HTMLInputElement>) => void | No | Native change event handler forwarded to the underlying input. |
min | number | No | The minimum value of the slider. Default: 0 |
max | number | No | The maximum value of the slider. Default: 100 |
step | number | No | The step increment for the slider. Default: 1 |
disabled | boolean | No | Whether the slider is disabled. Default: false |
Inherits additional props from Omit<
IBaseElementComponent<'input'>,
'type' | 'value' | 'defaultValue' | 'onChange' | 'children'
>.