项目作者: yairEO

项目描述 :
Renders native number input as a locale number (on blur) and reverts back to a workable number (on focus)
高级语言: JavaScript
项目地址: git://github.com/yairEO/react-number-input.git
创建时间: 2021-01-23T08:55:00Z
项目社区:https://github.com/yairEO/react-number-input

开源协议:

下载




converts input type number to locale string and back










React number-input component

Converts an <input type"number"> to a nicely-printed locale-based string when the input field
has no focus, and when it receives focus, the input field reverts back to type number so it could be edited easily.

Supports currency transformation (AKA money) based on Number.prototype.toLocaleString.


Install

  1. npm i @yaireo/react-number-input -s

Example usage (with currency)

  1. import NumberInput from '@yaireo/react-number-input'
  2. const MyComponent = () => (
  3. <NumberInput localeOptions={{
  4. maximumFractionDigits:2,
  5. currency:"USD",
  6. style:"currency",
  7. currencyDisplay:"symbol"
  8. }}
  9. ></NumberInput>
  10. )

Props

Prop Type Default Info
placeholder string
name string
inputMode string "decimal" MDN docs
onChange function
defaultValue number ""
localeOptions Object MDN docs