Skip to content

Change vs blur

The formatOn option decides when the thousand separators appear. It has two modes: 'change' (the default) and 'blur'. The raw value you get from onValueChange is the same in both.

Change

The separators update on every keystroke, and the caret stays where the user left it.

import { NumoraInput } from 'numora'

const input = new NumoraInput(container, {
  formatOn: 'change',
  decimalMaxLength: 2,
})

Blur

The input shows plain digits while it has focus. Numora removes the separators when the input takes focus and puts them back when it loses focus.

Blur the field to format.
import { NumoraInput } from 'numora'

const input = new NumoraInput(container, {
  formatOn: 'blur',
  decimalMaxLength: 2,
})

Removing and restoring the separators does not change the raw value, so onValueChange stays silent on focus and blur. onFormattedValueChange reports the new text. Numora groups a value you set from code while the input is unfocused.

onValueChange fires on blur only when blur also changes the raw value. This holds in both modes.

Blur changes the raw value in these cases, and no others:

  • A trailing decimal separator is dropped: 1. becomes 1.
  • decimalMinLength pads the decimals: with 2, 1.5 becomes 1.50.
  • A negative zero loses its sign: -0 becomes 0 and -0.00 becomes 0.00.
  • A value with no digit is cleared: -, . and -. become an empty string.

The demos on this page animate the digits with Torph. See the Torph integration to build them, and Formatting for the grouping styles.