ColorPicker is an input component to select a color.
import { ColorPicker } from '@mantle-ui/react/colorpicker';
ColorPicker is used as a controlled input with value and onChange properties.
<ColorPicker value={color} onChange={(e) => setColor(e.value)} />
ColorPicker is displayed as a popup by default, add inline property to customize this behavior.
<ColorPicker value={color} onChange={(e) => setColor(e.value)} inline />
Default color format to use in value binding is hex and other possible values can be rgb and hsb using the format property.
<ColorPicker format="hex" value={colorHEX} onChange={(e) => setColorHEX(e.value)} />
<ColorPicker format="rgb" value={colorRGB} onChange={(e) => setColorRGB(e.value)} />
<ColorPicker format="hsb" value={colorHSB} onChange={(e) => setColorHSB(e.value)} />
Enable alpha to add an opacity slider and a checkerboard transparency preview. It defaults to false, preserving the existing six-digit hex and RGB/HSB value contracts.
| Format | Value with alpha enabled |
|---|---|
| hex | Accepts six-digit RRGGBB or eight-digit RRGGBBAA, with an optional leading #. Emits lowercase RRGGBBAA without #. AA ranges from 00 (transparent) to ff (opaque), rounded to the nearest byte. |
| rgb | { r, g, b, a }, with each RGB channel from 0 to 255 and a from 0 (transparent) to 1 (opaque). |
| hsb | { h, s, b, a }, with hue from 0 to 360, saturation and brightness from 0 to 100, and the same 0-1 alpha range. |
Six-digit hex and objects without a are opaque. Missing or non-finite object alpha defaults to 1; finite alpha is clamped to the 0–1 range. The hex defaultColor follows the same six/eight-digit rules in every format.
Color and hue changes preserve alpha, including zero and supplied object precision. Opacity-only edits preserve the supplied RGB channels or hex RGB bytes. The slider displays the nearest whole percent and edits in 1% steps, emitting a = percent / 100 for objects. For example, 50% emits a: 0.5 or hex suffix 80; byte 80 represents 128/255, approximately 50.196%. These representations therefore have different precision.
Update value from onChange as with the existing controlled picker. External value, format, alpha and defaultColor changes refresh the control without emitting a change event. Both disabled and readOnlyprevent color, hue and opacity edits. Use alphaLabel to translate the visible and accessible opacity label.
6466f180{"r":100,"g":102,"b":241,"a":0.5}{"h":239,"s":59,"b":95,"a":0.5}
<ColorPicker alpha value={hex} onChange={(e) => setHex(e.value)} />
<ColorPicker alpha inline format="rgb" value={rgb} onChange={(e) => setRgb(e.value)} />
<ColorPicker alpha format="hsb" value={hsb} onChange={(e) => setHsb(e.value)} />
When disabled is present, the element cannot be edited and focused.
<ColorPicker disabled />
Use readOnly to prevent color, hue and opacity changes. The popup preview remains focusable and its panel can be opened for inspection.
<ColorPicker alpha readOnly value="6466f180" />
Provide a label for the popup preview using inputId and a matching label element, or use aria-label. With alpha enabled, opacity uses a native range input with a default accessible name of Opacity, a range of 0–100 and a percentage value. Customize its visible and accessible label with alphaLabel, or provide attributes through pt.alphaSlider.
The existing saturation/brightness area and hue strip use pointer and touch interaction and do not yet provide keyboard or screen reader color selection. The accessible opacity control does not make the entire color picker keyboard accessible.
| Key | Function |
|---|---|
| Tab | Moves focus to the preview. With an alpha popup open, moves from the preview to opacity, then closes the popup and moves to the next control. |
| Space | With alpha enabled, opens the popup and moves focus to opacity. Otherwise, toggles the popup. |
| Enter | With alpha enabled, opens the popup and moves focus to opacity. |
| Escape | Closes the popup. From opacity, restores focus to the preview. |
| Shift + Tab from opacity | Closes the popup and returns focus to the preview. |
Opacity is available in inline and popup modes. The native range input supports these keys:
| Key | Function |
|---|---|
| Right / Up arrow | Increases opacity by one percentage point. |
| Left / Down arrow | Decreases opacity by one percentage point. |
| Home / End | Sets opacity to 0% / 100%. |
Disabled pickers cannot be focused or edited. Read-only pickers keep the popup preview focusable and allow the popup to be inspected, while blocking color, hue and opacity edits.