# ColorPicker
Click the trigger to open the color panel: a saturation/value board, a hue slider, an alpha slider, a hex input and a predefined swatch palette, with hex and rgb output formats.
ColorPicker
<template>
<div class="demo-col" style="gap: 18px;">
<div class="demo-row" style="gap: 12px; flex-wrap: wrap;">
<LhColorPicker v-model="color" />
<LhColorPicker v-model="color" format="rgb" />
<LhColorPicker v-model="color" size="small" />
<LhColorPicker v-model="color" size="large" />
</div>
<div class="demo-row" style="gap: 12px; flex-wrap: wrap;">
<LhColorPicker v-model="color" :show-alpha="false" />
<LhColorPicker v-model="color" disabled />
<LhColorPicker v-model="empty" />
</div>
<LhColorPicker v-model="color" :predefine="predefine" />
<p class="demo-note">Current color: {{ color || '(empty)' }}; the panel closes automatically after picking a predefined swatch.</p>
</div>
</template>
<script>
export default {
data() {
return {
color: '#2B4C7C',
empty: '',
predefine: ['#3A7D5A', '#A63D40', '#B8860B', '#2C2C2C', '#FAF6F0'],
}
},
}
</script>
# Props
| Prop | Description | Type | Default |
|---|---|---|---|
| value (v-model) | Color value (hex / rgb() / rgba() string) | string | — |
| format | Output format (hex outputs 8-digit #rrggbbaa when a<1) | 'hex' \| 'rgb' | 'hex' |
| size | Size | 'small' \| 'medium' \| 'large' | 'medium' |
| disabled | Disable | boolean | false |
| showAlpha | Show the alpha slider | boolean | true |
| predefine | Predefined color list | string[] | — |
| teleportTarget | Popup mount target (Vue 2 has no Teleport) | string \| HTMLElement | 'body' |
| sx | sx shorthand layout props | — | — |
# Events
| Event | Description | Callback args |
|---|---|---|
| input | v-model (Vue 2 semantics) | (value: string) |
| change | Color changed | (value: string) |
# Interaction and precision conventions
- Dragging the saturation board / hue slider / alpha slider submits v-model in real time; the panel closes automatically after clicking a predefined swatch
- The hex / rgb input and predefined swatches are committed from the parsed value exactly; slider paths go through the HSV intermediate state, where channels have 1 unit of quantization loss (core's hue rounding and s/v two-decimal quantization — an established semantic)
- The trigger echoes the bound value only; an invalid string falls back to the placeholder and is flagged as empty
- Keyboard: Enter / Space opens the panel, Escape closes it; clicking outside closes it
# Accessibility
The trigger is role="button" (aria-haspopup="dialog", aria-expanded / aria-controls); the panel pops up as a dialog, and the hue / alpha sliders carry role="slider" with aria-valuenow.
← Cascader DatePicker →
Copyright © 2024-2026 FengMo WenXue