ColorPicker
A saturation/brightness area, hue slider, hex input, and optional swatches for picking a color.
Installation
npx dafink-ui add color-pickerAlso installs: Input
Demo
Accent color
Props
| Name | Type | Default | Description |
|---|---|---|---|
| value | string | - | Controlled hex color (`#rrggbb` or `#rgb`). |
| onValueChange | (hex: string) => void | - | Called with the new color as lowercase `#rrggbb`. |
| swatches | string[] | - | Preset hex colors rendered as a radio group below the picker. |
| label | string | - | Visible label; names the picker group. |
| showInput | boolean | true | Shows the hex input and color preview. |
| disabled | boolean | false | Disables every part of the picker. |
| className | string | '' | 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.
| Key | Function |
|---|---|
| left arrow | Area: lowers saturation by 1%. Hue: rotates hue back 1 degree. |
| right arrow | Area: raises saturation by 1%. Hue: rotates hue forward 1 degree. |
| up arrow | Area: raises brightness by 1%. Hue: rotates hue forward 1 degree. |
| down arrow | Area: lowers brightness by 1%. Hue: rotates hue back 1 degree. |
| shift+arrow | Moves in steps of 10 instead of 1. |
| home | Hue: jumps to 0 degrees. Swatches: focuses the first swatch. |
| end | Hue: jumps to 360 degrees. Swatches: focuses the last swatch. |
| enter | Hex field: applies the typed color. Swatches: selects the focused swatch. |
| space | Swatches: selects the focused swatch. |