Skip to content

Color Swatch

Use ColorSwatch to display a selectable color option, such as one of a product’s available colors. It renders a radio input by default, or a checkbox when you set multi.

The SDK ColorSwatch showing a selected color option.
import { ColorSwatch } from '/@dropins/tools/components.js';
PropTypeReq?Description
labelstringNoField label.
groupAriaLabelstringNoLabel for the swatch group, used in the accessible label.
namestringNoField name, used to map the value in a form.
idstringNoField id.
valuestringNoField value.
colorstringNoColor of the swatch. Accepts any valid CSS color; falls back to a default gray when invalid.
size'medium' | 'large'NoSize of the color swatch. Defaults to medium.
selectedbooleanNoWhether the color swatch is selected. Defaults to false.
disabledbooleanNoWhether the color swatch is disabled. Defaults to false.
outOfStockbooleanNoWhether the color swatch is out of stock. Defaults to false.
multibooleanNoWhether the swatch allows multiple selection, rendering a checkbox instead of a radio. Defaults to false.
onValue(value: any) => voidNoFunction to handle value changes.
onUpdateError(error: Error) => voidNoFunction to handle errors thrown by onValue.

ColorSwatch also accepts standard input HTML attributes (for example, aria-describedby and className), except label and size. Don’t pass your own onChange — it replaces the component’s built-in value handling; use onValue instead.

Render a selectable color swatch and handle selection with onValue:

import { ColorSwatch, provider } from '/@dropins/tools/components.js';
await provider.render(ColorSwatch, {
name: 'color',
label: 'Gray',
groupAriaLabel: 'Color',
value: 'gray',
color: '#E8E8E8',
selected: false,
onValue: (value) => yourSelectColor(value),
})(document.querySelector('.colorswatch'));
  • Image Swatch — the same selection pattern for image-based options.
  • Design tokens — the colors, spacing, and sizing swatches use.