color-picker

Form-associated color picker with HSL color space, hue slider, hex/RGB inputs, preset swatches, and EyeDropper API.

Overview

The <color-picker> component wraps a native <input type="color"> and replaces the limited browser picker with a full color space UI. It features a saturation/lightness area, hue slider, hex and RGB text inputs, preset swatches from a <datalist>, and EyeDropper API integration.

Attributes

Attribute Type Default Description
name string Form field name for submission.
disabled boolean false Disables the picker.
required boolean false Marks the field as required for form validation.

Preset Swatches

Add a <datalist> child with <option> elements to provide a row of preset color swatches.

EyeDropper

On supported browsers, a pipette button appears that opens the EyeDropper API to pick any color from the screen. The button is hidden on browsers that don’t support the API.

Form Integration

The component is form-associated via ElementInternals and works inside <form-field> for validation. The submitted value is always a 7-character hex string (e.g. #6366f1).

Keyboard

Color area (saturation/lightness)

Key Action
Arrow Left / Arrow Right Adjust saturation by 1% (Shift: 10%).
Arrow Up / Arrow Down Adjust lightness by 1% (Shift: 10%).

Hue slider

Key Action
Arrow Left / Arrow Right Adjust hue by 1° (Shift: 10°).

Events

Event Detail Description
color-picker:change { hex, rgb, hsl } Fired when the color changes. rgb is { r, g, b } (0–255). hsl is { h, s, l } (h: 0–360, s/l: 0–100).
color-picker:open Fired when the panel opens.
color-picker:close Fired when the panel closes.

Accessibility

The trigger button uses aria-haspopup="dialog" and aria-expanded. The panel is role="dialog" with an accessible label. The color area uses role="slider" with aria-valuetext describing saturation and lightness percentages. The hue strip uses role="slider" with aria-valuenow for the hue degree. Preset swatches use role="listbox" with individual role="option" buttons. Text inputs provide direct numeric entry for users who prefer precision over the visual interface.