audiocn-svelte
Esc

Start typing to search the docs

Tempo Control

An editable BPM input with tap tempo, keyboard stepping and a rolling average.

4 min read · 636 words

Installation

$ pnpm dlx shadcn-svelte@latest add https://juddisjudd.github.io/audiocn-svelte/r/tempo-control.json

Usage

<script lang="ts">
	import { TempoControl } from "#lib/components/ui/tempo-control/index.js";

	let bpm = $state(120);
</script>

<TempoControl bind:value={bpm} />

Tap at least twice to measure a tempo. The control averages the last four intervals and starts a new sequence after more than two seconds without a tap. Typing or stepping the input clears the tap history.

BPM values are always whole numbers. Tapped, typed and externally supplied fractional values round to the nearest integer. The default range is 30-600 BPM; set min and max to suit your application.

Anatomy

The input and tap button render by default. Supply children to arrange the parts, change their labels, or omit the tap button.

<TempoControl>
	<TempoControlInput />
	<TempoControlTap>Tap tempo</TempoControlTap>
</TempoControl>

Examples

Custom elements

128 BPM

Pass a child snippet to TempoControlTap to replace the default trigger with your own element. Spread props on it. This example combines a sound pad with a tempo readout.

<TempoControlTap>
	{#snippet child({ props })}
		<SoundPad {...props} class="w-full">
			<SoundPadLabel>Tap tempo</SoundPadLabel>
		</SoundPad>
	{/snippet}
</TempoControlTap>

Controlled BPM

Beat duration: 625 ms

Bind value to keep the BPM in your own state. onValueChange reports changes with a reason of tap, keyboard or input. onValueCommit fires after a measured tap, a keyboard step, or a text edit committed by blurring the input.

Sizes and disabled states

Small
Large
Disabled
Read-only

size and disabled inherit from a parent mixer or channel strip; explicit props win. readOnly keeps the input focusable but prevents editing and tapping.

Theming

Variable or attributeMeaning
--tempo-heightShared input and tap-button height, set by size
data-sizesm, default or lg, on the root
data-disabledDisabled state, on the root
data-readonlyRead-only state, on the root
data-slottempo-control, tempo-control-input-group, tempo-control-input, tempo-control-unit, tempo-control-tap

Use class on the root, input and tap button to customize the layout and appearance. Colours follow the standard shadcn theme tokens.

Accessibility

  • The input is labelled "Tempo in beats per minute". Override aria-label, supply aria-labelledby, or pair id with a visible label and remove the default with aria-label={undefined}.
  • Space and Enter activate the focused tap button.
  • Disabled and read-only controls ignore taps. Holding a key does not generate repeated taps.
  • Press feedback respects reduced-motion preferences.
<label for="delay-tempo">Delay tempo</label>
<TempoControl>
	<TempoControlInput id="delay-tempo" aria-label={undefined} />
	<TempoControlTap />
</TempoControl>
FocusKeyAction
InputUp / DownChange by 1 BPM
InputShift + Up / DownChange by largeStep
InputHome / EndSet min / max
Tap buttonSpace / EnterTap once

API reference

TempoControl

PropTypeDefault
value

BPM. Bindable.

number120
onValueChange

details.reason is tap, keyboard or input.

(value, details) => void—
onValueCommit

On a measured tap, a keyboard step, or a typed value on blur.

(value) => void—
min / max

Positive integer BPM bounds; min must not exceed max.

number30 / 600
largeStep

Positive integer increment for Shift + Up / Down.

number10
tapTimeout

Idle milliseconds. Set at least 60000 / min to support the slowest tempo.

number2000
size

Inherits audio configuration.

"sm" | "default" | "lg""default"
disabled / readOnly booleanfalse
name

Name of the numeric form field.

string—

TempoControlInput

Accepts <input> attributes, including id, aria-label, class and a bindable ref.

TempoControlTap

Accepts <button> attributes, including children, class, a bindable ref and disabled. A disabled or read-only root always disables tapping. An onclick handler can cancel a tap with event.preventDefault().

PropTypeDefault
child

Render your own element. Spread props on it.

Snippet<[{ props }]>—
Last updated on November 4, 2026