Skip to content
Cynosurev0.5.0
SearchStorybookGitHubnpmColour mode: System. Switch to Light

Components / Controls

Slider

Picks a number by dragging a thumb along a track, or a range with two thumbs. It works with the keyboard, pointer and touch, and submits with native forms.

Pointer drags and commits on release

When to useLink to "When to use"

  • A value where the rough position matters more than the exact number: volume, opacity, playback speed.
  • A range: a price band, a time window.

Use something else when:

UsageLink to "Usage"

tsx
Copy
import { Slider } from "@arshad-shah/cynosure";

<Slider label="Volume" value={volume} onChange={setVolume} showValue />
<Slider label="Price" defaultValue={[20, 60]} name="price" onCommit={search} />

onChange follows every movement while dragging; onCommit fires once the change is finished, so expensive work (a search, a save) can wait for it.

RangeLink to "Range"

Pass [from, to] for two thumbs. Each thumb is limited by the other, so they can meet but never cross. Each thumb has its own name ("Price, minimum" and "Price, maximum"), and the pair is a group named by the label.

Range thumbs never cross

More thumbs, and your own trackLink to "More thumbs, and your own track"

Give three or more numbers for as many thumbs, each held between its neighbours: gradient stops, or the cut points of a timeline. trackContent draws your own track (a gradient, a histogram) under the thumbs, in place of the accent fill; it is as tall as a thumb.

tsx
Copy
<Slider
  label="Gradient"
  value={stops}
  onChange={setStops}
  trackContent={<span style={{ background: `linear-gradient(to right, ${colours})` }} />}
/>
Gradient stops

Marks and value textLink to "Marks and value text"

marks draws ticks along the track, with optional text under it. labels.value turns a number into words, used for showValue and read by screen readers.

Labels marks and hidden label

PropsLink to "Props"

Every prop of Slider
PropWhat it doesTypeDefault
labelRequired
Accessible name, shown above the slider unless labelHidden.string
labelHidden
Visually hide the label (it still names the slider).boolean
value
A number, [from, to] for a range, or more numbers for more thumbs (each stays between its neighbours).SliderValue
defaultValue
Starting value when uncontrolled. Default: min.SliderValue`min`
onChange
Every change while dragging or pressing keys.((value: SliderValue) => void)
onCommit
When a change is finished: pointer released, or after each key press.((value: SliderValue) => void)
min
Lowest value. Default 0.number0
max
Highest value. Default 100.number100
step
Values snap to this step, and the arrow keys move by it. Default 1.number1
largeStep
Page Up and Page Down step (default a tenth of the range).number
orientation
vertical runs bottom to top. Default "horizontal"."horizontal" | "vertical""horizontal"
marks
Ticks on the track, with optional text under them.SliderMark[]
trackContent
Your own drawing of the track (a gradient, a histogram, a waveform), filling it under the thumbs. The accent fill is not drawn then.ReactNode
showValue
Show the current value (or range) at the end of the label row.boolean
name
Form field name; a range submits two values under it.string
disabled
Not focusable, cannot be changed and not submitted.boolean
size
Track and thumb size. Default "md".Size"md"
labels
Replace the built-in English text: the thumb names and the value text.Partial<SliderLabels>
className
Added to the root element, for layout.string
style
Layout only. Restyle through --cy-slider-* tokens.CSSProperties

Generated from the type definitions in @arshad-shah/cynosure 0.5.0.

Behaviour and accessibilityLink to "Behaviour and accessibility"

Behaviour and accessibility, table 1
InputResult
Right arrow / Up arrowUp by step (in right-to-left text, Right arrow lowers it)
Left arrow / Down arrowDown by step
Page Up / Page DownBy largeStep (a tenth of the range by default)
Home / EndTo min / max
Press or drag on the trackMoves the nearest thumb and keeps dragging
  • Roles: each thumb is role="slider" with aria-valuemin, aria-valuemax, aria-valuenow, aria-valuetext and aria-orientation. A range is a group.
  • Forms: with name, the value is submitted (two values for a range) and a form reset restores the default. Disabled sliders are not submitted.
  • Disabled: thumbs leave the Tab order; the track fades but the label stays readable.
  • Direction: horizontal sliders start at the inline start (right in right-to-left text); vertical ones start at the bottom.
Vertical

TouchLink to "Touch"

The thumb keeps its size, but its hit area is 44px on coarse pointers. Horizontal drags belong to the slider, so the page does not scroll sideways, while a vertical swipe over it still scrolls the page.

ThemingLink to "Theming"

Tokens: --cy-slider-track-{sm,md,lg}, --cy-slider-thumb-{sm,md,lg}, --cy-slider-track (the empty bar colour) and --cy-slider-length (vertical length).

ts
Copy
createTheme({ components: { slider: { thumbMd: "18px", trackMd: "6px" } } });

ProgressBar · SegmentedControl · TextField

These examples run Cynosure 0.5.0 (commit 50ce30b), the version on npm.

Getting started
Theming
Icons
Accessibility
Code editors and highlighters
Using Cynosure without React
Build-tool adapters
Components
Accordion
AppShell
AspectRatio
Breadcrumbs
Calendar
Card
Container
Disclosure
Divider
DocumentViewport
Grid
Inline
PageHeader
PanZoomCanvas
ScrollArea
SideNav
SortableList
SplitPane
Stack
StatusBar
Tabs
TitleBar
Toolbar
Tree
VirtualList
ZoomControls
Announcer
Avatar
Badge
CodeBlock
DescriptionList
EmptyState
ErrorBoundary
Field
Heading
IconTile
Image
Kbd
List
LoadingDots
Notice
ProgressBar
Prose
Skeleton
Stat
Steps
Table
Text
Button
Checkbox
Checklist
ColorField
ColorSwatches
Combobox
CompareSlider
CopyButton
DateField
FileDrop
IconButton
KeyValueEditor
Link
NumberField
Pagination
PathField
RadioGroup
SearchField
SegmentedControl
Select
SelectionFrame
SignaturePad
Slider
Switch
TagInput
TextArea
TextField
ThemeToggle
TimeField
ButtonBase
ChoiceBase
DialogBase
FileInputBase
HiddenValue
Icon
InputBase
LinkBase
LiveRegion
TextAreaBase
ChatMessage
Choice
DataGrid
DeviceFrame
HighlightedText
HotkeyField
ListRow
OptionList
OverlayFrame
QRCode
RowActions
Section
SiteFooter
SiteHeader
SkipLink
SortButton
VisuallyHidden
CommandPalette
ContextMenu
Dialog
FloatingToolbar
HoverCard
Menu
Menubar
Popover
ProgressOverlay
Sheet
Toast
Tooltip
Changelog