Color input component.

The user picks a color with the HSV saturation/value canvas, the hue slider and the optional alpha slider. The user can also type a color string: hex, rgb(a), hsl(a) or a named CSS color.

The component supports pre-defined swatches and the native EyeDropper API, where the browser provides one. The anchor is a trigger button (mode="default") or an editable text field (mode="input").

Slots
value-missing — Renders content when the required validation fails.
custom-error — Renders content when setCustomValidity(message) is set.
invalid — Renders content when the component is in invalid state (validity.valid = false).
helper-text — Renders content below the picker.
CSS Parts
color-picker — The wrapper of the anchor, the label and the helper text.
anchor — The trigger element that opens the picker (the button in default mode, or the swatch prefix in input mode).
empty — Applied alongside `anchor` when no color value is set, rendering a checkered background.
input-mode — Added to the anchor part in input mode.
label — The label rendered after the anchor in default mode.
picker — The popover container holding the canvas, sliders, inputs and swatches.
picker-canvas — The saturation and value canvas.
marker — The marker on the canvas that shows the saturation and value.
dragging — Added to the marker part while the user drags it.
main-row — The row containing the hue slider and the copy/eyedropper buttons.
alpha-row — The row containing the alpha slider and input, rendered when `show-alpha` is set.
inputs-row — The row containing the format select and the color value input.
buttons — The wrapper around the copy and eyedropper buttons.
hue — The hue slider.
alpha — The alpha slider.
alpha-input — The input of the alpha value, rendered when `show-alpha` is set.
copy — The button that copies the current color value to the clipboard.
eye-dropper — The button that activates the EyeDropper API.
format-select — The select control used to switch the color string format.
swatches — The container of the pre-defined color swatches.
swatch — An individual color swatch button.

The color format of the string value.

A format change renders value in the new notation. The color does not change, so the component emits no igcInput or igcChange.

format: ColorFormat

Whether the format select is hidden.

hideFormats: boolean

The label of the component.

In mode="input" the component forwards the label to the anchor input. In mode="default" it renders the label as a separate element.

label: string | undefined
locale: string

The mode of the color picker.

In "default" mode the anchor is a trigger button. In "input" mode the anchor is an editable text field with a color swatch prefix. The prefix also opens the picker.

mode: ColorPickerMode

Whether the component is open.

open: boolean
resourceStrings: TGet

The behavior of the component when a parent container scrolls.

If the value is hide, the component hides while the anchor is fully out of view. hide is the default value.

If the value is scroll, the component stays visible and anchored.

If the value is close, the component closes on each scroll.

scrollStrategy: PopoverScrollStrategy

Whether to show the alpha slider and input.

showAlpha: boolean

Pre-defined color strings. The component renders them as clickable swatches below the picker controls. A click on a swatch sets its color as the value.

swatches: string[]

The value of the component as a CSS color string. Accepts hex, rgb(a), hsl(a) and named colors.

An empty, whitespace-only or invalid string clears the value.

value: string

Removes focus from the color picker.

blur(): void

Returns void

Sets focus on the color picker.

focus(options: FocusOptions): void

Parameters

  • options: FocusOptions

Returns void

Closes the component. It does not emit events. The promise resolves to false when the component is already closed, or when a later call replaces this one.

hide(): Promise<boolean>

Returns Promise<boolean>

Opens the component. It does not emit events. The promise resolves to false when the component is already open, or when a later call replaces this one.

show(): Promise<boolean>

Returns Promise<boolean>

Opens the component when it is closed, and closes it when it is open. It does not emit events. The promise resolves to true when the state changes.

toggle(): Promise<boolean>

Returns Promise<boolean>

Emitted when the focus leaves the component after the user changed the color.

onChange(args: CustomEvent<string>): void

Parameters

Returns void

Emitted after the picker dropdown closes on a user action.

onClosed(args: CustomEvent<void>): void

Parameters

Returns void

Emitted before the user closes the picker dropdown. Cancelable.

onClosing(args: CustomEvent<void>): void

Parameters

Returns void

Emitted when the user changes the color with the canvas, the sliders, the alpha input, a swatch or the eyedropper.

onInput(args: CustomEvent<string>): void

Parameters

Returns void

Emitted after the picker dropdown opens on a user action.

onOpened(args: CustomEvent<void>): void

Parameters

Returns void

Emitted before the user opens the picker dropdown. Cancelable.

onOpening(args: CustomEvent<void>): void

Parameters

Returns void