Lynx

Quantity Picker

A component used to increase or decrease quantity in integer units.

Engine ≥ 3.6
Available since@seed-design/lynx-react@0.8.0, @seed-design/lynx-css@0.12.0
Loading Lynx example…

Installation

npx @seed-design/cli@latest add ui:quantity-picker

Props

Registry convenience component

Registry's QuantityPicker is a convenience API that provides three slots needed for quantity selection in a single component.

Prop

Type

style?CSSProperties | undefined
className?string | undefined
minnumber
maxnumber
step?number | undefined
value?number | undefined
defaultValue?number | undefined
onValueChange?((value: number) => void) | undefined
disabled?boolean | undefined
invalid?boolean | undefined
readOnly?boolean | undefined
loading?QuantityPickerLoading | undefined
onRemove?(() => void) | ((() => void) & (() => void)) | undefined
getValueText?QuantityPickerGetValueText | undefined
dir?"ltr" | "rtl" | undefined
layout?"fill" | "hug" | undefined
size?"small" | "medium" | "large" | undefined
removable?boolean | undefined

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.

@seed-design/lynx-react compound API

When combining low-level APIs directly without using Registry, use the following four public components.

import { QuantityPicker } from "@seed-design/lynx-react";

<QuantityPicker.Root min={1} max={99} accessibility-label="Product quantity">
  <QuantityPicker.DecrementButton accessibility-label="Decrease quantity" />
  <QuantityPicker.ValueDisplay />
  <QuantityPicker.IncrementButton accessibility-label="Increase quantity" />
</QuantityPicker.Root>;

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.

Examples

Layout

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.

Loading Lynx example…

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.

Value Text

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.

Loading Lynx example…

Controlled

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.

Loading Lynx example…

Removable

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.

Loading Lynx example…

Loading

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.

Loading Lynx example…

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.

Form

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.

Accessibility

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.

Differences from Web Version

Lynx QuantityPicker has the following differences from the React web version.

Web (React)Lynx
Registry APIQuantityPicker convenience component and aria-* propsQuantityPicker convenience component and accessibility-* props
Low-level APIRoot, DecrementButton, ValueDisplay, IncrementButton, HiddenInputRoot, DecrementButton, ValueDisplay, IncrementButton
RenderingRenders HTML elements and buttonsRenders Lynx native <view> and accessibility elements, operates via tap
Accessibility namesaria-label, decrementAriaLabel, incrementAriaLabel, removeAriaLabelRoot and slot's accessibility-label, Registry's decrementAccessibilityLabel, incrementAccessibilityLabel, removeAccessibilityLabel
Form submissionSubmit hidden input's name/value to HTML form with inputPropsHTML form, hidden input, FormData, inputProps not supported. Include app state's value directly in request payload
Compound APICan connect to browser form model with HiddenInputApp 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.

Table of contents