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".
valueandonChangeto control it from outside, orinitialValue(1 by default) to leave it uncontrolled;namesends it in a native form.minis the lowest (1 by default).maxwith the stock: when reached, the add button is truly disabled. FromwarnFromunits (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
NumberFieldwith buttons:size(30, 36 or 44 px) andvariant(outline,soft,ghost) are the same as for all fields, and in a form it stays aligned with them. readOnlyon an already closed order: the figure can be read and focused, but does not change;disabledwhile 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.
| Prop | Type | What it does |
|---|---|---|
labelrequired | string | Required and specific: in a cart there is one selector per line, and a bare "Quantity" repeated six times distinguishes none of them. |
className | string | — |
disabled | boolean | Neither the buttons nor the figure respond, and they leave the Tab order. |
hiddenLabel | boolean | The label for the screen reader only, which is the normal thing in a cart. |
initialValue | number | The quantity at the start, without controlling it from outside. By default, 1. |
max | number | The stock. When reached, the add button is turned off and the reason is stated. |
min | number | The lowest quantity. 1 by default. |
name | string | The name it travels under in a native form: the quantity as a number (`12000`), not its text (`12.000`). |
onChange | (quantity: number) => void | — |
readOnly | boolean | The figure is focused and read, but does not change: an order that is already closed. |
size | "sm" | "md" | "lg" | — |
value | number | The quantity, controlled from outside (with `onChange`). |
variant | FieldVariant | — |
warnFrom | number | From 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.
| Variable | Default |
|---|---|
--amset-quantity-figures | 3 |
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:
