Number field
Bounded numeric entry with step buttons, cancellable hold-repeat and a UI-thread scrub variant.
npx @swipeui/cli add number-fieldWhen to use it
- Quantities, guests, servings or repetitions with minus and plus buttons.
- Bounded values where people may also type the number.
- A scrub control, where dragging sideways changes the value, for settings like font size.
- Holding a button to change a value quickly.
When not to use it
- Money. Use Money input.
- Large ranges where position matters. Use Slider.
- Picking from a few fixed numbers. Use Segmented control or Chip group.
Installation
Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.
npx @swipeui/cli add number-field- Adds
components/swipeui/ui/number-field.tsxand 13 shared helpers. - Installs react-native-gesture-handler, react-native-reanimated, react-native-worklets, uniwind, clsx, tailwind-merge, expo-haptics, class-variance-authority, react-native-svg. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
import { NumberField } from '@/components/swipeui/ui/number-field';
<NumberField label="Quantity" min={1} max={10} defaultValue={1} />;Examples
Use the variant and appearance controls in the live specimen to compare the documented states. The application owns validation, operation results and persistence.
API reference
NumberFieldProps
| Prop | Type | Default | Description |
|---|---|---|---|
label? | | — | Visible label, or inherit an enclosing Field. |
helper? | | — | Instructions under the field; an error or success message replaces it. |
error? | | — | Validation message: a destructive ring, an alert glyph, one shake and an error haptic. |
success? | | — | Confirmation under the field, such as "Username available", in the success colour. |
status? | | |
|
required? | | | Required; "Required" is spoken, and |
requiredIndicator? | | | How a required label is marked: a muted asterisk, the word, or nothing. |
optionalIndicator? | | | Show a muted "Optional" after the label. |
disabled? | | | Disable editing and accessory actions. |
disabledStyle? | | |
|
appearance? | | | The surface: |
size? | | | Height: |
shape? | | |
|
labelPlacement? | | |
|
focusRing? | | | The focus indicator: a primary ring with a soft halo, the ring alone, or none. |
messageMorph? | | | How a changed message arrives: rises in, letter by letter, or at once. |
reserveMessageSpace? | | | Keep one line of room under the field so forms don't move as messages appear. |
displayValue? | | — | Decorative rendering for an unfocused value; the native text remains the accessible/editable source. |
leadingIcon? | | — | A leading icon: a node, or a function given the state colour and size. It turns primary while focused. |
trailingIcon? | | — | A trailing icon: a node, or a function given the state colour and size. |
clearButton? | | | When a "Clear text" button shows. |
undoClear? | | | After clearing, the button becomes "Undo clear" for a moment. Phones have no ⌘Z. |
undoClearWindow? | | | How long undo stays, in milliseconds. |
counter? | | | A rolling character counter under the field, using |
tintCaret? | | | Caret and selection in the primary colour. |
iconTint? | | | The leading icon turns primary while focused ( |
shakeOnError? | | | Shake once for each new error. Reduce Motion keeps it still. |
messages? | | | Built-in strings, for translation. |
nextRef? | | — | Ref focused when Return is pressed; otherwise a single-line field dismisses. |
haptics? | | | All feedback, or each part: |
motion? | | | Ring, label and message motion. |
className? | | — | Classes on the outer field. |
controlClassName? | | — | Classes on the field surface. |
inputClassName? | | — | Classes on the editable text. |
style? | | — | Outer field style. |
inputStyle? | | — | Native editable text style. |
value? | | — | Controlled numeric value. |
defaultValue? | | | Initial value. |
onValueChange? | | — | Reports accepted finite values. |
min? | | — | Optional lower bound. |
max? | | — | Optional upper bound. |
step? | | | Increment per button/detent. |
variant? | | | Buttons and keyboard entry, or horizontal scrubbing. |
repeatInterval? | | | Milliseconds between repeats after a long press; functional timing. |
width? | | |
|
align? | | | Where a |
scrubSlider? | | | Scrub: hold the value to bring up a ruler, drag along it, and let go to hide it. Off scrubs straight away with a sideways drag. |
scrubPlacement? | | | Scrub: whether the ruler rises above the field or drops below it. |
scrubDelay? | | | Scrub: how long to hold before the ruler appears, in milliseconds (gesture timing). |
scrubHint? | | | Scrub: show small arrows either side of the value, so it reads as draggable. |
Native view/input props not listed here pass through where the exported TypeScript type allows them.
Number field settings
| Prop | Does | Default |
|---|---|---|
| width | fit (compact, centred) or full | fit |
| align | Where a fit field, its label and message sit: start, center or end | center |
| scrubPlacement | Scrub: the ruler rises above the field or drops below it | above |
| scrubSlider | Scrub: hold to raise a ruler, drag, release to hide; off scrubs on a sideways drag | true |
| scrubDelay | Scrub: hold before the ruler appears (ms) | 250 |
| scrubHint | Scrub: arrows either side of the value | true |
Composition and behavior
- variant is stepper (buttons and typing) or scrub (drag sideways).
- min, max and step bound the value.
- repeatInterval sets the hold-to-repeat speed (100 ms).
Behavior and gestures
- Tap minus or plus to change by step; buttons disable at the minimum or maximum.
- Press and hold a button to repeat every 100 milliseconds until you let go.
- Type a number directly; values outside the bounds are clamped.
- In the scrub variant, drag sideways: every 12 points changes the value by one step.
- Each change plays a light selection tick.
Accessibility
- The control is adjustable: swipe up or down with VoiceOver, or use increment and decrement actions.
- It reports its current value, minimum and maximum.
- The buttons are named Decrease and Increase.
- Scrubbing is never required; the actions do the same thing.
Motion
- Uses the
pressmotion role, so it follows your app's feel. Passmotionto tune this one instance. - Digits roll with Slot text when the value changes.
- Reduce Motion changes digits instantly.
Performance
- Scrubbing runs on the UI thread and commits once on release.
- Repeat timers stop when you let go or the field is disabled.
Notes for AI
- Set min, max and step; step can be a decimal like 0.5.
Compatibility
| Runs on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.