LabDAW

XY Pad

A two-dimensional control for two parameters at once, with pointer, wheel and keyboard input.

Controls two values at once, such as filter cutoff and resonance, pan and mix, or two macros. The registry component is written on the XY pad primitive, which installs with it, and adds a grid, a crosshair, a cursor and a value display.

Overview

  • Input: press or drag on the pad, or use the mouse wheel, a trackpad or the keyboard, on both axes.
  • Axes: X and Y have their own range and step (minX, maxX, stepX; minY, maxY, stepY).
  • Display: grid lines, a crosshair, a cursor and an optional value display. The position is exposed as the CSS variables --xy-pad-x (from the left) and --xy-pad-y (from the top).
  • Accessibility: the cursor holds one native <input type="range"> per axis. Both carry the accessible name (aria-label becomes "… X" and "… Y", or set each with getAriaLabel on the primitive's Thumb). The X input takes focus, and the arrow keys move both axes.

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 a grid, a crosshair, a cursor and a value display, is one command:

The styled component, with size variants and theme styles:

pnpm dlx shadcn@latest add @audio-ui/xypad

Or the primitive alone, to style yourself:

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

Uncontrolled: set only the initial value.

<XYPad
  defaultValue={{ x: 0, y: 0 }}
  maxX={100}
  maxY={1}
  minX={-100}
  minY={-1}
  stepX={1}
  stepY={0.01}
/>

Controlled: drive the value from state.

const [position, setPosition] = useState({ x: 50, y: 50 });

<XYPad
  maxX={100}
  maxY={100}
  minX={0}
  minY={0}
  onValueChange={setPosition}
  onValueCommitted={(value, details) => console.log("Committed:", value, details.reason)}
  value={position}
/>

The primitive alone, part by part:

The parts are a Root that owns the point, a Control that takes the pointer and the wheel, a Thumb that marks the point and holds the two inputs, a Value for the text, and an optional Label. The Thumb is placed for you, from the left edge and the top edge of the Control, and the Root carries the same place as two CSS variables, --xy-pad-x and --xy-pad-y, for a crosshair or a guide. Give the Control its size.

import { useState } from "react";
import { XYPad } from "@/components/audio-ui/xypad/react";

export function Filter() {
  const [point, setPoint] = useState({ x: 25, y: 75 });
  return (
    <XYPad.Root onValueChange={setPoint} value={point}>
      <XYPad.Control className="relative size-40 rounded-md bg-muted">
        <XYPad.Thumb aria-label="Cutoff and resonance" className="absolute size-3 rounded-full bg-primary" />
      </XYPad.Control>
      <XYPad.Value />
    </XYPad.Root>
  );
}

Two inputs, one name

The Thumb holds a native <input type="range"> for each axis. Both carry the name, which is the Thumb's aria-label followed by "X" or "Y" (getAriaLabel(axis) on the Thumb says it in your own words), and the form names <name>.x and <name>.y. Only the X input is in the tab order, and the arrow keys move both axes from it.

Interaction

Pointer

Behavior · 4

Press / drag on pad
A press jumps the value to the pointer; a drag follows it. Reported as eventDetails.reason "press" then "drag".
Clamping
Values always clamp to the configured axis ranges and snap to stepX / stepY.
Commit event
onValueCommitted fires when a gesture that changed the value ends.
Lagging value
While dragging, the cursor follows the pointer even if a controlled value updates late. Reject a value with eventDetails.cancel().

Keyboard

On the focused pad:

Keys · 5

ArrowLeft / ArrowRight
Decrease / increase X by stepX
ArrowUp / ArrowDown
Increase / decrease Y by stepY
Shift + arrow
Move by 10 steps
PageUp / PageDown
Increase / decrease Y by stepY × 10
Home / End
X to minX / maxX

Wheel

Wheel and trackpad input over the pad moves the point by the scrolled distance: scrolling up raises Y, scrolling right raises X. Reported as eventDetails.reason === "wheel".

API reference

Registry component

XYPad accepts style props (size, formatValue, valueDisplay, className) plus the props of the XYPad primitive's Root. aria-label, aria-labelledby, and aria-describedby are forwarded to the axis inputs.

Value and state

Props · 12

Layout and display

Props · 4

The XYPad primitive that installs with it exposes XYPad.Root, XYPad.Control (the pad surface), XYPad.Thumb (positioned at the value, holds the axis inputs), XYPad.Value (formatted <output>), and XYPad.Label. Every part accepts a render prop, className / style as functions of state, and exposes data-disabled / data-dragging. Draw grids and crosshairs with your own elements and the --xy-pad-x / --xy-pad-y variables.

Options

Set on the Root, as props (an attribute in kebab case in the web adapter).

OptionTypeDefault
value, defaultValue{ x, y }the centerThe controlled point, or the starting one. defaultValue is also where a reset returns.
minX, maxX, minY, maxYnumber0, 100The range of each axis.
stepX, stepYnumber1The grid each axis snaps to.
format, localeIntl.NumberFormat options, a localeHow each axis is written, for the Value and the inputs' aria-valuetext.
disabledbooleanfalseTakes no key, wheel or press.
namestringThe form field's name.
onValueChange(point, details) => voidEvery change, which details.cancel() refuses.
onValueCommitted(point, details) => voidThe end of a gesture.

The Value shows both axes as one text, with the separator of the locale. Its content can read formatted.x, formatted.y and value from the state.

What a change reports

details carries what moved the point and how:

  • reason: "press", "drag", "keyboard", "wheel", "input-change" (a typed value) or "reset".
  • source: "mouse", "touch", "pen", "keyboard", "programmatic" or "agent".
  • event: the DOM event behind it, when there is one.
  • cancel(): refuses the change. A controlled pad keeps the point you give it.

In the web adapter, onValueChange is an input event and onValueCommitted a change event, both with detail: { value, reason, source }, where value is the point, and event.preventDefault() refuses a change.

Parts

Parts · 5

Events

Events · 2

Examples

Bipolar ranges (pan and mix style)

Pocket synth

An oscillator, a filter and an XY pad that plays them: drag the pad to sweep the sound.

Wave shaper

Distortion, tone and detune on a synth, with the XY pad and knobs side by side.

For an agent

The pad declares one action, setValue(x, y), 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) sets the point with the source "agent". Each axis is a change of its own, so onValueChange hears two, and an app can refuse either.

Built by Ouest Labs, the source code is available on GitHub.
RSS