NOCTA UI

Slider

A customizable range slider component with variants, orientations, and accessibility support for value selection

Installation

Install the Slider component using the nocta-ui CLI:

Terminal
npx nocta-ui add slider

Then import the component:

Import
import { Slider } from '@/components/ui/slider';

Basic Usage

Default Slider

Primary Slider

Secondary Slider

Variants

The Slider component supports three variants: default, primary, and secondary.

Sizes

Three size options are available: sm, md, and lg. The default size is md.

Features

Show Value

42

Custom Range & Formatting

22°C
7

Step Values

20

Vertical Orientation

Primary
Secondary Large

States

Disabled State

Controlled vs Uncontrolled

Controlled Slider

const [value, setValue] = useState(50);

return (
  <Slider 
    value={value} 
    onChange={setValue}
  />
);

Uncontrolled Slider

return (
  <Slider 
    defaultValue={50}
    onChange={(value) => console.log('Value changed:', value)}
  />
);

Keyboard Navigation

The Slider component supports full keyboard navigation:

  • Arrow Left/Down: Decrease value by step
  • Arrow Right/Up: Increase value by step
  • Home: Jump to minimum value
  • End: Jump to maximum value
  • Page Down: Decrease by 10 × step
  • Page Up: Increase by 10 × step

Accessibility

The Slider component includes comprehensive accessibility features:

  • role="slider" for screen readers
  • aria-valuemin, aria-valuemax, aria-valuenow for value communication
  • aria-orientation for orientation awareness
  • aria-label and aria-labelledby support
  • Full keyboard navigation
  • Focus management with visible focus rings

Props

PropTypeDefaultDescription
valuenumberControlled value
defaultValuenumber0Default value for uncontrolled usage
minnumber0Minimum value
maxnumber100Maximum value
stepnumber1Step increment
disabledbooleanfalseDisable the slider
size'sm' | 'md' | 'lg''md'Slider size
variant'default' | 'primary' | 'secondary''default'Slider style variant
orientation'horizontal' | 'vertical''horizontal'Slider orientation
showValuebooleanfalseShow current value
formatValue(value: number) => string(value) => value.toString()Custom value formatter
onChange(value: number) => voidValue change handler
onValueCommit(value: number) => voidCalled when value is committed
classNamestring''Additional CSS classes
trackClassNamestring''Track element CSS classes
thumbClassNamestring''Thumb element CSS classes
aria-labelstringAccessibility label
aria-labelledbystringID of labeling element

The Slider component also accepts all standard HTML div attributes.