WlColorPicker
Appearance
#3c6cff
Full example
<div class="wl-stack" data-space="md">
<WlColorPicker
v-model="value"
alpha
custom
palette-label="Material color"
input-label="Material color HEX code"
/>
<p class="wl-text-small" role="status">{{ value }}</p>
</div>Example data
#3c6cff
Full example
<div class="wl-stack" data-space="md">
<WlColorPicker
v-model="value"
alpha
custom
palette-label="Material color"
input-label="Material color HEX code"
/>
<p class="wl-text-small" role="status">{{ value }}</p>
</div>States
#3c6cff
Full example
<div class="wl-stack" data-space="md">
<WlColorPicker
v-model="value"
alpha
custom
palette-label="Material color"
input-label="Material color HEX code"
/>
<p class="wl-text-small" role="status">{{ value }}</p>
</div>Palette and HEX input
Custom swatches, sm/md, a normalised model, external invalid, disabled and the colour's text value.
Custom palette, sizes and HEX
Palette sm
Palette md
#rgb and #rrggbb input is normalized to lowercase #rrggbb. Invalid text marks the field and preserves the last valid model value.
External error and disabled
Approve the selected color before saving.
Unavailable color
Model value: #2563eb.
Full example
<script setup lang="ts">
import { WlButton, WlColorPicker } from "legato-ui";
import { ref } from "vue";
const color = ref("#2563eb");
const swatches = ["#2563eb", "#2e9e68", "#bf8615", "#d2494f", "#22252b", "#f7f7f8"];
</script>
<template>
<div class="wl-stack" data-space="xl" data-input-example="WlColorPicker">
<section class="wl-stack" data-space="md">
<h3 class="wl-text-subheading">{{ "Custom palette, sizes and HEX" }}</h3>
<div class="wl-grid" data-space="lg">
<div
v-for="size in ['sm', 'md'] as const"
:key="size"
class="wl-stack"
data-space="sm"
><p class="wl-text-small">{{ "Palette" }} {{ size }}</p><WlColorPicker
v-model="color"
:size="size"
:swatches="swatches"
:palette-label="`${'Material color, '}${size}`"
:input-label="`${'Material color HEX, '}${size}`"
/></div>
</div>
<p class="wl-text-small wl-text-muted">{{ "#rgb and #rrggbb input is normalized to lowercase #rrggbb. Invalid text marks the field and preserves the last valid model value." }}</p>
</section>
<section class="wl-stack" data-space="md">
<h3 class="wl-text-subheading">{{ "External error and disabled" }}</h3>
<div class="wl-grid" data-space="lg">
<div
class="wl-stack"
data-space="sm"
role="group"
aria-label="Color with an external error"
aria-describedby="docs-color-error"
>
<WlColorPicker
v-model="color"
:swatches="swatches"
invalid
palette-label="Palette with an error"
input-label="HEX with an error"
/>
<p id="docs-color-error" class="wl-text-small" role="alert">{{ "Approve the selected color before saving." }}</p>
</div>
<div class="wl-stack" data-space="sm"><p class="wl-text-small">{{ "Unavailable color" }}</p><WlColorPicker
model-value="#2e9e68"
:swatches="swatches"
disabled
palette-label="Unavailable palette"
input-label="Unavailable HEX"
/></div>
</div>
<div class="wl-inline" data-space="sm">
<span class="docs-color-preview" :style="{ backgroundColor: color }" aria-hidden="true"></span>
<WlButton size="sm" @click="color = '#2563eb'">{{ "Reset color" }}</WlButton>
</div>
<p class="wl-text-small" role="status">{{ "Model value:" }} {{ color }}.</p>
</section>
</div>
</template>
<style scoped>
.docs-color-preview {
width: var(--wl-space-xl);
height: var(--wl-space-xl);
border: 1px solid var(--wl-border);
border-radius: var(--wl-radius-sm);
}
</style>Props
Types, accepted values and literal defaults come from the public manifest. Inherited settings name their source; “Not set” means no default is declared.
v-model: stringThrough modelValue + update:modelValue (default "").
| Prop | Type / values | Default | Purpose |
|---|---|---|---|
modelValue | string | "" | Current colour: #rgb or #rrggbb. Normalised to #rrggbb. |
swatches | readonly string[] | ["#2563eb","#2e9e68","#bf8615","#d2494f","#f7f7f8","#e7e7ea","#dcdce1","#b9bdc6","#9aa0aa","#5d626c","#43474f","#22252b"] | Palette HEX colours. |
size | WlColorPickerSize | "md" | Colour swatch size. |
disabled | boolean | false | Disables the palette and input. |
invalid | boolean | false | External error state. |
paletteLabel | string | Not set | Accessible color list name; falls back to WlConfig.locale.colorPalette (Palette in English). |
inputLabel | string | Not set | Accessible HEX field name; falls back to WlConfig.locale.colorHex (Color HEX code in English). |
alpha | boolean | false | Enable an alpha channel in the selected color. |
custom | boolean | false | Allow entering a custom color beyond the swatch palette. |
pt | WlPt< | Not set | Attributes and callbacks for the component's documented pass-through sections. |
Events
| Event | Payload | When emitted |
|---|---|---|
update:modelValue | [value: string] | New normalised #rrggbb colour. |
Slots
No public slots.
Pass-through: pt
Sections WlColorPicker are listed below. Attributes merge in this order: createWlPt() WlConfig.ptpt instance. Class and style merge; the last supplied value takes priority for other attributes.
| Section | DOM | Purpose |
|---|---|---|
root | div.wl-color-picker | Main element of the component. |
grid | div.wl-color-picker__grid | Calendar or color-palette grid. |
swatch | button.wl-color-picker__sw | Color swatch button in the palette. |
controls | div.wl-color-picker__controls | Container for the HSV and opacity controls. |
channel | label.wl-color-picker__channel | Labelled color-channel row. |
channelLabel | span | Visible color-channel name. |
channelInput | input.wl-color-picker__channel-input | Native range input for a color channel. |
input | input | Native input that receives focus and control attributes. |
Sections refer to the component DOM. Dotted names identify a configuration group and its section; composite parts use their own pt groups. Global and local attributes merge, with class and style added together.
Keyboard and accessibility
- Provide separate paletteLabel and inputLabel: the palette and HEX field are independent controls.
- Arrows cycle focus through swatches; Home/End move to the ends; Enter/Space selects a colour using the native button.
- The model is normalised to lowercase #rrggbb. An invalid draft marks the HEX field and preserves the last valid value.
- Also show the colour in text. Explain external invalid; disabled disables the palette and input.
Keyboard and application responsibilities
Provide a meaningful accessible name and connect labels, hints and errors to the focusable element. Check the behavior with your own data and a screen reader.
WAI-ARIA Authoring PracticesChanges are emitted through v-model. After selection, cancellation and reset, labels and states must remain clear.
In your application, check keyboard controls, zoom and focus visibility. State labels and required information must be readable in every theme.