LabDAW

Fader

A linear slider for gain and other continuous parameters.

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. onValueCommitted fires when the interaction ends.
  • Layout: vertical by default, or horizontal, in sm, default and lg sizes.
  • 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-label or aria-labelledby), the value text (formatted with format) 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:

pnpm dlx shadcn@latest add @audio-ui/fader

Or the primitive alone, to style yourself:

pnpm 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:

pnpm dlx shadcn@latest add @audio-ui/primitives-css

Usage

import { Fader } from "@/components/audio-ui/fader";

Uncontrolled: set only the initial value.

<Fader defaultValue={0} max={6} min={-60} step={1} />

Controlled: drive the value from state.

const [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.

import { 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

Track click / drag
Click or drag on the track to set the value from the pointer position.
Thumb drag
Dragging the thumb changes the value continuously, within min…max.
Commit event
onValueCommitted fires when an interaction ends with a new value.
Lagging value
While dragging, the thumb follows the pointer even if a controlled value updates late; it returns to value on release. Reject a value with eventDetails.cancel().

Keyboard

On the focused thumb:

Keys · 6

ArrowUp / ArrowRight
Increase by step
ArrowDown / ArrowLeft
Decrease by step
PageUp / Shift + ArrowUp
Increase by largeStep (default 10)
PageDown / Shift + ArrowDown
Decrease by largeStep (default 10)
Home
Set to min
End
Set to max

On 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

Double click / Enter / F2
Lays a text field over the readout, its text selected
Enter / leaving the field
Sets the number typed, as a change of the fader
Escape
Keeps the value

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

Layout and visuals

Props · 4

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).

OptionTypeDefault
value, defaultValuenumberthe midpointThe controlled value, or the starting one. defaultValue is also where a reset returns.
min, max, stepnumber-60, 6, 1The range, in dB for an audio fader, and the grid the value snaps to.
largeStepnumber10What Page Up, Page Down and Shift with an arrow move by.
anchornumberminWhere 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, localeIntl.NumberFormat options, a localeThe Value's text and the input's aria-valuetext.
disabledbooleanfalseTakes no key, wheel or press.
namestringThe form field's name, carried by the input.
onValueChange(value, details) => voidEvery change, which details.cancel() refuses.
onValueCommitted(value, details) => voidThe 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

Events

Events · 2

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.

Built by Ouest Labs, the source code is available on GitHub.
RSS