Skip to content

Color Picker ​

The ColorPicker field renders a color selection interface with HSL sliders, a color value input, swatches, an eyedropper tool, and a copy-to-clipboard action. The field stores its value as a color string.

Basic Usage ​

Example
php
use InertiaUI\Forms\Fields\ColorPicker;

ColorPicker::make('brand_color');

The default format is hex, which adds the hex_color validation rule. Switching to rgb or hsl removes that managed format rule and keeps the base string rule. Rules you add yourself using the rule or rules method are preserved.

Color Values ​

These methods set the format of the submitted color and the color the picker shows when no value is set.

Color Format ​

To choose between the hex, rgb, and hsl output formats, call the matching method:

Example
php
ColorPicker::make('color')->hex();   // #3b82f6
ColorPicker::make('color')->rgb();   // rgb(59, 130, 246)
ColorPicker::make('color')->hsl();   // hsl(217, 91%, 60%)

You may also pass the format to the format method directly:

php
ColorPicker::make('color')->format('rgb');

The format method throws an InvalidArgumentException for any other value. The hex_color validation rule is only added for the hex format.

Alpha Channel ​

The showAlpha method adds an alpha, or opacity, slider:

Example
php
ColorPicker::make('overlay_color')->showAlpha();

The alpha slider is off by default. An opacity below 100% submits the alpha value in the selected output format:

php
ColorPicker::make('color')
    ->showAlpha()
    ->hex(); // #3b82f680

ColorPicker::make('color')
    ->showAlpha()
    ->rgb(); // rgba(59, 130, 246, 0.5)

ColorPicker::make('color')
    ->showAlpha()
    ->hsl(); // hsla(217, 91%, 60%, 0.5)

Default Color ​

The defaultColor method sets a fallback color that the picker uses when no value is set:

php
ColorPicker::make('background')->defaultColor('#ffffff');

The default color is a visual fallback only. It doesn't submit a value until the user selects or types a color.

Swatches ​

The swatches method provides a set of preset colors for quick selection:

Example
php
ColorPicker::make('theme_color')->swatches([
    '#ef4444', '#f97316', '#eab308',
    '#22c55e', '#3b82f6', '#8b5cf6',
    '#ec4899', '#6b7280', '#000000',
]);

The default swatches value is null, which tells the frontend to use its built-in palette. Passing an array replaces that palette with your own colors:

php
ColorPicker::make('brand_color')->swatches([
    '#1e40af',
    '#059669',
    '#d97706',
]);

To show no preset swatches at all, pass an empty array. Calling swatches(null) returns to the frontend's default palette.

Named swatches may show the name of the selected swatch in the closed trigger. The array key is the submitted color value, and the array value is the swatch name:

Example
php
ColorPicker::make('brand_color')
    ->swatches([
        '#1e40af' => 'Brand color',
        '#059669' => 'Accent color',
    ])
    ->showSwatchName();

With showSwatchName enabled, the trigger falls back to the formatted color value when the selected color doesn't match a named swatch.

Picker Controls ​

The text input, the eyedropper button, and the copy action are enabled by default. The following sections show how to turn them off, add a clear action, and handle the readonly state.

Color Input ​

The text input for typing a color value is visible by default. It accepts hex, rgb or rgba, and hsl or hsla values, then normalizes the submitted value to the configured output format. To let users choose from swatches only, hide it using the hideInput method:

Example
php
ColorPicker::make('color')
    ->swatches([
        '#1e40af' => 'Brand blue',
        '#059669' => 'Accent green',
        '#d97706' => 'Warning orange',
        '#dc2626' => 'Danger red',
        '#7c3aed' => 'Violet',
        '#db2777' => 'Pink',
    ])
    ->showSwatchName()
    ->hideInput();

You may also pass false to the showInput method:

php
ColorPicker::make('color')->showInput(false);

With the input controls hidden, the popover only shows the swatch list. The HSL sliders, the alpha slider, the text input, the eyedropper button, and the copy button are hidden too. Pair the hideInput method with a custom swatch array, so users still have colors to select.

The hideInput method only controls the popover controls. To show the name of a selected swatch in the closed trigger, use the showSwatchName method.

Eyedropper ​

The eyedropper button lets users pick a color from anywhere on the screen. It's enabled by default in supported browsers, which are Chromium-based browsers only:

Example
php
ColorPicker::make('color')
    ->defaultColor('#3b82f6')
    ->showEyeDropper();

To hide it, call the hideEyeDropper method:

php
ColorPicker::make('color')->hideEyeDropper();

You may also pass false to the showEyeDropper method:

php
ColorPicker::make('color')->showEyeDropper(false);

Copy to Clipboard ​

The copy action is enabled by default, but the button only appears when the input controls are visible and the field has an actual value. A defaultColor preview doesn't show the copy button until the user selects or types a color.

The copied value matches the normalized display value for the configured format. Hex values are copied in uppercase, such as #3B82F6, while rgb and hsl fields copy the normalized rgb(...) or hsl(...) string. To disable the action, pass false to the copyable method:

php
ColorPicker::make('color')->copyable(false);

Clearable ​

The clearable method lets the user clear the selected color:

php
ColorPicker::make('accent_color')->clearable();

Readonly ​

The ColorPicker field doesn't currently support a readonly state. Use the disabled method when users shouldn't be able to change the value.

Palette With Alpha ​

The following field combines a custom palette with the alpha slider:

php
ColorPicker::make('brand_color')
    ->label('Brand Color')
    ->help('Used throughout the dashboard')
    ->swatches([
        '#1e40af', '#059669', '#d97706',
        '#dc2626', '#7c3aed', '#db2777',
    ])
    ->showAlpha()
    ->clearable()
    ->required();

The color picker methods work together with the shared field APIs:

Using the Component Directly ​

Each stack exports the ColorPicker component from its components subpath. Pass serialized form.getField(...) props during manual rendering, or bind a local color value for standalone usage:

vue
<script setup lang="ts">
import { ColorPicker } from '@inertiaui/form-vue/components'
import { ref } from 'vue'

const brandColor = ref<string | null>('#1e40af')
const badgeColor = ref<string | null>(null)
const swatches = ['#1e40af', '#059669', '#d97706', '#dc2626', '#7c3aed', '#db2777']
const namedSwatches = [
    { color: '#1e40af', label: 'Brand blue' },
    { color: '#059669', label: 'Accent green' },
]
const pickerParts = {
    dropdown: 'max-h-80',
    swatch: 'rounded-md',
    slider: 'shadow-none',
    preview: 'ring-zinc-300',
    action: 'text-zinc-500',
}

const trackOpenIntent = () => {}
</script>

<template>
    <div class="grid gap-4">
        <ColorPicker
            v-model="brandColor"
            id="brand-color"
            name="brand_color"
            label="Brand color"
            help="Used in dashboard accents."
            format="hex"
            :swatches="swatches"
            show-input
            show-alpha
            show-eye-dropper
            copyable
            clearable
            default-color="#1e40af"
            control-class="min-w-64"
            wrapper-class="max-w-xl"
            :part-classes="pickerParts"
            data-testid="brand-color"
            @click="trackOpenIntent"
        />

        <ColorPicker
            v-model="badgeColor"
            name="badge_color"
            label="Badge color"
            :swatches="namedSwatches"
            :show-input="false"
            show-swatch-name
            default-color="#059669"
        />
    </div>
</template>
tsx
import { useState } from 'react'
import { ColorPicker } from '@inertiaui/form-react/components'

const swatches = ['#1e40af', '#059669', '#d97706', '#dc2626', '#7c3aed', '#db2777']
const namedSwatches = [
    { color: '#1e40af', label: 'Brand blue' },
    { color: '#059669', label: 'Accent green' },
]
const pickerParts = {
    dropdown: 'max-h-80',
    swatch: 'rounded-md',
    slider: 'shadow-none',
    preview: 'ring-zinc-300',
    action: 'text-zinc-500',
}

export default function BrandColorPicker() {
    const [brandColor, setBrandColor] = useState<string | null>('#1e40af')
    const [badgeColor, setBadgeColor] = useState<string | null>(null)
    const trackOpenIntent = () => {}

    return (
        <div className="grid gap-4">
            <ColorPicker
                value={brandColor}
                onValueChange={setBrandColor}
                id="brand-color"
                name="brand_color"
                label="Brand color"
                help="Used in dashboard accents."
                format="hex"
                swatches={swatches}
                showInput
                showAlpha
                showEyeDropper
                copyable
                clearable
                defaultColor="#1e40af"
                controlClass="min-w-64"
                wrapperClass="max-w-xl"
                partClasses={pickerParts}
                data-testid="brand-color"
                onClick={trackOpenIntent}
            />

            <ColorPicker
                value={badgeColor}
                onValueChange={setBadgeColor}
                name="badge_color"
                label="Badge color"
                swatches={namedSwatches}
                showInput={false}
                showSwatchName
                defaultColor="#059669"
            />
        </div>
    )
}

Vue uses v-model, while React uses a controlled value with onValueChange. Standalone values are normalized color strings or null. The defaultColor prop only changes the empty visual state, and the name prop renders a hidden input for native form submission. Direct Vue and React usage may pass named swatches as { color: '#1e40af', label: 'Brand color' } objects in the same swatches array.

Native attributes and listeners target the underlying trigger <button>. See Native Attributes And Events.