Directory
- Welcome
Color Picker Component
The Color Picker component provides an intuitive interface for color selection with support for multiple color formats, eyedropper functionality, and color history. Built with accessibility and user experience in mind, it offers rich functionality including format switching, opacity control, and keyboard navigation.
Key Features
-
Multiple Color Formats: Support for HEX, RGB, RGBA, HSL, and HSLA
-
Eyedropper Tool: Pick colors from anywhere on screen
-
Color History: Track and reuse recently selected colors
-
Keyboard Navigation: Full keyboard support with intuitive controls
-
Accessibility: ARIA compliance and screen reader support
Basic Usage
<ColorPicker label="Choose a color" />
Size Variants
The color picker supports different size variants through the size
prop.
<ColorPicker size="sm" /><ColorPicker size="default" /><ColorPicker size="lg" />
Color Picker Panel Directly on the page
<ColorPickerPanel isModal={false} />
Required Field
Add the required
prop to mark the color picker as a required field.
<ColorPicker required label="Required Color" />
Initial Value
Set an initial color using the value
prop.
<ColorPicker value="#ff00FF1e" />
Custom Event Listeners
You can listen to the change custom event emitted by the color picker component:
Waiting for events to be emitted… (Click on the color picker to see the events)
CustomEvent<{ id?: string; // id of the color picker name?: string; // name of the hidden input color: string; // selected color in current format format: 'hex' | 'rgb' | 'rgba' | 'hsl' | 'hsla'; // current color format}>;
Color Picker Props API
Prop | Type | Default | Description |
---|---|---|---|
id | string | Unique identifier for the color picker | |
label | string | Label text for the color picker | |
required | boolean | false | Mark field as required |
size | sm | default | lg | default | Size variant of the color picker |
value | string | #ffffff | Initial color value |
variant | default | default | Visual style variant |
Error State
The color picker component supports an error state. Set the data-state
attribute to error
to indicate validation errors.
<ColorPicker data-state="error" />
Keyboard Navigation
Key | Action |
---|---|
Space/Enter | Open/close color picker + select color |
Tab | Navigate through controls |
Arrow Keys | Adjust color values |
Escape | Close color picker |
Limited Time Launch Sale
Add professional color selection to your web applications with our Color Picker component. Get our AstroJS starter template now!
GET 60% OFF!