Color Field
Features
- Supports hex color input mode.
- Individual color channel editing mode.
- Keyboard navigation with arrow keys.
- Mouse wheel support for increment/decrement.
- Page Up/Down for larger value changes.
- Home/End keys to jump to min/max values.
- Form integration with hidden inputs.
- Support for HSL, HSB, and RGB color spaces.
Installation
Install the component from your command line.
$ npm add reka-uiLooking for a complete color picker? Check out the Color Picker example that combines Color Area, Color Slider, Color Field, and Color Swatch components.
Anatomy
Import all parts and piece them together.
<script setup>
import {
ColorFieldInput,
ColorFieldRoot,
} from 'reka-ui'
</script>
<template>
<ColorFieldRoot>
<ColorFieldInput />
</ColorFieldRoot>
</template>API Reference
ColorFieldRoot
The root component that provides the color field context and state management.
| Prop | Default | Type |
|---|---|---|
as | 'div' | AsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | |
channel | 'hue' | 'saturation' | 'red' | 'green' | 'blue' | 'alpha' | 'lightness' | 'brightness'The color channel to display. If not provided, displays hex value. | |
colorSpace | 'hsl' | 'hsl' | 'rgb' | 'hsb'The color space to operate in when displaying a channel. |
defaultValue | '#000000' | string | ColorThe default color value (uncontrolled). |
disabled | false | booleanWhen |
disableWheelChange | false | booleanWhen |
locale | stringThe locale to use for number formatting. | |
modelValue | string | ColorThe color value (controlled). Can be a hex string or Color object. | |
name | stringThe name of the field. Submitted with its owning form as part of a name/value pair. | |
placeholder | stringPlaceholder text when the field is empty. | |
readonly | false | booleanWhen |
required | booleanWhen | |
step | numberCustom step value for increment/decrement. Defaults to channel step or 1 for hex. |
| Emit | Payload |
|---|---|
update:color | [value: Color] |
update:modelValue | [value: string]Event handler called when the value of the checkbox changes. |
ColorFieldInput
The input element for entering color values.
| Prop | Default | Type |
|---|---|---|
as | 'input' | AsTag | ComponentThe element or component this component should render as. Can be overwritten by |
asChild | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. |
Examples
Hex Color Input
Basic hex color input field.
<script setup>
import {
ColorFieldInput,
ColorFieldRoot,
} from 'reka-ui'
import { ref } from 'vue'
const color = ref('#3b82f6')
</script>
<template>
<ColorFieldRoot v-model="color">
<ColorFieldInput />
</ColorFieldRoot>
</template>Channel Input
Input for a specific color channel (e.g., hue).
<script setup>
import {
ColorFieldInput,
ColorFieldRoot,
} from 'reka-ui'
import { ref } from 'vue'
const color = ref('#3b82f6')
</script>
<template>
<ColorFieldRoot
v-model="color"
color-space="hsl"
channel="hue"
>
<ColorFieldInput />
</ColorFieldRoot>
</template>With Wheel Control Disabled
Prevent changing values with mouse wheel.
<script setup>
import {
ColorFieldInput,
ColorFieldRoot,
} from 'reka-ui'
import { ref } from 'vue'
const color = ref('#3b82f6')
</script>
<template>
<ColorFieldRoot
v-model="color"
disable-wheel-change
>
<ColorFieldInput />
</ColorFieldRoot>
</template>Read-only Mode
Display the color value without allowing edits.
<script setup>
import {
ColorFieldInput,
ColorFieldRoot,
} from 'reka-ui'
import { ref } from 'vue'
const color = ref('#3b82f6')
</script>
<template>
<ColorFieldRoot
v-model="color"
readonly
>
<ColorFieldInput />
</ColorFieldRoot>
</template>Accessibility
Keyboard Interactions
| Key | Description |
|---|---|
ArrowUp | Increases the value by one step. |
ArrowDown | Decreases the value by one step. |
PageUp | Increases the value by 10 steps. |
PageDown | Decreases the value by 10 steps. |
Home | Sets the value to minimum. |
End | Sets the value to maximum. |
Enter | Commits the current input value. |
