SKU
Product spec picker: specs describes spec groups and options, skus maps combinations to price / stock / image. Once every group is selected the SKU is located and its price shown; during partial selection each option is checked for "can this lead to an in-stock combination" and disabled with a "Sold out" marker when it cannot (path hint). The quantity stepper caps at the matched SKU's stock. Two carriers share one panel: an inline panel on wide screens and a bottom sheet (layout="popup", or automatically at ≤480px).
Basic usage
value is the selected combination (JSON object) and quantity the amount; user selections write both attributes back and dispatch oas-change:
Specs + price linkage + event feedback
Pick a color and size to see price and stock feedback.
Sold out and path hints
After choosing "Obsidian", size M has no stock for that color — it is greyed out and marked "Sold out"; "Mist" still has one M left, so switching colors makes it selectable. When no combination has stock, every option is disabled.
Path hints
Popup (bottom sheet)
layout="popup" hands the same panel to a bottom sheet (oas-bottom-sheet: drag down / tap the backdrop / Esc to close, focus moves into the panel on open and Tab cycles inside it). When layout is omitted the form follows the viewport: ≤480px wide uses the sheet, wider stays inline; an explicit value is never overridden by the viewport, and crossing the breakpoint re-evaluates immediately (no reload).
Opening follows the bottom-sheet protocol: open is a controlled attribute (host writes apply silently), the sheet's close request arrives as oas-close (with reason) and the component collapses itself; interactive and imperative open/close dispatch oas-open-change:
layout=popup + trigger button
In the inline form
openOverlay()/closeOverlay()only warn once (no ghost open state); theopenattribute applies to the popup form only.
Quantity and stock cap
The quantity cap equals the matched SKU's stock; the plus button disables at the cap and typed values above stock are clamped. Sold-out combinations disable the quantity controls:
Quantity stepper (stock 2)
The plus button disables at the stock cap.
Currency and precision
The price inside the panel is rendered by an embedded oas-price, so currency / locale / precision behave exactly like the price component:
Multi-currency / no decimals
Fully disabled
disabled makes every option and the quantity controls unavailable (amount and sold-out hints stay readable); handy for delisted products or campaigns that have not started:
Disabled state
Multiple spec groups (apparel)
Real apparel categories commonly show 6 selling dimensions at once (color / size / collar / sleeve / shawl / material): the component renders one group per specs entry in order, and the SKU table only needs the combinations actually sold (288 in the full cartesian product, 31 here). Impossible combinations cannot be reached by interaction — pick "V-neck" and "With shawl" greys out immediately. When a host-preset value falls outside the table (deep link / stale cache), the component greys out every other option that cannot reach an in-stock combination and marks it "Sold out" — the selected options themselves included — while options in the same group that still lead to stock (e.g. "Crew") stay selectable, so users can re-pick in place to exit. Narrow viewports switch to the sheet by default; this demo pins layout="embedded" to show the multi-group inline layout:
Multiple spec groups (apparel)
Pick specs to see combination linkage.
Selling dimensions vs descriptive attributes
specs is for selling dimensions only — attributes that split SKU combinations and stock (color / size / collar / sleeve / shawl). The test: "can price or stock differ between spec combinations?". Descriptive attributes do not belong in specs: info shared by every combination (origin, brand, fabric content) never varies within one product, and putting it in specs multiplies the SKU table by its option count — 3 groups of 3 options already start at 27 combinations; adding one 2-option descriptive dimension yields 54 skus entries with identical price and stock (pure data bloat, zero business meaning). Descriptive attributes belong in the host's product detail area (outside the component); keep the SKU table to combinations that are actually purchasable and can differ in price or stock. There is no need to fill the full cartesian product — combinations absent from the table are greyed out automatically as unreachable.
API
oas-sku
Attributes
| Attribute | Description | Type | Default |
|---|---|---|---|
currency | ISO 4217 currency, default CNY | string | CNY |
disabled | Disables everything (honours config-provider injected disabled) | boolean | — |
layout | Carrier form: embedded (inline panel) / popup (bottom sheet, bottom-sheet protocol); defaults to viewport-based (sheet at ≤480px); invalid values warn and fall back to embedded | — | — |
locale | Price formatting locale; defaults to the document <html lang>, then en | — | — |
open | Sheet open state (controlled: host writes apply silently; popup form only). Interactive and openOverlay() / closeOverlay() changes dispatch oas-open-change | boolean | string | — |
precision | Price decimal places, default 2 | — | — |
quantity | Quantity (default 1; capped by the matched SKU stock) | number | string | — |
skus | SKU JSON array [{ id?, specs: { [key]: value }, price?, stock?, image?, imageAlt? }] | SkuItem[] | string | — |
specs | Spec group JSON array [{ key, label?, values: (string | { value, label? })[] }] | SkuSpecGroup[] | string | — |
value | Selected combination JSON object { [specKey]: value } (controlled; user picks write back) | Record<string, string> | string | — |
Property (JS property; see each row for attribute reflection)
| Property | Description | Type | Default |
|---|---|---|---|
open | Sheet open state (controlled: reads/writes mirror the open attribute silently; popup form only). Switching popup (while open) back to embedded writes false and dispatches once — the sheet is hidden, so open never lingers stale. A write while embedded is kept as a pending intent (no event) and the sheet opens automatically when the layout switches back to popup | boolean | string | — |
Methods
| Method | Signature | Description |
|---|---|---|
openOverlay | openOverlay(): void | Open the sheet imperatively (idempotent; dispatches oas-open-change; warns once on the inline form) |
closeOverlay | closeOverlay(): void | Close the sheet imperatively (idempotent; dispatches oas-open-change; warns once on the inline form) |
Events
| Event | Description |
|---|---|
oas-change | Dispatched on spec or quantity change with { value, quantity, sku, change: 'spec' | 'quantity' } (sku is the matched object or null), detail: { value: { ...this.selected }, quantity: qty, sku, change: 'quantity', } satisfies SkuChangeDetail | { value: { ...this.selected }, quantity, sku, change, } satisfies SkuChangeDetail |
oas-close | Close request passed through from oas-bottom-sheet (drag down / backdrop / Esc), detail: { reason }; the component already collapses itself, so hosts need no handler (listen only for observation) |
oas-open-change | Sheet open state changed (interactive / imperative / layout-switch settle), detail: { open }; attribute writes stay silent |