Skip to content
nexubDesign System
v11.9.0

Components · Form Controls

Color Picker

AlphaAdded v11.2.0

Pick a colour from swatches or type a hex, with an optional contrast hint against a background.

import { ColorPicker } from '@nexub/react';
View as Markdown

Usage

Use it for
  • Brand, label or theme colours from a small palette.

  • A text or accent colour that must stay readable on a known background (`contrastAgainst`).

Use something else for
  • Free-form colour mixing (hue, saturation, alpha): not covered.

  • A few named options where the colour is incidental: use Select or RadioGroup.

Playground

Props

size
TSX
<ColorPicker aria-label="Label colour" value={color} onValueChange={setColor} />

Examples

Default

Contrast hint

Named swatches

States

  • default
  • disabled
  • invalid
  • readOnly
  • size="sm"
  • size="md"
  • size="lg"

Props

Props
PropTypeDefaultDescription
valuestring—The colour as #rrggbb.
defaultValuestring'#000000'The colour as #rrggbb.
onValueChange((hex: string) => void)—Called with a lowercase #rrggbb.
swatchesColorSwatch[]neutrals and huesThe colours offered. A label is read out instead of the hex. Defaults to neutrals and hues.
contrastAgainststring—A background hex: shows the WCAG 2.x contrast ratio and whether it passes AA for text (4.5:1).
disabledboolean—Field states. Read-only stays focusable but does not open.
readOnlyboolean—Field states. Read-only stays focusable but does not open.
invalidboolean—Field states. Read-only stays focusable but does not open.
namestring—A hidden input posts the value with a plain form.
size'sm' | 'md' | 'lg''md'Height of the trigger.
sheetfalse | true | 'auto''auto' (a bottom sheet below 768px)The popover as a bottom sheet below 768px.
aria-describedbystring—
aria-invalidfalse | true | 'true' | 'false'—
aria-labelstring—
aria-labelledbystring—
classNamestring—
idstring—

Accessibility

Keyboard

  • Enter / Space

    Opens the popover with focus on the picked swatch.

  • Arrow keys

    Move between swatches and pick (six per row).

  • Home / End

    First and last swatch.

  • Tab

    Moves to the hex field. Enter or leaving it applies the hex.

  • Escape

    Closes the popover.

Notes

  • The trigger is a `combobox` named by `aria-label`; its text is the hex.

  • Swatches are a `radiogroup` with one tab stop. An invalid hex keeps the last colour and marks the field invalid.

  • The contrast hint is announced politely when it changes.

On iOS & Android