Skip to content
EspañolEnglish
All components (204)

Quantity picker

Choice · QuantityPicker · .amset-quantity

What it is and when to use it

The minus and plus of a cart line: − 2 +. Inside it is its own numeric text field, so the figure can also be typed by hand and never goes beyond the limits.

When to use it

  • The quantity of each product in the cart, or on the product page before "Add to cart".
  • value and onChange to control it from outside, or initialValue (1 by default) to leave it uncontrolled; name sends it in a native form. min is the lowest (1 by default).
  • max with the stock: when reached, the add button is truly disabled. From warnFrom units (5 by default) it says how many are left ("3 left", or "Out of stock" with 0); a large stock is not shown.
  • It is the box of NumberField with buttons: size (30, 36 or 44 px) and variant (outline, soft, ghost) are the same as for all fields, and in a form it stays aligned with them.
  • readOnly on an already closed order: the figure can be read and focused, but does not change; disabled while it cannot be touched.

When not to

  • A number that is not a cart quantity (an amount, a percentage, a weight): NumberField.
  • Choosing the size or the metal before the quantity: VariantPicker.

Keyboard: Tab reaches the figure; up arrow and down arrow add and subtract one, Page Up and Page Down make a bigger jump, and Home and End go to the limits (End only if there is max). The number can be typed: on leaving or with Enter, anything beyond a limit stays at the limit (99 with 4 in stock stays at 4). The buttons are not in the Tab order: with the keyboard, the arrow keys are used.

Accessibility: the label (label) is required and specific ("Quantity of Aurelia Ring"), because in a cart there is one picker per line. By default only the screen reader hears it (hiddenLabel, on out of the box); with hiddenLabel={false} it is visible as the label of the fields. The buttons are real buttons, "Remove one" and "Add one", with their disabled state. The stock warning is read as the description of the figure and enters with a short transition. The focus is the 2 px ring of the fields on the box. With a finger, the box becomes 48 px, each button 44 px wide and the figure 16 px, so that the iPhone does not zoom the page.

Context: the language of LocaleProvider (or AmsetProvider) decides how the figure is written; without a provider, es-ES.

Fine-tuning: --amset-quantity-figures (how many digits fit without the box growing; 3 by default) and the field variables, --amset-field-* (height, padding, font, radius, background and border). The buttons are those of NumberField (amset-number__step) and the warning is amset-quantity__stock.

What it looks like

2 × €89.00 = €178.00 · To get free shipping you need 1.

<QuantityPicker label="Units" value={unidades} onChange={setUnidades} min={1} max={10} />

Props

Import it with import { QuantityPicker } from '@amset/ui'. Required props are marked.

PropTypeWhat it does
labelrequiredstringRequired and specific: in a cart there is one selector per line, and a bare "Quantity" repeated six times distinguishes none of them.
classNamestring—
disabledbooleanNeither the buttons nor the figure respond, and they leave the Tab order.
hiddenLabelbooleanThe label for the screen reader only, which is the normal thing in a cart.
initialValuenumberThe quantity at the start, without controlling it from outside. By default, 1.
maxnumberThe stock. When reached, the add button is turned off and the reason is stated.
minnumberThe lowest quantity. 1 by default.
namestringThe name it travels under in a native form: the quantity as a number (`12000`), not its text (`12.000`).
onChange(quantity: number) => void—
readOnlybooleanThe figure is focused and read, but does not change: an order that is already closed.
size"sm" | "md" | "lg"—
valuenumberThe quantity, controlled from outside (with `onChange`).
variantFieldVariant—
warnFromnumberFrom how many units a low-stock warning is shown. 5 by default.

It also accepts the attributes of the element it renders: className, style, data-*, aria-* and its events.

CSS variables

These CSS variables are how you adapt it. Declare them on the component's selector, not on :root: the stylesheet redeclares them in the rule itself, and a declaration on the same element always wins.

VariableDefault
--amset-quantity-figures3

How to change it

.amset-quantity {
  --amset-quantity-figures: ...;
}

In the test bench

Every state and variant, to try one at a time, on its page at ui.amset.tech: