ColorPicker

ColorPicker is an input component to select a color.


import { ColorPicker } from 'primeng/colorpicker';

ColorPicker is used as a controlled input with ngModel property.


<p-colorpicker [(ngModel)]="color" />

ColorPicker can also be used with reactive forms. In this case, the formControlName property is used to bind the component to a form control.


<form [formGroup]="formGroup">
    <p-colorpicker formControlName="color" />
</form>

ColorPicker is displayed as a popup by default, add inline property to customize this behavior.


<p-colorpicker [(ngModel)]="color" [inline]="true" />

Default color format to use in value binding is hex and other possible values can be rgb and hsb using the format property.

#6466f1
r:100 g:102 b:241
h:239 s:59 b:95

<p-colorpicker [(ngModel)]="color" inputId="cp-hex" />

<p-colorpicker [(ngModel)]="colorRGB" format="rgb" inputId="cp-rgb" />

<p-colorpicker [(ngModel)]="colorHSB" format="hsb" inputId="cp-hsb" />

When disabled is present, the element cannot be edited and focused.


<p-colorpicker [(ngModel)]="color" [disabled]="true" />

Screen Reader

Specification does not cover a color picker yet and using a semantic native color picker is not consistent across browsers so currently component is not compatible with screen readers. In the upcoming versions, text fields will be introduced below the slider section to be able to pick a color using accessible text boxes in hsl, rgba and hex formats.

Closed State Keyboard Support of Popup ColorPicker

KeyFunction
tabMoves focus to the color picker button.
spaceOpens the popup and moves focus to the color slider.

Popup Keyboard Support

KeyFunction
enterSelects the color and closes the popup.
spaceSelects the color and closes the popup.
escapeCloses the popup, moves focus to the input.

Color Picker Slider

KeyFunction
arrow keysChanges color.

Hue Slider

KeyFunction
up arrowdown arrowChanges hue.