Navigated to /docs/ui/components/color-picker

ColorPicker

Native color selection control with token-backed styling.

Preview

A live, theme-aware example rendered with the published component.

Loading preview…

Import

Import from the focused entry point below, or use the same named export from @tavojs/ui. Both are public APIs; measure the built application when comparing their bundle cost.

TSX
tsximport { ColorPicker } from "@tavojs/ui/color-picker";

The component import loads compiled component CSS. Enable tavoUi() for your project theme variables, or import @tavojs/ui/theme.css once for the package default theme. The equivalent CSS-safe component alias is @tavojs/ui/css/color-picker.

When to use

Use it when

Use `ColorPicker` for native solid-color selection or CSS paint strings such as alpha colors, variables, and gradients

Choose something else when

Avoid ColorPicker when wrapping controls without labels or accessible names.

Examples

These examples include imports and local state where interaction requires it. Render the exported component in a page after completing UI installation. Demo state stays in the mounted component; connect file handling, persistence, and data loading to your application as needed.

ColorPicker example

TSXCreate: src/components/examples/ColorPickerExample1.tsx
tsximport { createTavo } from "@tavojs/core";
import { ColorPicker } from "@tavojs/ui/color-picker";
import { Text } from "@tavojs/ui";

type State = { color: string; savedColor: string };

export const ColorPickerExample1 = createTavo<Record<string, never>, State>({
  model: () => ({ color: "#6633ff", savedColor: "#6633ff" }),
  view: ({ state, model }) => (
    <>
      <ColorPicker
        aria-label="Brand color"
        value={state.color}
        onValueInput={(color) => model.set("color", color)}
        onValueChange={(color) => model.patch({ color, savedColor: color })}
      />
      <Text>Committed color: {state.savedColor}</Text>
    </>
  )
});

Common props and defaults

A curated starting point. The complete TypeScript API below includes additional props and compound member contracts.

PropTypeDefaultDescription
classNamestring

Optional class hook applied to the public root element owned by the component.
valuestring

Controlled color value in `#rrggbb` format.
defaultValuestring

Initial color value for an uncontrolled picker.
namestring

Form field name submitted with the selected color.
sizeSize

Control scale: `sm`, `md`, or `lg`.
format"hex" | "css"

Keeps the backward-compatible native picker or enables CSS-string editing.
swatchesArray<string | ColorPickerOption>

Optional reusable paint choices.
tokensColorPickerOption[]

Optional labeled CSS token choices.
onValueInput(value: string) => void

Runs for transient paint previews.

Complete TypeScript API

Import from @tavojs/ui/color-picker. Published exports: ColorPicker, ColorPickerOption, ColorPickerProps.

ColorPickerProps

PropertyTypeRequiredDescription
classNamestring

No

Optional class hook applied to the public root element owned by the component.

sizeSize

No

Control scale: `sm`, `md`, or `lg`.

format"hex" | "css"

No

Keeps the backward-compatible native picker or enables CSS-string editing.

labelChild

No

Inherited label attribute accepted by ColorPicker.

valuestring

No

Controlled color value in `#rrggbb` format.

defaultValuestring

No

Initial color value for an uncontrolled picker.

namestring

No

Form field name submitted with the selected color.

placeholderstring

No

Inherited placeholder attribute accepted by ColorPicker.

requiredboolean

No

Inherited required attribute accepted by ColorPicker.

typenever

No

Inherited type attribute accepted by ColorPicker.

swatches(string | ColorPickerOption)[]

No

Optional reusable paint choices.

tokensColorPickerOption[]

No

Optional labeled CSS token choices.

onValueInput(value: string) => void

No

Runs for transient paint previews.

onValueChange(value: string) => void

No

Inherited onValueChange attribute accepted by ColorPicker.

onChangeValueChangeHandler<HTMLInputElement>

No

Inherited onChange attribute accepted by ColorPicker.

onInputValueChangeHandler<HTMLInputElement>

No

Inherited onInput attribute accepted by ColorPicker.

State ownership and DOM target

ConcernContract
StateUse value to supply rendered state. Update it through the documented callback or native event handler. For browser-owned initial values, use defaultValue instead.
DOM targetNative input attributes target the owned form control; wrapper-specific props stay on the documented component root.

Anatomy and related components

This component exposes one public component root rather than a compound member API.

Limitations

Avoid ColorPicker when wrapping controls without labels or accessible names.

Use only the documented props, entry points, and compound members. Internal DOM nesting and CSS class names can change without becoming part of the public component contract.

Accessibility

Pair native mode with `Field` or `aria-label`; CSS mode accepts a visible `label` and keeps the solid-color chooser keyboard reachable.

  • Pair native mode with `Field` or `aria-label`; CSS mode accepts a visible `label` and keeps the solid-color chooser keyboard reachable.

Component status

ContractCurrent value
Maturitystable
Categoryforms
Component import@tavojs/ui/color-picker
Explicit CSS import@tavojs/ui/css/color-picker
PreviewInteractive preview available on this page