Skip to content

Text Swatch

Use TextSwatch to display a selectable text option, such as a size or category. Set multi to allow multiple selections in a group; otherwise each swatch behaves as a single-select radio option.

The SDK TextSwatch showing a selected text option.
import { TextSwatch } from '/@dropins/tools/components.js';
PropTypeReq?Description
labelstringYesField label.
idstringYesField ID.
namestringNoField name, used for mapping the value in a form.
groupAriaLabelstringNoAccessible label for the swatch group.
valuestringNoField value.
disabledbooleanNoWhether the swatch is disabled. Defaults to false.
selectedbooleanNoWhether the swatch is selected. Defaults to false.
outOfStockbooleanNoWhether the swatch is out of stock. Defaults to false.
multibooleanNoWhether the swatch allows multiple selection. Defaults to false.
onValue(value: any) => voidNoFunction to handle value changes.
onUpdateError(error: Error) => voidNoFunction to handle errors thrown by onValue.

TextSwatch also accepts standard HTML attributes (for example, className), except label.

import { TextSwatch, provider } from '/@dropins/tools/components.js';
await provider.render(TextSwatch, {
name: 'size',
id: 'size-m',
label: 'M',
value: 'M',
groupAriaLabel: 'Size',
onValue: (value) => yourSelectText(value),
})(document.querySelector('.text-swatch'));
  • Radio Button — a single-select control with a similar API.
  • Design tokens — the colors, spacing, and typography the swatch uses.