Fader
A volume fader in decibels, with tapers, detents, a scale, reset and an editable value.
Installation
$ pnpm dlx shadcn@latest add @audiocn/faderUsage
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.
Bipolar gain
Set origin={0} so the fill grows from the middle.
Silence at the bottom
With silenceAtMin, the lowest position reports -Infinity.
With a meter in the track
Sizes
Keyboard
| Key | Action |
|---|---|
| Arrow keys | Change by step (0.5 dB) |
| Shift + arrow, Page Up / Page Down | Change by largeStep (6 dB) |
| Alt + arrow | Change by fineStep (0.1 dB) |
| Home / End | Minimum (or silence) / maximum |
Holding Alt while dragging uses fineStep resolution.
Theming
| Variable or attribute | Meaning |
|---|---|
--fader-track-size, --fader-thumb-size | Set by size |
data-orientation, data-variant, data-size | Current settings |
data-dragging | The thumb is held |
data-at-detent | The value sits on a detent |
data-silent | The value is -Infinity |
data-disabled | Disabled |
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.