Colour input
VColorInput is a form field holding a colour. It can be typed in any format, and the swatch at its start opens VColorPicker in a panel.
Usage
Hex, rgb(), hsl() or oklch().
Examples
Formats
The field accepts hex, rgb(), hsl() and oklch(). Enter or leaving the field rewrites the colour in format; anything else puts the field back as it was.
Opacity and swatches
alpha and swatches are passed to the picker. The swatch in the field shows the opacity over a checkerboard.
Clearable
clearable adds a cross that sets the value to null.
Validation
VColorInput follows the field model: error replaces the hint and is announced. Attributes such as name and required go to the text field.
Sizes
size sets the height of the field to 32, 40 or 48 pixels.
Read-only and disabled
readonly shows the colour without a picker. disabled blocks the field and the swatch.
API
Props
| Prop | Type | Default |
|---|---|---|
format | ColorFormat'hex' | 'rgb' | 'hsl' | 'oklch' | 'hex' |
| How the value is written. The field accepts all four formats. | ||
alpha | boolean | false |
| Adds an opacity track to the picker and writes the alpha below 1. | ||
swatches | ColorSwatch[] | none |
| Preset colours offered in the picker. | ||
hideEyeDropper | boolean | false |
| Hides the picker eyedropper button. | ||
label | string | none |
Visible label. Without a visible name, provide aria-label or aria-labelledby. | ||
hint | string | none |
Help text linked through aria-describedby. | ||
error | string | none |
Error message shown in place of the hint. Sets aria-invalid and is announced when it appears. | ||
placeholder | string | none |
| Placeholder shown when the field is empty. | ||
size | ColorInputSize'sm' | 'md' | 'lg' | 'md' |
| Component size. | ||
compact | boolean | false |
| Reduces the control height without changing text or icons. | ||
disabled | boolean | false |
| Disables interaction. | ||
readonly | boolean | false |
| Prevents typing and removes the picker. The field remains focusable. | ||
invalid | boolean | false |
Sets aria-invalid and the error style. Does not block form submission by itself. | ||
clearable | boolean | false |
| Adds a button that empties the value. | ||
clearLabel | string | none |
| Accessible name of the clear button. Defaults to the library dictionary. | ||
pickerButtonLabel | string | none |
| Accessible name of the swatch button that opens the picker. Defaults to the library dictionary. | ||
placement | ColorInputPlacement'bottom' | 'bottom-start' | 'bottom-end' | 'top' | 'top-start' | 'top-end' | 'bottom-start' |
| Preferred panel position relative to the field. | ||
v-model | string | null | null |
Colour written in format, or null when the field is empty. Typed text updates it when the reader presses Enter or leaves the field. | ||
Events
| Event | Type |
|---|---|
clear | [] |
| The value was cleared; the model is already reset. | |
Slots
| Slot | Type |
|---|---|
value-end | {} |
| Content before the clear button. | |
Types
Types used in the API tables. Import exported types from vectis-ui.
export type ColorSwatch = string | { color: string; label: string }CSS variables
| Token | Value |
|---|---|
--vectis-control-size-color-picker-checker | 0.5rem |