Skip to Content
Soundor Components
Components

Knob

A 270° dial for one numeric value.

Use Knob for parameters that read well as a dial, such as feedback or tone.

import { Knob, formatters } from '@soundor/components';
import { View } from '@soundor/react';
import { useState } from 'react';
import { parameters } from 'soundor:parameters';

export default function Demo() {
  const [feedback, setFeedback] = useState(0.4);
  return (
    <View style={{ flexDirection: 'row', gap: 24, alignItems: 'center' }}>
      <Knob
        parameter={parameters.feedback}
        size="lg"
        format={formatters.percent}
      />
      <Knob
        label="Disabled"
        disabled
        defaultValue={0.4}
        format={formatters.percent}
      />
      <Knob
        label="Standalone"
        value={feedback}
        onChange={setFeedback}
        format={formatters.percent}
      />
    </View>
  );
}
knob.tsx, running in the web runtime.Source

Usage

With a parameter

Pass a generated parameter and the control inherits its range, mapping, formatting, parser and reset value. It opens and closes host gestures and records undo history; set history={false} to opt out, or history={{ label: 'Adjust feedback' }} to name the entry.

import { Knob, formatters } from '@soundor/components';

<Knob parameter={parameters.feedback} size="lg" format={formatters.percent} />;

Without a parameter

Pass value and onChange (or defaultValue) with the range you need. A controlled control should update value in response to onChange.

const [feedback, setFeedback] = useState(0.4);

<Knob
  label="Feedback"
  value={feedback}
  onChange={setFeedback}
  format={formatters.percent}
/>;

Keyboard and accessibility

A read-only parameter's value can be focused and read without being edited. A ContextMenu can still offer Copy. A disabled knob cannot take focus.

← → ↑ ↓ change the value by 1% of the range, Page Up and Page Down by 10%, and Home and End go to the minimum and maximum. Shift makes any of them ten times finer, in drag and wheel too. Double-click or Alt-click (Option-click on a Mac) resets the value, as do Delete and Backspace, and Esc cancels a drag. A screen reader hears the label and formatted value, and can increment, decrement, set or reset it. See Keyboard and accessibility.

Props

See Mixed values for editing multiple items.

Knob props

Prop

Type

Range props

Prop

Type

On this page