Skip to main content

Slider

An interactive input control that allows users to select a numeric value within a defined range using pointer dragging, track clicking, or keyboard navigation. Supports controlled and uncontrolled usage, step snapping, and full accessibility semantics.


Usage

Basic usage

import { Slider } from '@nofinite/nui';

<Slider />;

Controlled slider

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

<Slider value={value} onChange={setValue} />;

Custom range and step

<Slider min={0} max={10} step={0.5} defaultValue={5} />

Disabled slider

<Slider disabled defaultValue={40} />

Props

PropTypeDefaultDescription
minnumber0Minimum value
maxnumber100Maximum value
stepnumber1Step increment
valuenumberControlled value
defaultValuenumberminInitial uncontrolled value
onChange(value: number) → voidCallback when value changes
disabledbooleanfalseDisables interaction
classNamestringAdditional styling

Variants

Range configuration

<Slider min={0} max={100} />
<Slider min={0} max={10} step={0.1} />

Controlled vs uncontrolled

<Slider defaultValue={20} />
<Slider value={value} onChange={setValue} />

Disabled

<Slider disabled />

Available variants

  • Default range
  • Custom range
  • Controlled
  • Uncontrolled
  • Disabled

Guidelines

  • Use controlled mode when value must sync with external state
  • Use uncontrolled mode for simple forms
  • Prefer smaller step values for precision inputs
  • Avoid extremely small steps causing excessive updates

States

  • Idle
  • Hover thumb
  • Dragging
  • Focus-visible
  • Keyboard interaction
  • Disabled
  • Reduced motion

Keyboard Interaction

KeyBehavior
ArrowRight / ArrowUpIncrease by step
ArrowLeft / ArrowDownDecrease by step
PageUpIncrease by step × 10
PageDownDecrease by step × 10
HomeJump to min
EndJump to max

Accessibility

  • Uses role="slider"
  • Provides aria-valuemin, aria-valuemax, aria-valuenow
  • Keyboard operable with full navigation semantics
  • Focus is programmatically applied on pointer interaction
  • Disabled state exposed via aria-disabled
  • Respects prefers-reduced-motion
  • Large invisible hit target improves touch usability

Design Tokens

TokenUsage
--nui-bg-subtleTrack background
--nui-color-primaryFill color + thumb border
--nui-bg-surfaceThumb background
--nui-brand-50 / 100 / 600Hover + focus states
--nui-fg-mutedDisabled styling

Best Practices

Do

  • Match slider range with meaningful domain values
  • Use stepping for predictable snapping behavior
  • Provide visible labels or value indicators in forms
  • Use controlled mode when slider drives UI changes
  • Ensure adequate width for precise interaction

Don’t

  • Use extremely small step sizes for long ranges
  • Hide numeric meaning of slider value
  • Rely solely on slider for critical precision input
  • Disable keyboard navigation
  • Use sliders for binary choices (prefer toggle)