Skip to content

ColorInput

A labeled native color picker paired with a synced hex field for exact keyboard entry. Typed values commit on change, validated and normalized.

Import

import { ColorInput } from "@hyzer-labs/ui"

Demo

The swatch is the native picker. The hex field commits on blur or Enter: type f60 and it normalizes to #ff6600, while an entry it cannot read restores the current value. Picks and typed values stay in sync.

let discColor = $state('#ff6b35');

<ColorInput name="disc-color" label="Disc color" bind:value={discColor} />

Props

NameTypeDefaultNote
namestringRequired. Form field name.
labelstringRequired. Always in the DOM; sr-only with hideLabel.
valuestring'#000000'Bindable. The platform normalizes to 7-char lowercase hex.
showInputbooleantrueRenders the exact-entry hex field beside the swatch.
inputLabelstring`${label} (hex value)`Accessible name for the hex field.
descriptionstringHelp text below the label.
errorstringInline error message; sets the error state.
requiredbooleanfalseLabel indicator only.
disabledbooleanfalse
hideLabelbooleanfalse
classstringMerged after the hz-field hz-field--color classes.

Theme hooks

What this component promises your CSS. The reference theme styles exactly these — from @layer hz-theme, so your unlayered rules win. See Styling Components for the how.

Root class: .hz-field hz-field--color

Data attributes

HookValuesStyles
data-state'default' | 'error' | 'disabled'The universal field state hook, on the root. Precedence is fixed: error beats disabled.

Custom properties

HookValuesStyles
--hz-color-swatch-size<length> — default 2remThe swatch height; its width follows at 1.5×, so the 3:2 shape is fixed. Declared on input.hz-color — set it there or deeper, not on the .hz-field root, or the local declaration wins over your inherited value.

Part classes

HookValuesStyles
.hz-field-labelchild elementThe label.
.hz-field-requiredchild elementThe required marker.
.hz-field-descriptionchild elementThe hint text.
.hz-field-errorchild elementThe error message.
.hz-color-rowchild elementThe swatch-and-readout row.
.hz-colorthe color inputThe native swatch.
.hz-color-hexchild elementThe editable hex field.
.hz-color-valuechild elementThe read-only hex readout.

Accessibility

The color input is the labeled (id/for), named, form-participating control. Activating it opens the platform picker, which owns the picking experience.

The hex field is there for typing an exact value. It has its own accessible name (inputLabel) and no name, so it never submits.

description and error chain into aria-describedby, description first, and an error sets aria-invalid. required renders the label indicator only, since a color input always holds a value.

Do not let color alone carry meaning; the visible hex value helps.

References: MDN: <input type="color">