min and max are required and must be safe integers. The default value of step is 1, and if defaultValue is omitted, it starts from min. Using value and onValueChange together allows you to control the value with external state.
size: small, medium (default), large
layout: hug (default), fill. In fill, the Value Display area expands to fill remaining width.
loading: If true, blocks both Decrement and Increment; if passed as an object, blocks each action separately with { decrement?: boolean, increment?: boolean }.
removable: Changes Decrement to Remove action at minimum value. Handle item deletion in onRemove.
getValueText: Changes the quantity text displayed on screen. The actual quantity value and arguments to onValueChange remain as numbers.
Pass quantity range and state (min, max, step, value, defaultValue, onValueChange, disabled, invalid, readOnly, loading, removable, onRemove, getValueText, dir, layout, size) to Root. When removable={true}, you must also pass removeAccessibilityLabel.
DecrementButton, ValueDisplay, and IncrementButton share values and state using Root's Context. You can pass icons, loading indicators, native accessibility-* attributes, and Lynx events directly to each slot. The Registry convenience component's decrementAccessibilityLabel, incrementAccessibilityLabel, decrementIcon, incrementIcon, removeIcon, loadingIndicator are props that configure this compound slot instead. Lynx compound API does not have the web-only HiddenInput slot.
layout="hug" maintains the width that fits the content. If the parent is a Flex layout and needs to fill remaining space, use layout="fill". Both button sizes are maintained and only the Value Display area expands.
The Quantity Picker recipe used in this example uses display: grid. It is compatible with Android/iOS Lynx engine 2.1 and above and HarmonyOS Lynx engine 3.4 and above.
Using getValueText, you can add units or supplementary descriptions to the displayed quantity. The returned value is the display text used for Value Display and accessibility values, and does not affect internal quantity state or increment/decrement units.
Using value and onValueChange, you can control quantity state with app state. Save the new number in the change callback and pass the saved value back as value.
Using removable, when the value reaches min, the Decrement button switches to a Remove button. In this case, pressing Decrement calls only onRemove without changing the quantity. Handle deletion or removal from the list in onRemove.
With loading, you can temporarily prevent all actions or specific actions from executing and display a loading indicator. loading={true} applies to both Decrement and Increment, and passing an object like loading={{ increment: true }} prevents only that action.
disabled, readOnly, and loading all prevent actions from being executed. disabled disables both actions and passes disabled to accessibility state. readOnly prevents quantity changes and Remove callback calls but does not change the value to another state. loading temporarily prevents only the specified action and displays the action's indicator. Therefore, even at the minimum value of removable, if Decrement is disabled, readOnly, or decrement loading, onRemove is not called.
Since Lynx does not have HTML <form>, hidden <input>, or FormData submission models, it does not provide inputProps-based Form examples like the web. When you need to submit quantity, manage app state with value and onValueChange, and then put that state directly in the payload in the code that creates the submission or network request. This approach can separate getValueText for UI display and the raw numeric value to send to the server.
Provide accessibility-label describing the purpose of Quantity Picker to Root. Root is exposed by default with accessibility-role-description="quantity picker", and if needed, you can directly specify native accessibility attributes like accessibility-role-description and accessibility-value.
In the Registry convenience component, specify the accessibility name of each button with decrementAccessibilityLabel and incrementAccessibilityLabel. When the minimum value is reached in the removable state, the Decrement button switches to a Remove button, so also specify removeAccessibilityLabel describing the Remove action. The Registry defaults are Decrease quantity, Increase quantity, and Delete item respectively. In the compound API, directly specify accessibility-label on the Decrement/Increment buttons and pass removeAccessibilityLabel to Root.
Buttons in the disabled state have disabled reflected in accessibility traits. In the readOnly and loading states, the action cannot be executed, so explain the state and restrictions together with surrounding labels or guidance text. The loading indicator is a visual display element and is hidden from accessibility elements.
Root and slot's accessibility-label, Registry's decrementAccessibilityLabel, incrementAccessibilityLabel, removeAccessibilityLabel
Form submission
Submit hidden input's name/value to HTML form with inputProps
HTML form, hidden input, FormData, inputProps not supported. Include app state's value directly in request payload
Compound API
Can connect to browser form model with HiddenInput
App manages value and onValueChange without HiddenInput
Lynx does not have browser's HTML form validation and keyboard focus model, so it uses app state, native tap, and Lynx accessibility navigation instead of form submission, required validation, and DOM events.