Skip to content

Formatting

Formatting groups the digits of the value with thousand separators. groupingStyle defaults to 'thousand', and 'none' turns grouping off. Formatting runs on every keystroke by default, or only on blur with 'blur'. Numora keeps the cursor in place either way.

Grouping styles

Wan grouping: 1234,5678

Groups of 4 from the right.

Grouping style
import { NumoraInput } from 'numora'

// Thousand (1,234,567)
const input1 = new NumoraInput(container, {
  groupingStyle: 'thousand',
})

// Lakh (Indian, 12,34,567)
const input2 = new NumoraInput(container, {
  groupingStyle: 'lakh',
})

// Wan (East Asian, 123,4567)
const input3 = new NumoraInput(container, {
  groupingStyle: 'wan',
})

// None (1234567)
const input4 = new NumoraInput(container, {
  groupingStyle: 'none',
})

When to format

The separators appear on every keystroke by default, or only on blur with formatOn: 'blur'. See Change vs blur for both modes.

Caret position

When the separators move, the caret stays between the same two digits:

Naive formatter

NumoraInput

The 9 lands at the end in naive. Numora puts it after the 8.

Without that, a production app looks like this:

The caret is put inside the number and one digit is deleted. Each time, the caret lands at the end.

Separator skipping

  • Backspace and Delete jump over thousand separators, so you never delete one by hand.
  • This applies with formatOn: 'change', a thousand separator set and no text selected. In blur mode a focused field has no separators to skip.
  • Two handlers share the work. keydown moves the cursor over the separator, and beforeinput deletes the digit. Mobile keyboards that send no usable keydown still work, because beforeinput then deletes the digit past the separator itself.
Backspace after a comma
With Numora

beforeinput then deletes the 1.