Color picker

A color field: type a hex, rgb() or hsl() color, or pick one from a saturation and brightness area, a hue slider, an optional opacity slider and preset swatches.

  • vig-color-picker
Import
import { ColorPicker } from '@vigdx/ui/color-picker';

Basic

Bind [(value)] to a string | null signal. The swatch button opens the picker in a panel; the text field next to it takes a typed color, updating the value as soon as it reads as one.

Brand color

Value: #2b5ce6

Inline, opacity and presets

mode="inline" shows the picker in place. alpha adds an opacity slider and writes translucent colors with an alpha part ( #rrggbbaa ). presets adds one-click swatches; give them a label for screen readers. Where the browser has the EyeDropper API (Chromium), a button samples a color from the screen.

Highlight

Value: #2b5ce6cc

Formats

format is the format the value is written in: hex (default), rgb or hsl . The text field accepts all three syntaxes, comma or space separated, whatever the format. Typing writes the color at once; leaving the field never rewrites a value, so #F00 set from code stays #F00 until the user changes it. Without alpha the colors the user picks or types are written opaque.

RGB

HSL with opacity

rgb(17, 117, 79) · hsla(262, 83%, 58%, 0.8)

Sizes and states

size sets the field height ( sm , md , lg ). readonly keeps the text selectable but the picker closed; disabled turns everything off.

Small

Read-only

Disabled

Signal Forms

vig-color-picker implements FormValueControl<string | null> . Text that is not a color shows its own error at once and never reaches the model.

Label color

Required

Valid: no · none

Reactive Forms

Import VigValueAccessor next to the component to use formControlName , [formControl] or ngModel .

Background

#f7f8fa · pristine

Native alternative

When an opaque hex color is all you need and the browser's own picker is acceptable, a labelled <input type="color"> is the lighter choice: it is keyboard and screen-reader accessible by default and opens the platform's picker. It has no opacity, no presets and no typed entry on most platforms, and its look varies by browser, which is what vig-color-picker adds.

Styling hooks

Internal elements carry a stable data-part and the component's data-scope; both are public API, so removing one is a breaking change. Select a part by both, e.g. [data-scope="color-picker"][data-part="label"] { … }: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through aria-* and, where listed, a data-state; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other data-* attributes listed below (such as data-opening while an overlay animates) are API too. See Customizing.

Scope: [data-scope="color-picker"]

ColorPicker styling hooks
Part Element data-state
label The visible label. —
field The bordered row of the swatch (button) and the text field. —
trigger The swatch button that opens the panel ( mode="popup" ). open, closed
swatch The current color over a checkerboard; empty without a value. empty
input The text field: hex, rgb() or hsl() . —
panel The popup dialog (in the overlay container), or the inline group. —
area The saturation and brightness area ( role="slider" ). —
area-thumb The marker in the area. —
hue The native hue range. —
alpha The native opacity range ( alpha ). —
eye-dropper The button that samples the screen (EyeDropper API browsers only). —
presets The group of preset swatches. —
preset One preset swatch button ( aria-pressed ). —
preset-selected The ring around the selected preset. —
hint The vig-hint (a display: contents host; style its text part). —
disabled-reason The vig-hint with the disabled reason ( display: contents ). —
error The vig-field-error (a display: contents host; style its message part). —
ColorPicker data attributes
Attribute Meaning
data-opening On the overlay element (panel or <dialog> ) while its entrance transition plays; removed once it settles (2s at most). Style the entrance with data-opening: utilities.
data-closing On the overlay element while its exit transition plays, before it closes; removed once it settles (2s at most). Style the closed look with data-closing: utilities.

Accessibility

  • The text field is the field's main control: it is named by the label, carries aria-required, aria-invalid and the hint and error, and always shows the value as text, so the color is never conveyed by the swatch alone.
  • The swatch button (aria-haspopup="dialog") opens a non-modal dialog and moves focus to the area; Escape (also from the text field) closes it and returns to the button, Tab past the last control leaves it. Leaving the whole field marks it touched, also in inline mode.
  • The area is a role="slider": Left and Right change the saturation, Up and Down the brightness (Shift for steps of 10), Page Up and Page Down the brightness by 10, Home and End the saturation to 0 and 100. Its aria-valuetext always says both ("Saturation 40%, brightness 80%"); aria-valuenow follows the axis changed last. One slider rather than two keeps the area a single tab stop, as the arrow keys already cover both axes. Hue and opacity are native ranges with readable aria-valuetext ("210 degrees", "50%").
  • Drags use pointer capture, and only the area sets touch-action: none.
  • In forced-colors mode the swatches, the area and the slider tracks keep their colors (they are the information) inside system-colored borders; the selected preset is marked by a ring, not a tint.
  • The EyeDropper button renders only where window.EyeDropper exists. The picker works in sRGB (the area is an HSV model), so it uses no color-mix() or oklch(); wide-gamut colors typed in are not read.

API

ColorPicker

vig-color-picker component

A color field: a saturation/brightness area, a hue slider, an optional opacity slider (alpha), preset swatches and a text field for typing a color, either in place (mode="inline") or behind a swatch button (mode="popup", the default). Where the browser has the EyeDropper API a button samples a color from the screen.

Example :
<vig-color-picker label="Brand color" [(value)]="color" />

The value is a string in format (#1e90ff by default, or rgb() / hsl()), null while empty. The text field takes any of those syntaxes; what it cannot read shows an error and leaves the value alone. Every part works from the keyboard: the area is a slider (arrows, Page Up/Down, Home and End) announced as "Saturation 40%, brightness 80%", the hue and opacity sliders are native ranges. Works with Signal Forms and, through VigValueAccessor, with Reactive Forms and ngModel. While it plays its entrance or exit transition, the animating element carries data-opening or data-closing (stable hooks for styling and for waiting in tests; see the theming guide). data-opening data-closing

ColorPicker props
Name Type Default Description
alphabooleanfalse

Adds an opacity slider; translucent values get an alpha part (#rrggbbaa, rgba(), hsla()). Without it the picker works with opaque colors: what the user picks or types is written without alpha. A translucent value set from outside is kept as it is until the user changes the color.

dirtybooleanfalse
—
disabledbooleanfalse
—
disabledReasonsreadonly WithOptionalFieldTree<DisabledReason>[][]
—
errorMessagesRecord<string, string>—
—
errorsreadonly ValidationError.WithOptionalFieldTree[][]
—
formatColorFormat'hex'

The format the value is written in: hex (default), rgb or hsl.

hiddenbooleanfalse
—
hideLabelbooleanfalse

Keeps the label for assistive tech only.

hintstring | undefinedundefined
—
invalidbooleanfalse
—
label required string—
—
labelsPartial<ColorPickerLabels>—

Texts (i18n); locale defaults.

modeColorPickerMode'popup'

popup (default): a swatch button opens the picker; inline: shown in place.

namestring''
—
pendingbooleanfalse
—
presetsreadonly ColorPreset[][]

Swatches to pick from with one click; name them for screen readers with { value, label }.

readonlybooleanfalse
—
requiredbooleanfalse
—
sizeFieldSize'md'
—
touchedbooleanfalse
—
value model string | nullnull

The color in format, null while empty.

Are you sure?