Forms
ColorPicker
Free26.6 KB gzippedAn inline color picker: a 2D saturation / brightness area, a hue slider, an optional opacity slider, a text field, optional preset swatches, and an eyedropper (when the browser supports it).
Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Arrow Left, Arrow Right, Arrow Up and 8 more · Full report
Import
import { ColorPicker, ColorInput } from "@vjdesigns/vjdesigns-ui";
Importing only ColorPicker adds about 26.6 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Panel
The full picker: a saturation area, hue slider, text input and optional swatches.
Selected: #7c3aed
import { useState } from "react";
import { ColorPicker, Stack, Text } from "@vjdesigns/vjdesigns-ui";
export function Panel() {
const [color, setColor] = useState("#7c3aed");
return (
<Stack gap={3} align="center">
<ColorPicker
aria-label="Brand color"
value={color}
onValueChange={setColor}
swatches={["#007db9", "#7c3aed", "#047857", "#a16207", "#c21f1f", "#111111"]}
/>
<Text size="sm" tone="muted">
Selected: <code>{color}</code>
</Text>
</Stack>
);
}
Color field
ColorInput is a compact field that opens the picker in a popover.
import { ColorInput, Field } from "@vjdesigns/vjdesigns-ui";
export function ColorField() {
return (
<div style={{ width: "100%", maxWidth: "18rem" }}>
<Field label="Accent color">
<ColorInput defaultValue="#047857" fullWidth />
</Field>
</div>
);
}
With alpha
alpha adds an opacity slider; format picks how the value is written.
import { ColorPicker } from "@vjdesigns/vjdesigns-ui";
export function WithAlpha() {
return <ColorPicker aria-label="Overlay color" alpha format="rgb" defaultValue="rgba(11, 17, 24, 0.55)" />;
}
Accessibility
The saturation and brightness area is two native sliders sharing one Tab stop: Left / Right change saturation, Up / Down brightness. Every slider also says the color in words ("dark blue"), so the choice doesn't rely on seeing it.
Value: #1d4ed8
import { useState } from "react";
import { ColorPicker, Field, Stack, Text } from "@vjdesigns/vjdesigns-ui";
export function Accessibility() {
const [color, setColor] = useState("#1d4ed8");
return (
<Stack gap={3} align="center">
<Field label="Brand color">
<ColorPicker value={color} onValueChange={setColor} />
</Field>
<Text size="sm" tone="muted">
Value: <code>{color}</code>
</Text>
</Stack>
);
}
Translated
Slider names, color descriptions ("bleu foncé"), the eyedropper and error messages come from the locale (French here).
import { ColorPicker, Field, LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import fr from "@vjdesigns/vjdesigns-ui/locales/fr";
export function Translated() {
return (
<LocaleProvider locale="fr" messages={fr}>
<Field label="Couleur de l'équipe">
<ColorPicker defaultValue="#047857" swatches={["#047857", "#b91c1c", "#1d4ed8", "#7c3aed"]} />
</Field>
</LocaleProvider>
);
}
Right to left
The first example again, inside a right-to-left LocaleProvider (Arabic). Layout, spacing and arrow icons mirror, and the components' built-in text is translated. The example's own text stays in English.
Panel
Selected: #7c3aed
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";
// Panel is the "Panel" example above.
<LocaleProvider locale="ar" messages={ar}>
<Panel />
</LocaleProvider>
Usage notes
2D area pattern. The area is a group ("Saturation and brightness", aria-roledescription="2D slider") holding two visually hidden native range inputs, Saturation and Brightness, that share one tab stop and one visible thumb. Each reports its own value plus a plain color description ("Brightness 40%, dark blue"), so a screen reader's adjust gesture works on either axis. Left / Right change saturation and Up / Down brightness (Shift: 10 at a time), with focus following the axis; PageUp / PageDown change brightness by 10; Home / End go to the ends of the focused axis (on Brightness: pure black or white).
Hue and opacity are role="slider" thumbs with Arrows (+/-1, Shift +/-10), PageUp / PageDown (+/-10), and Home / End. Clicking any track or the area jumps there; dragging uses pointer capture.
Text field accepts any supported format and validates on blur or Enter. An invalid value shows an error (icon plus text, announced politely) and reverts to the last valid color. Escape discards the edit.
Inside a Field, the Field's label names the group (and, with the format word, the text field); hint, error, invalid, disabled, read-only, and size are wired automatically.
API reference
ColorPicker
| Prop | Type | Default |
|---|---|---|
variantPanel surface or plain. | "panel""plain" | "panel" |
swatchesOnlyShow only the swatch palette (plus the hidden form input), without the area, sliders, and text field. Requires | boolean | false |
aria-labelAccessible name of the group when there's no visible label. Inside a Field, the Field's label is used. | string | — |
aria-labelledbyid of a visible label for the group. Inside a Field, the Field's label is used. | string | — |
valueControlled color string in any supported format ( | string | — |
defaultValueInitial color when uncontrolled. | string | "#1d4ed8" |
onValueChangeCalled with the formatted color string on every change (drag, key press, swatch, typed value). | (color: string) => void | — |
onValueCommitCalled once an interaction ends: pointer up, key up, swatch pick, eyedropper pick, or a committed typed value. Use it for expensive work. | (color: string) => void | — |
formatFormat of the emitted string. | "hex""rgb""hsl" | "hex" |
alphaEnables the opacity slider and alpha output. Alpha is written only when it is below 1 ( | boolean | false |
swatchesPreset colors, shown as a radio group of swatches. Unparseable entries are skipped. | string[] | — |
eyeDropperShow the eyedropper button when the browser supports the EyeDropper API (hidden otherwise). | boolean | true |
sizeControl size. Picks up a surrounding Field's size. | "sm""md""lg" | "md" |
disabledDisables every part. Picked up from a surrounding Field. | boolean | — |
readOnlyEvery part stays focusable and announces its value, but the color can't change. Picked up from a surrounding Field. | boolean | — |
invalidInvalid styling and | boolean | — |
nameForm field name. Renders an | string | — |
labelsOverride any built-in string. | Partial<ColorPickerLabels> | — |
Also accepts native <div> attributes, plus className, style and ref.
ColorInput
A pill field showing a swatch and the color value; pressing it opens a ColorPicker in a Popover (a non-modal dialog on the shared overlay layer stack: Escape and outside presses close it, focus returns to the field). Takes the same value, format, alpha, swatch, and state props as ColorPicker.
The trigger is a native <button> with aria-haspopup="dialog" and aria-expanded. Its name is the label plus the current value and a plain description ("Jersey color, #1d4ed8, dark blue"). Inside a Field, the label, hint, error, invalid, disabled, and read-only state are wired to it. A read-only field still opens, so the values can be inspected.
| Prop | Type | Default |
|---|---|---|
openControlled open state of the picker popover. | boolean | — |
defaultOpenInitial open state when uncontrolled. | boolean | false |
onOpenChangeCalled with the next open state. | (open: boolean) => void | — |
placementWhere the popover opens. Flips when there isn't room. | "top""top-start""top-end""bottom""bottom-start""bottom-end""left""left-start""left-end""right""right-start""right-end" | "bottom-start" |
sizeSize of the pill field and the picker. Picks up a surrounding Field's size. | "sm""md""lg" | "md" |
fullWidthStretch the field to fill its container. | boolean | false |
dialogLabelAccessible name of the picker popover. | string | "Choose a color" |
aria-labelAccessible name when there's no visible label. Inside a Field, the Field's label is used. The current color is always appended. | string | — |
aria-labelledbyid of a visible label. Inside a Field, the Field's label is used. | string | — |
valueControlled color string in any supported format ( | string | — |
defaultValueInitial color when uncontrolled. | string | "#1d4ed8" |
onValueChangeCalled with the formatted color string on every change (drag, key press, swatch, typed value). | (color: string) => void | — |
onValueCommitCalled once an interaction ends: pointer up, key up, swatch pick, eyedropper pick, or a committed typed value. Use it for expensive work. | (color: string) => void | — |
formatFormat of the emitted string. | "hex""rgb""hsl" | "hex" |
alphaEnables the opacity slider and alpha output. Alpha is written only when it is below 1 ( | boolean | false |
swatchesPreset colors, shown as a radio group of swatches. Unparseable entries are skipped. | string[] | — |
eyeDropperShow the eyedropper button when the browser supports the EyeDropper API (hidden otherwise). | boolean | true |
disabledDisables every part. Picked up from a surrounding Field. | boolean | — |
readOnlyEvery part stays focusable and announces its value, but the color can't change. Picked up from a surrounding Field. | boolean | — |
invalidInvalid styling and | boolean | — |
nameForm field name. Renders an | string | — |
labelsOverride any built-in string. | Partial<ColorPickerLabels> | — |
Also accepts native <button> attributes, plus className, style and ref.
See what changed in each version in the Changelog.
Accessibility report
ColorPicker targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10038 passed · 0 failed · 27 not applicable · 10 to check by hand
Dark mode
Score 10038 passed · 0 failed · 27 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
| Key | Action |
|---|---|
| Arrow LeftArrow Right | On the area: changes saturation (Shift: by 10). |
| Arrow UpArrow Down | On the area: changes brightness (Shift: by 10). |
| Page UpPage Down | Changes brightness, hue or opacity by 10. |
| HomeEnd | Moves the focused axis or slider to its ends. |
| Arrow keys | On hue and opacity: ±1 (Shift: ±10). On swatches: next or previous, wrapping, and selects. |
| Enter | In the text field: applies the typed color. |
| Escape | In the text field: discards the edit. |
Roles and states
| Element | Role | States and properties |
|---|---|---|
| Picker | group | aria-label |
| 2D area | group | aria-roledescription="2D slider"; holds Saturation and Brightness range inputs with aria-valuetext ("Brightness 40%, dark blue") |
| Hue, opacity | slider | aria-valuenow, aria-valuemin, aria-valuemax, aria-valuetext |
| Swatches | radiogroup / radio | aria-checked, aria-label (color name and hex) |
| Invalid text | none | Error announced through aria-live="polite" |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |