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-labelbecomes "… X" and "… Y", or set each withgetAriaLabelon the primitive'sThumb). 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:
Copy to Clipboardpnpm dlx shadcn@latest add @audio-ui/xypad
Or the primitive alone, to style yourself:
Copy to Clipboardpnpm 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:
Copy to Clipboardpnpm dlx shadcn@latest add @audio-ui/primitives-css
Usage
Copy to Clipboardimport { XYPad } from "@/components/audio-ui/xypad";
Uncontrolled: set only the initial value.
Copy to Clipboard<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.
Copy to Clipboardconst [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.
Copy to Clipboardimport { 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
eventDetails.reason "press" then "drag".stepX / stepY.onValueCommitted fires when a gesture that changed the value ends.value updates late. Reject a value with eventDetails.cancel().Keyboard
On the focused pad:
Keys · 5
stepXstepYstepY × 10minX / maxXWheel
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
XYPad.Value and the inputs' aria-valuetext.format.Layout and display
Props · 4
"hidden" to hide the overlay.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).
| Option | Type | Default | |
|---|---|---|---|
value, defaultValue | { x, y } | the center | The controlled point, or the starting one. defaultValue is also where a reset returns. |
minX, maxX, minY, maxY | number | 0, 100 | The range of each axis. |
stepX, stepY | number | 1 | The grid each axis snaps to. |
format, locale | Intl.NumberFormat options, a locale | How each axis is written, for the Value and the inputs' aria-valuetext. | |
disabled | boolean | false | Takes no key, wheel or press. |
name | string | The form field's name. | |
onValueChange | (point, details) => void | Every change, which details.cancel() refuses. | |
onValueCommitted | (point, details) => void | The 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
@value-change. Web: the input event.@value-committed. Web: the change event.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.