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
valuestringSelected hex color value (e.g., "#4f46e5")
onChange(color: string) => voidCallback when color changes
labelstringLabel text above the picker
presetColorsstring[][18 colors]Array of preset hex colors
showInputbooleantrueShow hex input field in dropdown
disabledbooleanfalseDisable the color picker
classNamestringAdditional 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
  • Dark mode: Full dark mode support

Accessibility

Accessibility considerations

ARIA Attributes

Trigger button is focusablePreset colors are individual buttonsHex input has proper input semantics

Keyboard Navigation

KeyAction
TabNavigate to trigger button
Enter / SpaceOpen color picker dropdown
EscapeClose dropdown

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