Skip to content
Vertical Jump Designs-uiFront-End Studio
Get Pro

v3.9 is out.

Forms

ColorPicker

Free26.6 KB gzipped

An 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

tsx
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.

Color value, HEX
Preset colors

Selected: #7c3aed

tsx
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.

tsx
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.

Color value, RGB
tsx
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.

Color value, HEX

Value: #1d4ed8

tsx
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).

Valeur de la couleur, HEX
Couleurs prédéfinies
tsx
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

قيمة اللون, HEX
ألوان جاهزة

Selected: #7c3aed

tsx
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

ColorPicker props
PropTypeDefault
variant

Panel surface or plain.

"panel""plain""panel"
swatchesOnly

Show only the swatch palette (plus the hidden form input), without the area, sliders, and text field. Requires swatches.

booleanfalse
aria-label

Accessible name of the group when there's no visible label. Inside a Field, the Field's label is used.

string—
aria-labelledby

id of a visible label for the group. Inside a Field, the Field's label is used.

string—
value

Controlled color string in any supported format (#rgb, #rrggbb, #rrggbbaa, rgb(), rgba(), hsl(), hsla()).

string—
defaultValue

Initial color when uncontrolled.

string"#1d4ed8"
onValueChange

Called with the formatted color string on every change (drag, key press, swatch, typed value).

(color: string) => void—
onValueCommit

Called 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—
format

Format of the emitted string.

"hex""rgb""hsl""hex"
alpha

Enables the opacity slider and alpha output. Alpha is written only when it is below 1 (#rrggbbaa, rgba(), hsla()). Without it, any alpha in the value is ignored.

booleanfalse
swatches

Preset colors, shown as a radio group of swatches. Unparseable entries are skipped.

string[]—
eyeDropper

Show the eyedropper button when the browser supports the EyeDropper API (hidden otherwise).

booleantrue
size

Control size. Picks up a surrounding Field's size.

"sm""md""lg""md"
disabled

Disables every part. Picked up from a surrounding Field.

boolean—
readOnly

Every part stays focusable and announces its value, but the color can't change. Picked up from a surrounding Field.

boolean—
invalid

Invalid styling and aria-invalid. Picked up from a surrounding Field (pass error to the Field).

boolean—
name

Form field name. Renders an <input type="hidden"> holding the formatted color.

string—
labels

Override 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.

ColorInput props
PropTypeDefault
open

Controlled open state of the picker popover.

boolean—
defaultOpen

Initial open state when uncontrolled.

booleanfalse
onOpenChange

Called with the next open state.

(open: boolean) => void—
placement

Where 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"
size

Size of the pill field and the picker. Picks up a surrounding Field's size.

"sm""md""lg""md"
fullWidth

Stretch the field to fill its container.

booleanfalse
dialogLabel

Accessible name of the picker popover.

string"Choose a color"
aria-label

Accessible name when there's no visible label. Inside a Field, the Field's label is used. The current color is always appended.

string—
aria-labelledby

id of a visible label. Inside a Field, the Field's label is used.

string—
value

Controlled color string in any supported format (#rgb, #rrggbb, #rrggbbaa, rgb(), rgba(), hsl(), hsla()).

string—
defaultValue

Initial color when uncontrolled.

string"#1d4ed8"
onValueChange

Called with the formatted color string on every change (drag, key press, swatch, typed value).

(color: string) => void—
onValueCommit

Called 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—
format

Format of the emitted string.

"hex""rgb""hsl""hex"
alpha

Enables the opacity slider and alpha output. Alpha is written only when it is below 1 (#rrggbbaa, rgba(), hsla()). Without it, any alpha in the value is ignored.

booleanfalse
swatches

Preset colors, shown as a radio group of swatches. Unparseable entries are skipped.

string[]—
eyeDropper

Show the eyedropper button when the browser supports the EyeDropper API (hidden otherwise).

booleantrue
disabled

Disables every part. Picked up from a surrounding Field.

boolean—
readOnly

Every part stays focusable and announces its value, but the color can't change. Picked up from a surrounding Field.

boolean—
invalid

Invalid styling and aria-invalid. Picked up from a surrounding Field (pass error to the Field).

boolean—
name

Form field name. Renders an <input type="hidden"> holding the formatted color.

string—
labels

Override 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)

Running accessibility audit

Checking the examples above…

Lighthouse audit

Light mode

Score 100

38 passed · 0 failed · 27 not applicable · 10 to check by hand

Dark mode

Score 100

38 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

Keyboard
KeyAction
Arrow LeftArrow RightOn the area: changes saturation (Shift: by 10).
Arrow UpArrow DownOn the area: changes brightness (Shift: by 10).
Page UpPage DownChanges brightness, hue or opacity by 10.
HomeEndMoves the focused axis or slider to its ends.
Arrow keysOn hue and opacity: ±1 (Shift: ±10). On swatches: next or previous, wrapping, and selects.
EnterIn the text field: applies the typed color.
EscapeIn the text field: discards the edit.

Roles and states

Roles and states
ElementRoleStates and properties
Pickergrouparia-label
2D areagrouparia-roledescription="2D slider"; holds Saturation and Brightness range inputs with aria-valuetext ("Brightness 40%, dark blue")
Hue, opacityslideraria-valuenow, aria-valuemin, aria-valuemax, aria-valuetext
Swatchesradiogroup / radioaria-checked, aria-label (color name and hex)
Invalid textnoneError announced through aria-live="polite"

Manual checks

Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.

Manual accessibility checks
CheckWhat to testWCAG 2.2
KeyboardEvery 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)
FocusFocus 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 readersNames, 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)
ColorMeaning 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 reflowAt 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 targetsClick 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)
MotionAnimations respect the reduced-motion setting.2.3.3 (AAA)