audiocn

Fader

A volume fader in decibels, with tapers, detents, a scale, reset and an editable value.

Microphone
−6.0 dB

Installation

$ pnpm dlx shadcn@latest add @audiocn/fader

Usage

import { Fader } from "@/components/ui/fader";
const [gainDb, setGainDb] = useState(0);

<Fader aria-label="Microphone" value={gainDb} onValueChange={setGainDb} />;

The value is always in dB. The taper decides where each dB value sits on the travel. The thumb snaps to 0 dB while dragging, and double-clicking it resets.

Anatomy

<Fader value={db} onValueChange={setDb}>
  <FaderLabel>Microphone</FaderLabel>
  <FaderReset />
  <FaderValue editable />
  <FaderTrack>
    <FaderRange />
    <FaderThumb />
  </FaderTrack>
  <FaderScale />
</Fader>

FaderTrack accepts any children, so a LevelMeter can sit inside it.

Examples

Console faders

taper="audio" gives more travel around 0 dB, like a mixing console.

0.0 dB
Mic
−18.0 dB
Music
−12.0 dB
Game

Bipolar gain

Set origin={0} so the fill grows from the middle.

Input gain

Silence at the bottom

With silenceAtMin, the lowest position reports -Infinity.

Output
−10.0 dB

With a meter in the track

0.0 dB

Sizes

Keyboard

KeyAction
Arrow keysChange by step (0.5 dB)
Shift + arrow, Page Up / Page DownChange by largeStep (6 dB)
Alt + arrowChange by fineStep (0.1 dB)
Home / EndMinimum (or silence) / maximum

Holding Alt while dragging uses fineStep resolution.

Theming

Variable or attributeMeaning
--fader-track-size, --fader-thumb-sizeSet by size
data-orientation, data-variant, data-sizeCurrent settings
data-draggingThe thumb is held
data-at-detentThe value sits on a detent
data-silentThe value is -Infinity
data-disabledDisabled

Accessibility

The thumb is a slider whose aria-valuetext is the formatted value, such as "−6.0 dB" or "Silent". Give the fader a name with FaderLabel or aria-label.

API reference

Fader

Prop

Type

FaderValue

The value is as wide as the longest text the fader's range can show, and right-aligned, so moving the fader never shifts the layout. The editor opens at the same width.

Prop

Type

FaderScale

Takes DbScale props. The range, taper and orientation come from the fader.