This page as markdown: /slider-field.md · Index for agents: /llms.txt · Everything in one file: /llms-full.txt

SliderField

Status: stable

A slider drawn as a field: the whole box is the track, the fill is the value's share of the range, and the number sits inside it. Double-click, Enter or a typed digit turns the readout into a text input.

Keywords: slider, fill, field, numeric, number, range, property, inspector, toolbar, workspace, unit

Usage

Use SliderField for a bounded number in a panel, an inspector or a toolbar: opacity, strength, a resolution. It does the work of a Slider with a ScrubField beside it in one control, and the drag target is the full field instead of a 6px rail. The fill only means something between two bounds, so a number without them (an X offset, a seed) stays a ScrubField. In a form where the slider is the main control and its row has room, a Slider reads lighter.

Best practices

Props

Name Type Default Description
value number — Controlled value.
defaultValue number min Uncontrolled initial value.
onValueChange (next: number) => void — Fires on every change: each frame of a drag, each key step, a typed commit.
onValueCommitted (next: number) => void — Fires once when a change settles: the drag is released, a key step lands, a typed value is committed or reverted. Record an undo entry here.
min number 0 Lower bound, and the empty end of the fill.
max number 100 Upper bound, and the full end of the fill.
step number 1 Drag and arrow-key increment, and the source of the displayed precision: 0.01 shows 0.25. A typed value is clamped to the bounds and rounded to this precision, not snapped to a multiple.
label string — Accessible name for the slider and for the input that replaces the readout while typing. Required.
icon string — Semantic icon name shown at the start of the field. Decorative.
prefix ReactNode — Short text at the start of the field in place of an icon, for a toolbar with no label beside the control.
suffix ReactNode — Unit shown after the value ("%", "px"). A string is also spoken with the value.
size "md" | "sm" | "xs" "md" The field ladder shared with Input, SelectTrigger and DatePicker. md is the form field, sm the toolbar field, xs the borderless property-grid rung beside ScrubField.
disabled boolean — Ignores the pointer and keyboard, dims the field and submits nothing.
name string — Submits the value with a form under this name.
form string — Id of a form elsewhere on the page that the value belongs to.
className string — Sizes the field (w-36, flex-1). Defaults to w-full with a 7rem floor, so in a slot sized by its content (a PropertyRow's control side) it draws at the floor until given a width.

Tokens used

foreground, muted-foreground, ring, field, field-border, panel-field, panel-field-hover

Motion

Accessibility

Related

Examples

In a property row

import { PropertyRow, SliderField } from "@sableui/react"

<PropertyRow label="Strength">
  <SliderField size="xs" label="Strength" suffix="px" value={strength} min={0} max={20} onValueChange={setStrength} className="w-36" />
</PropertyRow>

Fractional step

import { SliderField } from "@sableui/react"

<SliderField size="xs" label="Falloff" value={falloff} min={0} max={2} step={0.1} onValueChange={setFalloff} className="w-36" />

In a toolbar, with the name inside the field

import { SliderField } from "@sableui/react"

<SliderField size="sm" label="Opacity" prefix="Opacity" suffix="%" defaultValue={80} className="w-44" />

Undo on commit

import { SliderField } from "@sableui/react"

<SliderField label="Brightness" suffix="%" value={brightness} onValueChange={setBrightness} onValueCommitted={(v) => history.push({ brightness: v })} />