Forms & inputs
Layout
ColorPicker
A swatch that opens a picker with a saturation and brightness plane, a hue slider, a hex field, optional presets and an eyedropper where supported. Use it when any color is allowed, not only a few.
Validating a form? vael-form wires this up with a schemaInstall
import { ColorPicker } from 'vael-ui'Playground
panel
md
Placement, behaviour and animation
Usage
<script setup lang="ts">
import { ref } from 'vue'
import { ColorPicker } from 'vael-ui'
const value = ref("#000000")
const open = ref(false)
</script>
<template>
<ColorPicker v-model="value" v-model:open="open" />
</template>Motion New
ColorPicker: the swatch's appearance and states, and the panel like Popover's.
<ColorPicker
:motion="{
initial: { panel: { opacity: 0, y: 8, scale: 0.98 } },
spring: { damping: 0.85, response: 0.35 },
}"
/>| Name | Type | Description |
|---|---|---|
initialexit | swatchpositionerpanel | Sets where each part comes in from and leaves to: any CSS property, plus x, y and blur. A plain number is px, or degrees for rotate. |
states | disabled | Sets values per part that hold while a state is on. An array is a set of keyframes that plays once as the state turns on, such as a shake on invalid. |
enterleave | (parts, context) => animation | Animates the parts with GSAP, motion or element.animate(). Return the animation and the component waits for it, and stops it if interrupted. |
morphlinkedexitOrder | 'trigger' | Record<string, LinkedMotion> | 'reverse' | morph: 'trigger' grows it out of the element that opened it. linked moves other elements with it, such as the page receding behind it. exitOrder: 'reverse' closes its children first. |
springdurationeasing | { damping, response } | number | string | Times all of it: a spring, or a duration in ms with an easing. Never both. |
false | boolean | Turns its motion off, for an animation of your own on its exposed elements. |
Accessibility
| Key | Action |
|---|---|
| EnterSpace | Opens or closes the panel from the swatch. |
| Tab | Moves focus from the swatch into the panel and through its controls. |
| ShiftTab | Moves focus back, closing the panel when it leaves the first control. |
| Escape | Closes the panel. |
| ArrowLeftArrowRight | Lowers or raises saturation by 1% on the color area. |
| ArrowUpArrowDown | Raises or lowers brightness by 1% on the color area. |
| ArrowRightArrowUp | Raises the hue by 1° on the hue slider. |
| ArrowLeftArrowDown | Lowers the hue by 1° on the hue slider. |
| PageUpPageDown | Raises or lowers the hue by 10°. |
| HomeEnd | Sets the hue to 0° or 360°. |
- The swatch is a
buttonwitharia-haspopup="dialog"andaria-expanded. Thelabelprop (default “Color”) names both the swatch and the panel, which hasrole="dialog". Label a custom#triggeryourself. - Opening keeps focus on the swatch. Tabbing past the last panel control closes the panel and moves on. Closing it while focus is inside returns focus to the swatch.
- The color area is a
role="slider"with anaria-valuetextthat reads saturation and brightness; hold Shift for 10% steps. The hue slider, the hex field and the eyedropper button have labels, and presets usearia-pressed. - Right to left, ArrowLeft and ArrowRight swap on the hue slider, and its hues run from the right. On the color area they keep their direction, because saturation always runs left to right.