Lab

Piano

The headless Piano of @audio-ui/react: its parts, what each renders and owns, and their props.

pnpm add @audio-ui/react
import { Piano } from "@audio-ui/react/piano";
ExportKindWhat it is
Piano.KeyfunctionOne key, placed along the keyboard for its pitch.
Piano.KeyLabelfunctionThe name of the key it sits in, such as "C4".
Piano.KeysfunctionRenders children once per key, lowest first: the place to put a Piano.Key for each pitch.
Piano.RootfunctionA 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

Data attributes · 1

data-disabled
Present when disabled.

Keys

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-active
Whether the key is sounding: pressed here, or listed in activeNotes.
data-disabled
Present when disabled.

KeyLabel

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-disabled
Present when disabled.

Styled

The registry's styled Piano, its usage and interaction: Piano.

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