Skip to content

Color Field

SColorField is a text input for a hex color with a preview swatch on the left. The value is normalized (case, #) and can be changed with the arrow keys and the mouse wheel. It is built on SFormField (label, hint, error message); the value is a hex string bound with v-model. For visual color picking, use SColorPicker.

Basic usage

Hint and error message

Sizes

The size prop controls the field height: sm (28px), md (36px), or lg (44px).

States

required adds * to the label, readonly prevents editing, disabled dims the field, invalid marks it as invalid, and hint shows a hint under the field.

prepend / append slots

The slots insert arbitrary content inside the field frame next to the swatch: an icon, text, or a button.

API

Props

NameTypeDefaultDescription
idstringundefinedField id. Generated automatically when omitted (SSR-safe).
labelstringundefinedField label.
floating-labelbooleantrueFloating label: the label sits inside the border, looks like a placeholder at rest and moves up to the top border on focus/when filled. On by default; false gives a regular label above. The label size is fixed and does not depend on size.
hintstringundefinedHint below the field.
errorstringundefinedError message. When set, the field is marked invalid.
placeholderstringundefinedPlaceholder in an empty field.
size"md" | "sm" | "lg""md"Field size: sm (32px), md (40px) or lg (48px).
disabledbooleanfalseDisables the field.
readonlybooleanfalseRead-only.
requiredbooleanfalseMarks the field as required: shows * next to the label.
invalidbooleanfalseExplicitly marks the field invalid (in addition to error).
squarebooleanundefinedSquare corners: removes the field border radius (rounded by default).
model-valuestringundefinedColor value in hex (e.g. #3B82F6). Two-way binding via v-model.

Events

NameSignatureDescription
update:modelValue(value: string | undefined) => voidEmitted when modelValue changes. Used for two-way binding (v-model).

Slots

NameDescription
prependContent at the start of the field, inside the border (icon, button).
appendContent at the end of the field, inside the border (icon, button).