pnpm add @audio-ui/react
import { Piano } from "@audio-ui/react/piano";| Export | Kind | What it is |
|---|---|---|
Piano.Key | function | One key, placed along the keyboard for its pitch. |
Piano.KeyLabel | function | The name of the key it sits in, such as "C4". |
Piano.Keys | function | Renders children once per key, lowest first: the place to put a Piano.Key for each pitch. |
Piano.Root | function | A keyboard to play: every key sounds while pressed, by pointer or from the keyboard. |
Anatomy
Import the primitive and assemble its parts.
import { Piano } from "@audio-ui/react";
<Piano.Root>
<Piano.Keys>
{(pitch) => (
<Piano.Key pitch={pitch}>
<Piano.KeyLabel />
</Piano.Key>
)}
</Piano.Keys>
</Piano.Root>API reference
Root
A keyboard to play: every key sounds while pressed, by pointer or from the keyboard. Dragging across the keys glides from one to the next, and each pointer holds its own key, so chords can be played on a touch screen. It is laid out like a piano, or with layout="even" as one equal share per key, the way a piano roll's rows are; orientation="vertical" puts the low end at the bottom. The keys are one tab stop, walked with the arrow keys. Renders a <div> element.
Props · 9
eventDetails.cancel() keeps it silent.minPitch…maxPitch.Data attributes · 1
data-disabledKeys
Renders children once per key, lowest first: the place to put a Piano.Key for each pitch. Renders no element of its own.
Props · 1
Key
One key, placed along the keyboard for its pitch. It sounds while pressed: by pointer through the keyboard, or with Enter or Space while focused. Its accessible name defaults to the pitch, such as "C4". Renders a <button> element.
Props · 1
Data attributes · 2
data-activeactiveNotes.data-disabledKeyLabel
The name of the key it sits in, such as "C4". Hidden from assistive technology, which reads the key's own name. Renders a <span> element.
Data attributes · 1
data-disabledStyled
The registry's styled Piano, its usage and interaction: Piano.