A linear control for continuous parameters such as volume, gain or a send level. The registry component is written on the fader primitive, which installs with it, and adds size variants and thumb marks.
Overview
- Input: drag the thumb or press the track, or use the mouse wheel or the keyboard.
onValueCommittedfires when the interaction ends. - Layout: vertical by default, or horizontal, in
sm,defaultandlgsizes. - Display: a filled range and a thumb, with optional marks inside the thumb (
thumbMarks). - Accessibility: the thumb holds a native
<input type="range">that carries the accessible name (aria-labeloraria-labelledby), the value text (formatted withformat) and the form value (name).
Installation
The primitives are built on the UI SDK kernel, in beta. Nothing of ours comes from npm: the primitive and its adapter are files you copy into your project and own, and the only packages are the kernel's. The commands name its version, @ui-sdk/*@0.1.0-beta.14.
The styled component, with size variants and theme styles:
Copy to Clipboardpnpm dlx shadcn@latest add @audio-ui/fader
Or the primitive alone, to style yourself:
Copy to Clipboardpnpm dlx shadcn@latest add @audio-ui/fader-react
It writes the primitive, its adapter and primitive.ts into components/audio-ui/ and installs the kernel's packages and what each file imports. The optional styles are one more command:
Copy to Clipboardpnpm dlx shadcn@latest add @audio-ui/primitives-css
Usage
Copy to Clipboardimport { Fader } from "@/components/audio-ui/fader";
Uncontrolled: set only the initial value.
Copy to Clipboard<Fader defaultValue={0} max={6} min={-60} step={1} />
Controlled: drive the value from state.
Copy to Clipboardconst [gain, setGain] = useState(0); <Fader max={6} min={-60} onValueChange={setGain} onValueCommitted={(value, details) => console.log("Committed:", value, details.reason)} step={1} value={gain} />
The primitive alone, part by part:
The parts are the same everywhere: a Root that owns the value, a Control that takes the pointer and the wheel, a Track and an Indicator that draw the travel and the fill, a Thumb that holds the focusable input, optional Marks along the track, and a Value for the text. A part takes the classes and attributes of its element, and the state attributes data-disabled, data-dragging and data-orientation to style from.
The Track, the Indicator, the Thumb and the Marks are positioned for you, from the bottom of a vertical fader and from the start edge of a horizontal one. Give the Track its length and the Control its size.
Copy to Clipboardimport { useState } from "react"; import { Fader } from "@/components/audio-ui/fader/react"; export function Level() { const [level, setLevel] = useState(-12); return ( <Fader.Root max={6} min={-60} onValueChange={setLevel} value={level}> <Fader.Control className="relative h-40 w-8"> <Fader.Track className="absolute inset-y-0 left-1/2 w-1 bg-muted"> <Fader.Indicator className="absolute bg-primary" /> <Fader.Mark value={0} /> </Fader.Track> <Fader.Thumb aria-label="Level" className="size-4 rounded-full bg-card" /> </Fader.Control> <Fader.Value /> </Fader.Root> ); }
Interaction
Pointer
Behavior · 4
min…max.onValueCommitted fires when an interaction ends with a new value.value updates late; it returns to value on release. Reject a value with eventDetails.cancel().Keyboard
On the focused thumb:
Keys · 6
stepsteplargeStep (default 10)largeStep (default 10)minmaxOn an editable readout, given editable on Value (the editable attribute on audio-ui-fader-value in plain HTML, editableValue on the styled fader), in every framework:
Editable readout · 3
The readout carries data-editable, and data-editing while the field is open.
Wheel
The mouse wheel over the fader moves the value by step and reports eventDetails.reason === "wheel".
API reference
Registry component
Fader accepts style props (size, thumbMarks, className) plus the props of the Fader primitive's Root (name, form, format, locale, largeStep, render, …). The primitive's Fader.Mark places a graduation at a value along the track, with data-active once the value has reached it, to build your own ruler. aria-label, aria-labelledby, and aria-describedby are forwarded to the thumb's input.
Value and state
Props · 15
min and max.min…max.anchor light up.auto while hovered, dragged or focused from the keyboard."-6.0 dB".reason: "input-change").Indicator fills from, such as 0 on a -1…1 pan. Defaults to min.Layout and visuals
Props · 4
false to hide them.Additional valid HTML attributes passed to Fader.Root are forwarded.
A vertical fader takes the height it is given, and never less than --fader-min-height (10rem by default). Set it lower where room is short, such as a mixer on a small screen: [--fader-min-height:5rem] on a parent.
Options
Set on the Root, as props (an attribute in kebab case in the web adapter).
| Option | Type | Default | |
|---|---|---|---|
value, defaultValue | number | the midpoint | The controlled value, or the starting one. defaultValue is also where a reset returns. |
min, max, step | number | -60, 6, 1 | The range, in dB for an audio fader, and the grid the value snaps to. |
largeStep | number | 10 | What Page Up, Page Down and Shift with an arrow move by. |
anchor | number | min | Where the Indicator's fill starts, like 0 on a pan from -1 to 1. |
orientation | "vertical" or "horizontal" | "vertical" | Which way the travel runs. |
format, locale | Intl.NumberFormat options, a locale | The Value's text and the input's aria-valuetext. | |
disabled | boolean | false | Takes no key, wheel or press. |
name | string | The form field's name, carried by the input. | |
onValueChange | (value, details) => void | Every change, which details.cancel() refuses. | |
onValueCommitted | (value, details) => void | The end of a gesture. |
The Mark takes a value and carries data-active while the value has reached it from the anchor. The Thumb takes getAriaValueText(formatted, value, index) to announce the value in your own words, like "-6 dB".
What a change reports
details carries what moved the value and how:
reason:"drag","track-press","keyboard","wheel","input-change"(a typed value) or"reset".source:"mouse","touch","pen","keyboard","programmatic"or"agent", for analytics and for telling a person from an agent. It is never a reason to behave differently.event: the DOM event behind it, when there is one.cancel(): refuses the change. A controlled fader keeps the value you give it.
While a pointer drags the thumb, it follows the pointer even if a controlled value lags behind, as with a seek bar driven by playback time.
In the web adapter, onValueChange is an input event and onValueCommitted a change event, both with detail: { value, reason, source }, and event.preventDefault() refuses a change.
Parts
Parts · 8
value: number.Events
Events · 2
@value-change. Web: the input event.@value-committed. Web: the change event.Examples
Pan, filled from the center
anchor={0} makes the fill grow from the center of a -1…1 range, left or right of it.
Mixing console
A fader per channel in dB, from silent at the bottom to +6 dB, beside the meter of what it lets through.
For an agent
The fader declares one action, setValue, and the name on its Thumb is what an agent finds it by. The bridge of the framework you use (createAgent in @ui-sdk/<framework>/agent) reads its value and range, sets it with the source "agent", and the same onValueChange hears it, so an app can refuse a value as it would a person's.