ColorPicker

A saturation/brightness area, hue slider, hex input, and optional swatches for picking a color.

Installation

npx dafink-ui add color-picker

Also installs: Input

Demo

Accent color

Props

NameTypeDefaultDescription
valuestring-Controlled hex color (`#rrggbb` or `#rgb`).
onValueChange(hex: string) => void-Called with the new color as lowercase `#rrggbb`.
swatchesstring[]-Preset hex colors rendered as a radio group below the picker.
labelstring-Visible label; names the picker group.
showInputbooleantrueShows the hex input and color preview.
disabledbooleanfalseDisables every part of the picker.
classNamestring''Additional classes merged onto the root. Default width is `w-48`.

Accessibility

ColorPicker is a role="group" named by its label. The saturation/brightness area and the hue bar are each a role="slider" in the normal Tab order with a spoken aria-valuetext (e.g. "Saturation 72%, brightness 96%", "217 degrees"), so every color is reachable without a pointer. The hex field is a native input. Swatches are a radiogroup using roving tabindex: one Tab stop for the whole set, arrow keys move focus, and Enter or Space selects. The selected swatch shows an offset ring, not just its fill, so selection doesn't rely on color alone.

KeyFunction
left arrowArea: lowers saturation by 1%. Hue: rotates hue back 1 degree.
right arrowArea: raises saturation by 1%. Hue: rotates hue forward 1 degree.
up arrowArea: raises brightness by 1%. Hue: rotates hue forward 1 degree.
down arrowArea: lowers brightness by 1%. Hue: rotates hue back 1 degree.
shift+arrowMoves in steps of 10 instead of 1.
homeHue: jumps to 0 degrees. Swatches: focuses the first swatch.
endHue: jumps to 360 degrees. Swatches: focuses the last swatch.
enterHex field: applies the typed color. Swatches: selects the focused swatch.
spaceSwatches: selects the focused swatch.