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
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | — | Selected hex color value (e.g., "#4f46e5") |
onChange | (color: string) => void | — | Callback when color changes |
label | string | — | Label text above the picker |
presetColors | string[] | [18 colors] | Array of preset hex colors |
showInput | boolean | true | Show hex input field in dropdown |
disabled | boolean | false | Disable the color picker |
className | string | — | 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 labelsKeyboard Navigation
| Key | Action |
|---|---|
| Tab | Move between trigger, swatch grid (one tab stop) and inputs |
| Enter / Space | Open or close the dropdown |
| Arrow Left / Right | Select the previous / next swatch (wraps) |
| Arrow Up / Down | Select the swatch in the row above / below |
| Home / End | Select the first / last swatch |
| Escape | Close 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