Color picker
vig-color-picker
import { ColorPicker } from '@vigdx/ui/color-picker';Basic
[(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.
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.
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(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.
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.
Required
Valid: no · none
Reactive Forms
VigValueAccessor next to the component to use formControlName , [formControl] or ngModel .
#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"]
| Part | Element | data-state |
|---|---|---|
label | — | |
field | — | |
trigger | mode="popup" ). | open, closed |
swatch | empty without a value. | empty |
input | rgb() or hsl() . | — |
panel | — | |
area | role="slider" ). | — |
area-thumb | — | |
hue | — | |
alpha | alpha ). | — |
eye-dropper | — | |
presets | — | |
preset | aria-pressed ). | — |
preset-selected | — | |
hint | vig-hint (a display: contents host; style its text part). | — |
disabled-reason | vig-hint with the disabled reason ( display: contents ). | — |
error | vig-field-error (a display: contents host; style its message part). | — |
| Attribute | Meaning |
|---|---|
data-opening | <dialog> ) while its entrance transition plays; removed once it settles (2s at most). Style the entrance with data-opening: utilities. |
data-closing | data-closing: utilities. |
Accessibility
- The text field is the field's main control: it is named by the label, carries
aria-required,aria-invalidand 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 ininlinemode. - 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. Itsaria-valuetextalways says both ("Saturation 40%, brightness 80%");aria-valuenowfollows 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 readablearia-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.EyeDropperexists. The picker works in sRGB (the area is an HSV model), so it uses nocolor-mix()oroklch(); wide-gamut colors typed in are not read.
API
ColorPicker
vig-color-pickerA 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.
<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
| Name | Type | Default | Description |
|---|---|---|---|
alpha | boolean | false | Adds an opacity slider; translucent values get an alpha part ( |
dirty | boolean | false | — |
disabled | boolean | false | — |
disabledReasons | readonly WithOptionalFieldTree<DisabledReason>[] | [] | — |
errorMessages | Record<string, string> | — | — |
errors | readonly ValidationError.WithOptionalFieldTree[] | [] | — |
format | ColorFormat | 'hex' | The format the value is written in: |
hidden | boolean | false | — |
hideLabel | boolean | false | Keeps the label for assistive tech only. |
hint | string | undefined | undefined | — |
invalid | boolean | false | — |
label | string | — | — |
labels | Partial<ColorPickerLabels> | — | Texts (i18n); locale defaults. |
mode | ColorPickerMode | 'popup' |
|
name | string | '' | — |
pending | boolean | false | — |
presets | readonly ColorPreset[] | [] | Swatches to pick from with one click; name them for screen readers with |
readonly | boolean | false | — |
required | boolean | false | — |
size | FieldSize | 'md' | — |
touched | boolean | false | — |
value | string | null | null | The color in |
| Name | Payload | Description |
|---|---|---|
touch | void | — |
valueChange | string | null | The color in |
| Signature | Description |
|---|---|
focus(options?: FocusOptions): void | Moves focus to the control's interactive element (the input, or the
trigger of a popup control). Signal Forms calls it through
|
reset(): void | Clears a typing error and closes the popup; see |