SwatchSelector
Row of selectable color/image swatches with controlled single selection.
Shares the selected value, onValueChange, and size with its
{@link SwatchSelectorItem} children through context.
Usage
import { Swatch, SwatchMore, SwatchSelector, SwatchSelectorItem } from "@desk/ui/components/swatch-selector";Best practices
Pair
SwatchSelectorwithSwatchSelectorItemchildren — it sharesvalue/onValueChange/sizethrough context, so items need no individual wiring.Prefer
SwatchGroupwhen the row is a single-choice form control needing radio roles + arrow-key navigation;SwatchSelectoris the lighter, roles-free option.Selection is controlled — pass
valueand update it fromonValueChange; there is no internal fallback state to fall back on.
Props
Swatch
| Prop | Type | Default | Description |
|---|---|---|---|
| color | string | CSS color value (hex, rgb, hsl, etc.). If provided along with children, children render on top. | |
| aria-label | string | Defines a string value that labels the current element. Accessible label for screen readers. | |
| value | string | (readonly string[] & string) | Unique value for this swatch | |
| children | import("react").ReactNode | Custom content rendered inside the swatch (e.g., images). | |
| size | SwatchSize | Override size for this specific swatch. | |
| unavailable | boolean | Whether this option is unavailable (out of stock) |
SwatchMore
| Prop | Type | Default | Description |
|---|---|---|---|
| count | number | Number of additional swatches not shown; rendered as |
SwatchSelector
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | Value of the currently selected item (controlled single selection). | |
| onValueChange | (value: string) => void | Fired with the newly selected item's | |
| size | SwatchSize | Swatch size, inherited by items via context unless they override it. |
SwatchSelectorItem
| Prop | Type | Default | Description |
|---|---|---|---|
| color | string | CSS color value (hex, rgb, hsl, etc.). If provided along with children, children render on top. | |
| aria-label | string | Defines a string value that labels the current element. Accessible label for screen readers. | |
| value | string | (readonly string[] & string) | Unique value for this swatch | |
| children | import("react").ReactNode | Custom content rendered inside the swatch (e.g., images). | |
| size | SwatchSize | Override size for this specific swatch. | |
| unavailable | boolean | Whether this option is unavailable (out of stock) |
Composition
Used by