Cart
The shopping-cart list for the checkout flow: item selection, built-in quantity stepper, delete (button / swipe / off), select-all with indeterminate state, and a selected-items subtotal. Data is driven by the items JSON attribute; after a user interaction the component writes the result back to items and dispatches oas-change (detail carries items / total / selectedCount) — uncontrolled usage works out of the box, controlled hosts ignore the write-back and re-assign items themselves.
Basic usage
Each entry is { id, title, price, quantity?, selected?, spec?, image?, maxQuantity?, disabled? }; both selection and quantity changes dispatch oas-change:
Selection, total and event feedback
Select an item or change a quantity to see oas-change feedback.
Select-all and indeterminate
The select-all checkbox sits at the start of the summary row: checked when everything is selected, indeterminate when only some items are. Disabled items never participate in select-all and never count towards the total.
Indeterminate state (partial selection)
Quantity stepper and stock limit
The stepper and the quantity input clamp automatically: below 1 becomes 1, above maxQuantity becomes the limit (the plus button is disabled at the limit). Quantity changes update the total immediately.
Stock limit 3
Delete
delete-mode picks the delete affordance: button (default, a trailing delete button) / swipe (drag towards the inline start to reveal a delete button — it stays in the tab order, so keyboard users can reach it, and it reveals itself on focus) / none (not deletable). A cancelable oas-remove fires before removal: calling preventDefault() vetoes it (hosts can confirm with a dialog and then write items themselves). Once a row is revealed, tapping that row's body collapses it (no oas-item-click); tapping another row's body first collapses the revealed row and still dispatches the event — at most one row is revealed at a time (swiping another row open collapses the previous one).
Button delete / swipe delete / no delete
delete-mode="swipe": drag left on the row to reveal the delete button, then click it (same gesture for mouse and touch).
delete-mode="none": read-only list (for example an order review view).
Click a delete button to see oas-remove feedback.
Disabled items and missing images
disabled items are dimmed, cannot be selected or resized, and never count towards the total — but their delete button stays enabled so delisted items can be cleared. A missing or broken image renders a dashed placeholder box (the layout never collapses).
Disabled item / missing images
Host-level disabled: the whole cart is read-only (checkout in progress, risk hold, and so on).
Currency and precision
currency / locale / precision are forwarded to item prices and to the subtotal (same formatter as oas-price); detail.total from oas-change is rounded with the same precision.
USD / no decimals
Empty cart
An empty items hides the list and the summary row and renders the empty state; the empty slot replaces it with onboarding copy and a call to action.
Empty state (default copy / custom slot)
Composing with the submit bar
This component only owns the list and the subtotal: put checkout buttons in the actions slot, or feed detail.total into oas-submit-bar. The demo below does both (the submit bar mirrors the cart total):
actions slot + oas-submit-bar sync
Change a selection or a quantity; the submit bar total follows.
Batch operations (capability subpath)
Batch remove / batch favorite goes through the capability subpath @oas-ui/ui/commerce/cart/batch (helper: import on demand, not shipped with the base component — the base API is unchanged). Targets = the selected set (items[].selected === true); disabled entries and unknown ids are skipped automatically. After execution the helper writes items back and dispatches oas-batch (detail = { op, items, succeeded, skipped, changed }) for host feedback:
Batch remove / batch favorite (executeBatch)
Select items, then click "Remove / Favorite selected"; the delisted product (disabled, cannot be checked) is never touched by the batch orchestration.
Host glue (same as the demo):
import { executeBatch } from '@oas-ui/ui/commerce/cart/batch'
removeBtn.addEventListener('click', () => {
const outcome = executeBatch(cart, { type: 'remove' })
// outcome.skipped carries skip reasons (disabled / not-found) for host messaging
})
// Batch favorite: `favorite` is a host-level convention field (true/false written back into items)
executeBatch(cart, { type: 'favorite' })Styling notes
A row is ::part(item) (the li) → ::part(item-inner) (the content layer) plus, in swipe mode, ::part(swipe-remove). The content layer paints its own background above the delete button, so when overriding the ::part(item) background or radius keep the swipe reveal (which shows ::part(swipe-remove)) in mind. Clicking an item body (title / spec / price) dispatches oas-item-click with { id, item } — use it to open the product page.
API
oas-cart
Attributes
| Attribute | Description | Type | Default |
|---|---|---|---|
currency | ISO 4217 currency, default CNY (forwarded to the nested oas-price) | string | CNY |
delete-mode | Delete affordance: button (default, trailing delete button) / swipe (drag towards the inline start to reveal the delete button, which stays in the tab order) / none (not deletable); invalid values fall back to button and warn once | — | — |
disabled | Disables the whole cart (honours config-provider injected disabled): selection, stepper, delete and select-all are all inert | boolean | — |
items | Item JSON array [{ id, image?, title, spec?, price, quantity?, selected?, maxQuantity?, disabled? }]; entries without id are ignored, an invalid price counts as 0 (warns once), quantity defaults to 1 and is clamped to [1, maxQuantity], selected defaults to false, and disabled items never count towards the total | CartItem[] | string | — |
locale | Amount formatting locale; defaults to the document <html lang>, then en | — | — |
precision | Amount decimal places, default 2 (the total in detail is rounded with it) | — | — |
Property (JS property; see each row for attribute reflection)
| Property | Description | Type | Default |
|---|---|---|---|
items | Items: get+set accessor (accepts an array or a JSON string and reflects the items attribute). After a user interaction the component writes the result back and dispatches oas-change; controlled hosts ignore the write-back and re-assign their own state | CartItem[] | string | — |
Events
| Event | Description |
|---|---|
oas-change | Fired after selecting, select-all, a quantity change or a deletion with detail: { items, total, selectedCount, allSelected, indeterminate } |
oas-item-click | Fired when an item body (title / spec / price) is clicked, detail: { id, item } — use it to open the product page |
oas-remove | Fired before removal (cancelable) with detail: { item, items, total, selectedCount } (items is the list after removal); calling preventDefault() vetoes the removal so hosts can confirm first |
Slots
| Name | Description |
|---|---|
actions | Extra area at the end of the summary row (checkout button, discounts, …); the whole row is hidden for an empty cart |
empty | Empty-state content (defaults to the i18n cart.empty copy) |