NumberFlow integration
NumberFlow by Maxwell Barvian is an animated number transition library. This guide pairs it with Numora React's NumoraInput in two ways. The readout animates a number next to the field and is the recommended one. The overlay draws a <NumberFlow> under a transparent-text input, so the field itself appears animated. It is experimental.
The overlay. With 'change', digits animate on every keystroke.
Installation
Animate a readout next to the input
The user types into a plain NumoraInput. A separate NumberFlow elsewhere on the page, such as a converted amount or a running total, animates as the value changes. Both read the same raw value from state. The input has no transparent text and no caret drift, and NumberFlow cannot change the raw value.
The input does not animate. Only the converted amount does. NumberFlow gets a real number here, so none of the overlay's caveats apply, and the string the user edits never passes through Number.
How the overlay works
Native <input> elements render their value as a string with no child DOM, so animation libraries can't inject animated spans into them directly. The overlay stacks two layers in the same box to get around that:
- Visible layer: a
<NumberFlow>that animates the formatted display number. - Keyboard layer: the real
NumoraInputpositioned on top withcolor: transparentand a visible caret. It still owns focus, keystrokes, selection, IME and mobileinputmode, so paste and native form submission keep working too.
Both layers render the same formatted number. As the user types, Numora React's onValueChange fires. Your handler stores the raw value and passes it to <NumberFlow>, which formats it again and tweens each digit into place. The input never animates. Its text is transparent, so you only see the NumberFlow layer.
The overlay is experimental. It suits short fields where users mostly add digits at the end. NumberFlow formats the number a second time, so every option that changes what the field shows needs a matching NumberFlow setting. Even then the two layers differ in a few states, and the caret runs ahead of the animation. The caveats list them. Torph animates the field's own string, so it has no second formatter to keep in step.
Building the overlay
Why each line matters
formatOn={'change'}is the default, written out because the overlay depends on it. With'blur'a focused field shows no grouping while NumberFlow does, and the caret drifts.- The raw string as
valuekeeps every digit.Intl.NumberFormatformats a numeric string digit for digit, so an 18-decimal token amount stays exact and"-0."keeps its sign.Number(value) || 0is exact only up to about 15 significant digits and turns"-0."into0.. The cast needs TypeScript'sES2023lib. With an older lib, writeas unknown as number. Chrome 106, Safari 15.4, Firefox 116 and later format the string exactly. Older browsers read it as aNumber. Either way, the string fromonValueChangeis the value you store and send. suffixdraws the dot the user just typed."1."is the number1, so without it NumberFlow shows"1"and the caret sits one character past the visible text until a fraction digit arrives.padLeadingZeroturns a typed"."into"0.". NumberFlow always prints the leading zero ("0.5"), so the input has to hold it too.- Dynamic
minimumFractionDigitskeeps trailing zeros.Intldrops them, so without it NumberFlow draws"1.2"while the input holds"1.20", and the caret sits one character past the visible text.decimalscounts the fraction digits in the raw value. useGrouping: trueandlocales="en-US"make NumberFlow group the way the input does. Withoutlocales, NumberFlow formats in the visitor's browser locale, which may not use","and".", Numora React's defaults.[font:inherit]gives the input the label's font, size and line height. The browser computes the caret position from the input's text layout, so if the fonts differ, the caret drifts.tabular-numson the label keeps every digit the same width while NumberFlow animates. On the label it reaches both layers, so the input's digits are as wide as the overlay's.
Caveats
Text NumberFlow cannot show. NumberFlow always draws a number, so an empty field shows 0 in the overlay. With allowNegative, a lone "-" shows 0 until a digit follows. With allowLeadingZeros, "007" shows as 7 and the caret sits two characters past it.
Precision in older browsers. Before Chrome 106, Safari 15.4 and Firefox 116, Intl reads the raw string as a Number, which is exact up to about 15 significant digits. Longer amounts lose their tail digits in the overlay there. The string you get from onValueChange is untouched either way. The overlay only changes what is displayed.
Locales. NumberFlow formats the number itself with Intl, so give it the same locale as the input and keep useGrouping: true. Left to its default, Intl does not group a four-digit number in Spanish and Polish (1234,5) while Numora does (1.234,5 in Spanish, 1 234,5 in Polish).
Locales with their own digits are not supported. For ar-EG, fa-IR, bn-BD and other tags where Intl prints non-ASCII digits, NumberFlow 0.6 draws the separators and no digits. The language alone does not decide it. The bare tag ar prints ASCII digits and works. Numora shows ASCII digits there (1٬234). Passing numberingSystem: 'latn' brings the digits back, but Intl then writes 1,234.5 where the field shows 1٬234٫5, so the layers still differ. A locale is affected when new Intl.NumberFormat(locale).resolvedOptions().numberingSystem is not 'latn'. Use Torph for those.
Custom separators and grouping. NumberFlow can only draw what Intl can format. With groupingStyle="none", pass useGrouping: false and the layers agree. A thousandSeparator or decimalSeparator that is not the locale's own, and groupingStyle="wan" (123,4567), have no Intl equivalent, so the overlay cannot match the field.
Caret drift during animation. The browser places the caret from the input's invisible text, which jumps to the new value at once. NumberFlow takes most of a second, by default, to move its digits there. Until it finishes, the caret sits next to characters that haven't arrived yet.
Mid-string editing is limited. A click on the overlay passes through to the input, and the browser places the caret by the input's invisible text. While NumberFlow is still animating, that click puts the caret next to the wrong character. Fields where users only add digits at the end are not affected. If users edit mid-number, don't use the overlay.
Mobile selection handles. iOS draws magnifier loupes and selection handles anchored to the input's text. The text is transparent, so the loupe shows nothing. Short amounts are usable, but test on a real device.
Try it with any locale
Give NumberFlow's locales prop the same tag as the input's locale. The typed decimal mark is then the last character of formattedValue, so keep both strings in state:
Switch the locale below, then type or paste. The two layers agree in every locale listed. ar-EG and fa-IR are left out, because the overlay does not support locales whose digits are not ASCII. This playground allows eight decimals, and long amounts stay exact.
Read-only animated totals
For read-only sections such as a portfolio summary fed by live prices, skip NumoraInput and use NumberFlow directly. See the NumberFlow docs.
Reducing motion
NumberFlow respects prefers-reduced-motion by default. If a user opts out of animations at the OS level, the digits swap without animating. You need no extra code.
FAQ
What is NumberFlow?
NumberFlow is an animated number transition library by Maxwell Barvian. It tweens between two numeric values by morphing each digit and supports Intl.NumberFormat options for currency and grouping. It has a React component (@number-flow/react) and a vanilla web component (number-flow).
How do I use NumberFlow with React?
Import NumberFlow from @number-flow/react and render it as a readout next to a NumoraInput, fed from the same raw value. To animate the field itself, render NumberFlow under a transparent-text NumoraInput, pass it the raw string as the value prop, and mirror the number of typed decimals through minimumFractionDigits so trailing zeros stay aligned with the caret.
Where can I install NumberFlow?
NumberFlow's docs are at number-flow.barvian.me. It is published on npm as @number-flow/react (React) and number-flow (vanilla web component). Install with npm install numora-react @number-flow/react.