StealThis .dev

Shop — Variant Selector

An e-commerce variant selector primitive with named color swatches that cross out sold-out shades, a material picker that adjusts the price, and size chips whose availability is computed per color and material so disabled combinations are clearly shown. Choosing a color or material filters the available sizes, while a live summary, per-variant price, compare-at savings, and stock chip stay in sync. Includes a size-guide dialog, keyboard-roving radio groups, and validation before add to cart.

Open in Lab
html css vanilla-js
Targets: JS HTML

Code

Variant Selector

A self-contained variant-picker primitive for a fictional knit-runner sneaker. The buy box pairs a gradient “product photography” tile and inline-SVG silhouette with three real radio groups: named color swatches, a material picker, and US size chips. Sold-out colors render crossed-out and disabled, and the size chips recompute their availability from a per-combination inventory map, so impossible color/material/size combinations are dimmed, dashed, and unselectable.

Every selection drives state. Choosing a color repaints the media tile and shoe upper, picking a material adds its surcharge to the price, and any change re-filters the sizes — clearing a now-unavailable size with a friendly hint. A live “Selected: Black / Recycled knit / US 9” summary, the per-variant price with compare-at savings, and a color-coded stock chip (in stock / only N left / out of stock) all update together. Submitting validates that a size is chosen and still in stock before firing the add-to-cart toast, and a size-guide dialog opens with US/EU/heel-to-toe measurements.

The radio groups use roving tabindex with arrow, Home, and End keys, expose aria-checked and aria-disabled state, and keep crisp focus-visible rings. The layout collapses to a single column on tablets, reflows at phone widths, and honors reduced-motion preferences.

Illustrative storefront UI only — fictional products, prices, and reviews. No real checkout.