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 todefaultValue. - Display: a track, an arc from
anchorto 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-labeloraria-labelledby), the value text (formatted withformat, or set withgetAriaValueTexton the primitive'sThumb) 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/knob
Or the primitive alone, to style yourself:
Copy to Clipboardpnpm 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:
Copy to Clipboardpnpm dlx shadcn@latest add @audio-ui/primitives-css
Usage
Copy to Clipboardimport { Knob } from "@/components/audio-ui/knob";
Uncontrolled: set only the initial value.
Copy to Clipboard<Knob defaultValue={50} max={100} min={0} step={1} />
Controlled: drive the value from state.
Copy to Clipboardconst [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.
Copy to Clipboardimport { 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
min…max.dragMode="vertical": drag up to increase, like a fader; 150px of travel spans min…max.dragMode="revolution": one full 360° turn spans min…max.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.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.
Copy to Clipboard<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
stepsteplargeStep (default 10)largeStep (default 10)minmaxOn 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
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
0 on a -1…1 pan knob). Defaults to min.anchor light up.auto while hovered, turned or focused from the keyboard."8.7 kHz".Knob.Value and the input's aria-valuetext.format.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).
| 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 | 0, 100, 1 | The range and the grid the value snaps to. |
largeStep | number | What Page Up, Page Down and Shift with an arrow move by. | |
anchor | number | Where 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, locale | Intl.NumberFormat options, a locale | The Value's text and the input's aria-valuetext. | |
disabled | boolean | false | Takes no key, wheel or drag. |
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. |
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
strokeWidth: number.value: number.strokeWidth: number.Events
Events · 2
@value-change. Web: the input event.@value-committed. Web: the change event.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.
Copy to Clipboardimport { 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.