Skip to content

Image Swatch

Use ImageSwatch to display a selectable image-based option, such as a product’s pattern or finish. It renders a radio input by default, or a checkbox when you set multi.

The SDK ImageSwatch showing a selected image-based option.
import { ImageSwatch } from '/@dropins/tools/components.js';
PropTypeReq?Description
srcstringYesImage path.
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.
altstringNoAlt text for the image.
selectedbooleanNoWhether the image swatch is selected. Defaults to false.
disabledbooleanNoWhether the image swatch is disabled. Defaults to false.
outOfStockbooleanNoWhether the image swatch is out of stock. Defaults to false.
multibooleanNoWhether the swatch allows multiple selection, rendering a checkbox instead of a radio. Defaults to false.
imageNodeVNode | ((props: ImageNodeRenderProps) => JSX.Element)NoCustom image content to render instead of the default Image, as a node or a render function.
onValue(value: any) => voidNoFunction to handle value changes.
onUpdateError(error: Error) => voidNoFunction to handle errors thrown by onValue.

ImageSwatch also accepts standard input HTML attributes (for example, onChange and className), except label. When you provide imageNode as a render function, it receives the resolved image props plus an imageSwatchContext object typed by the exported ImageNodeRenderProps interface.

Render a selectable image swatch and handle selection with onValue:

import { ImageSwatch, provider } from '/@dropins/tools/components.js';
await provider.render(ImageSwatch, {
name: 'pattern',
label: 'Striped',
groupAriaLabel: 'Pattern',
value: 'striped',
src: '/media/swatches/striped.jpg',
alt: 'Striped pattern',
onValue: (value) => yourSelectPattern(value),
})(document.querySelector('.imageswatch'));
  • Color Swatch — the same selection pattern for color options.
  • Image — the component that renders the swatch thumbnail.