LabDAW

Knob

A rotary control for continuous parameters, with pointer, wheel and keyboard input.

A rotary control for continuous parameters such as level, cutoff or pan. The registry component is written on the knob primitive, which installs with it, and adds size variants and theme styles.

Overview

  • Input: drag around the knob (dragMode="circular", the default), up and down ("vertical"), or by full turns ("revolution"). The mouse wheel and the keyboard also work. A double-click or a double-tap returns to defaultValue.
  • Display: a track, an arc from anchor to the value, and a needle that turns with the value. The needle follows the pointer without easing, so it stays in line with the arc.
  • Accessibility: the knob holds a native <input type="range"> that takes focus and carries the accessible name (aria-label or aria-labelledby), the value text (formatted with format, or set with getAriaValueText on the primitive's Thumb) 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/knob

Or the primitive alone, to style yourself:

pnpm dlx shadcn@latest add @audio-ui/knob-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 { Knob } from "@/components/audio-ui/knob";

Uncontrolled: set only the initial value.

<Knob defaultValue={50} max={100} min={0} step={1} />

Controlled: drive the value from state.

const [cutoff, setCutoff] = useState(1000);

<Knob
  max={20_000}
  min={20}
  onValueChange={setCutoff}
  step={1}
  value={cutoff}
/>

Pass defaultValue even when the knob is controlled if you use the double-tap reset: it sets the value the knob returns to, clamped and stepped.

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 arcs, a Thumb that holds the focusable input, and a Value for the text. A part takes the classes and attributes of its element, and a state attribute (data-dragging, data-disabled, data-drag-mode) on each part to style from.

import { useState } from "react";
import { Knob } from "@/components/audio-ui/knob/react";

export function Cutoff() {
  const [value, setValue] = useState(40);
  return (
    <Knob.Root
      format={{ style: "unit", unit: "percent" }}
      onValueChange={setValue}
      value={value}
    >
      <Knob.Control className="relative size-24">
        <Knob.Track className="absolute inset-0 text-muted" />
        <Knob.Indicator className="absolute inset-0 text-primary" />
        <Knob.Thumb aria-label="Cutoff" className="absolute inset-3 rounded-full bg-card" />
      </Knob.Control>
      <Knob.Value />
    </Knob.Root>
  );
}

Interaction

Pointer

Behavior · 5

Circular drag (default)
The value follows the rotation around the center, from the value at pointer down. The dial's 288° sweep spans min…max.
Vertical drag
dragMode="vertical": drag up to increase, like a fader; 150px of travel spans min…max.
Revolution drag
dragMode="revolution": one full 360° turn spans min…max.
Fine drag
Hold Shift while dragging, in any mode, to turn four times slower. Only the stretch moved with Shift held is slowed, and small moves add up rather than rounding away.
Double-tap / double-click
Two quick taps (each moving ≤ ~12px, within ~320ms) reset to defaultValue, or to the middle of the dial's travel without one. Reports eventDetails.reason === "reset".

Values stay within min…max and do not wrap. While dragging, the knob follows the pointer even if a controlled value updates late.

Scale

scale sets how the value maps onto the dial's travel. "linear" (the default) suits levels and times; "log" suits frequency, resonance and ratios, which are heard as proportions: on a 20 Hz–20 kHz cutoff, every decade gets the same share of the dial, and 632 Hz sits at the middle. A log scale needs a positive min. For anything else, pass your own { to, from }, mapping a value into an even space and back.

<Knob aria-label="Cutoff" max={20_000} min={20} scale="log" />

Away from linear, the keys and the wheel move a share of the travel (1%, or 10% with Shift and the Page keys) rather than a step, and always by at least one step.

Keyboard

On the focused knob:

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-knob-value in plain HTML, editableValue on the styled knob), 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 knob
Escape
Keeps the value

The readout carries data-editable, and data-editing while the field is open.

Wheel

The mouse wheel over the knob moves the value by step and reports eventDetails.reason === "wheel".

API reference

Registry component

Knob accepts size and className plus the props of the Knob primitive's Root. aria-label, aria-labelledby, and aria-describedby are forwarded to the knob's input.

Props · 21

The knob primitive that installs with it exposes Knob.Root, Knob.Control (pointer, wheel, reset), Knob.Track and Knob.Indicator (SVG arcs; strokeWidth in the 48×48 viewBox), Knob.Thumb (rotates with the value and holds the input), Knob.Value (formatted <output>), Knob.Provider (the default dragMode of the knobs below it), Knob.Mark (a graduation at a value, rotated onto the dial's scale, with data-active once reached), and Knob.Label. Every part accepts a render prop, className / style as functions of state, and exposes data-disabled / data-dragging.

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, stepnumber0, 100, 1The range and the grid the value snaps to.
largeStepnumberWhat Page Up, Page Down and Shift with an arrow move by.
anchornumberWhere the Indicator's arc starts, like 0 for a pan.
scale"linear", "log" or { to, from }"linear"How the value maps onto the dial.
dragMode"circular", "revolution", "vertical""circular"How pointer travel turns into value.
format, localeIntl.NumberFormat options, a localeThe Value's text and the input's aria-valuetext.
disabledbooleanfalseTakes no key, wheel or drag.
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.

What a change reports

details carries what moved the value and how:

  • reason: "drag", "wheel", "keyboard" 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 knob keeps the value you give it.

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 · 9

Events

Events · 2

Examples

Rail, anchor, and range highlight

Use anchor to show a reference point on the rail (for example the center of a bipolar control). The arc highlights the interval between anchor and the current value.

Logarithmic scale

scale="log" spreads a frequency evenly by ratio, so a quarter turn goes from 1 kHz to 8.7 kHz instead of packing the useful range into the first few degrees.

Vertical drag

dragMode="vertical" turns the knob like a fader: drag up to increase, down to decrease, with 150px of travel for the whole range. It suits a small knob, or one next to others, where going around it would be fiddly.

To turn every knob of an app that way, wrap it once in Knob.Provider: each Knob.Root below it takes that mode, unless it sets its own dragMode.

import { Knob } from "@/components/audio-ui/knob/react"

<Knob.Provider dragMode="vertical">
  <Mixer />
</Knob.Provider>

For an agent

The knob 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