Color Picker

Color Picker

Forms
Selection

Select colors from a preset palette or enter custom hex values. Features color preview, native color picker integration, and input validation.

Preview

Color selection with preset palette and hex input

Without Hex Input

Only preset colors, no manual hex input

Custom Preset Colors

Custom color palette for specific use cases

Disabled State

Color picker in disabled state

Props

ColorPicker component API reference

PropTypeDefaultDescription
valuestring—Selected hex color value (e.g., "#4f46e5")
onChange(color: string) => void—Callback when color changes
labelstring—Label text above the picker
presetColorsstring[][18 colors]Array of preset hex colors
showInputbooleantrueShow hex input field in dropdown
disabledbooleanfalseDisable the color picker
classNamestring—Additional CSS classes

Usage

Import and implementation example

import { ColorPicker } from '@/components/ui/color-picker'
export default function Example() {
const [color, setColor] = useState('#4f46e5')
return (
<>
{/* Basic usage */}
<ColorPicker
label="Brand Color"
value={color}
onChange={setColor}
/>
{/* Without hex input */}
<ColorPicker
label="Theme Color"
value={color}
onChange={setColor}
showInput={false}
/>
{/* Custom preset colors */}
<ColorPicker
label="Accent Color"
value={color}
onChange={setColor}
presetColors={['#ef4444', '#f97316', '#14b8a6', '#3b82f6']}
/>
</>
)
}

Features

Built-in functionality

  • 18 preset colors: Organized 6x3 grid of common colors
  • Large color preview: Preview area shows selected color
  • Hex input with validation: Manual hex entry with format validation
  • Native color picker: Integration with browser color picker
  • Click outside to close: Dropdown closes on outside click
  • Customizable presets: Define your own preset color palette

Accessibility

Accessibility considerations

ARIA Attributes

Trigger has aria-haspopup, aria-expanded and aria-controlsPreset swatches form a radiogroup, the current color has aria-checked="true"Each swatch is named by its hex value, for example "#3B82F6"Hex input and native color input have accessible labels

Keyboard Navigation

KeyAction
TabMove between trigger, swatch grid (one tab stop) and inputs
Enter / SpaceOpen or close the dropdown
Arrow Left / RightSelect the previous / next swatch (wraps)
Arrow Up / DownSelect the swatch in the row above / below
Home / EndSelect the first / last swatch
EscapeClose the dropdown and return focus to the trigger

Notes

  • Selected color shown as visual indicator with ring
  • Hex value displayed in monospace font for clarity
  • Color preview helps users with color identification

Related Components