Skip to main content

Slider

Selects a numeric value within a defined range.

import { Slider } from "@/fragments/ui";Source

Preview

<div style={{ width: '300px' }}>
  <Slider label="Volume" defaultValue={50} />
</div>

Installation

npx @usefragments/cli add slider

Writes src/fragments/ui/components/Slider plus what it imports, the globals stylesheet, and .fragments/registry-lock.json, then prints the packages to add. No account, no key.

Your own registry: publish from Fragments Cloud and add --registry org/name. Connect a workspace.

Examples

With Value Display

showValue prints the number opposite the label.

<div style={{ width: '300px' }}>
  <Slider
    label="Brightness"
    defaultValue={75}
    showValue
    valueSuffix="%"

Custom Range

min, max and step bound the track to real-world units.

<div style={{ width: '300px', display: 'flex', flexDirection: 'column', gap: '16px' }}>
  <Slider
    label="Temperature"
    min={60}
    max={80}
    step={1}

Controlled

The parent owns the value and can react to every move.

<ControlledSliderDemo />

Drag Value Bubble

The number floats above the thumb only while dragging.

<div style={{ width: '300px' }}>
  <Slider
    label="Mix"
    defaultValue={40}
    showValueOnDrag
    valueSuffix="%"

With Helper Text

A line below the track explains the trade-off.

<div style={{ width: '300px' }}>
  <Slider
    label="Quality"
    defaultValue={80}
    showValue
    valueSuffix="%"

Disabled

Dimmed; the thumb will not move.

<div style={{ width: '300px' }}>
  <Slider
    label="Locked Setting"
    defaultValue={30}
    showValue
    disabled

API

Component props
Prop
Type
Default
Description
labelstringNot setLabel text
helperTextstringNot setHelper text shown below the slider
errorbooleanfalseShow error styling
valuenumberNot setControlled value
defaultValuenumberNot setDefault value for uncontrolled usage
onChangefunctionNot setCalled with new value when changed
onValueChangefunctionNot setAlias for onChange (Radix convention): (value: number) => void
minnumber0Minimum value
maxnumber100Maximum value
stepnumber1Step interval
showValuebooleanfalseDisplay current value
showValueOnDragbooleanfalseShow current value in a floating bubble while dragging the thumb
valueSuffixstringSuffix after value (e.g., "%", "px")
disabledbooleanfalseDisable the slider
namestringNot set
aria-labelstringNot setAccessible label when visible label is omitted
aria-labelledbystringNot setAccessible labelled-by relationship
aria-describedbystringNot setAccessible described-by relationship
idstringNot set
formstringNot setID of the form that owns the hidden slider input
largeStepnumberNot setLarger step used for Page Up/Page Down and shift-arrow keyboard input
onValueCommittedfunctionNot setCallback when the user commits a slider value
thumbAlignmentenumcenteredgeedge-client-onlyNot setHow the thumb is aligned at the minimum and maximum edges

Accessibility

  • Label is tied to the track
  • Arrow keys move the thumb
  • The current value is announced
  • Native slider semantics throughout

Guidance

Use when

  • Any value along a range, where roughly right is good enough
  • Volume, brightness, opacity
  • Price and range filters
  • The effect is visible as the user drags

Avoid when

  • An exact number matters (use Input type="number")
  • A handful of fixed choices (use RadioGroup or Select)
  • On or off (use Switch)
  • InputalternativeUse Input for precise numeric entry
  • ProgresssiblingSimilar visual, but Progress is read-only

Next steps