Skip to content

Commit 0cd0c99

Browse files
committed
V3 Release 🎉
1 parent 2337e62 commit 0cd0c99

File tree

5 files changed

+54
-22
lines changed

5 files changed

+54
-22
lines changed

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@ Through npm
1616

1717
Or get compiled development and production version from ./dist
1818

19+
### Usage
20+
ES6
21+
```js
22+
import NumberFormat from 'react-number-format';
23+
```
24+
25+
ES5
26+
```js
27+
const NumberFormat = require('react-number-format');
28+
```
29+
30+
Typescript
31+
```js
32+
import * as NumberFormat from 'react-number-format';
33+
```
34+
35+
1936
### Props
2037
| Props | Options | Default | Description |
2138
| ------------- |-------------| -----| -------- |
@@ -118,7 +135,7 @@ Mask can also be a array of string. Each item corresponds to the same index #.
118135
```jsx
119136
<NumberFormat format="##/##" placeholder="MM/YY" mask={['M', 'M', 'Y', 'Y']}/>
120137
```
121-
138+
![Screencast example](https://media.giphy.com/media/xT9IgojmLf6x3jX0nS/giphy.gif)
122139

123140
#### Custom format method : Format credit card expiry time
124141
```jsx
@@ -155,6 +172,7 @@ function cardExpiry(val) {
155172
```jsx
156173
<NumberFormat format="+1 (###) ###-####" mask="_"/>
157174
```
175+
![Screencast example](https://media.giphy.com/media/l1J9wJ6ZSONO7cXkI/giphy.gif)
158176

159177
### Custom Inputs
160178
You can easily extend your custom input with number format. But custom input should have all input props.
@@ -190,7 +208,7 @@ All custom input props and number input props are passed together.
190208
- mask can be now array of string in which case mask at specific index will be mapped with the # of the pattern.
191209
- Value can be passed as string or number, but if it is passed as string it should be either formatted value or if it is a numeric string, you have to set isNumericString props to true.
192210
- Added support for numbers in prefix / suffix / pattern.
193-
- Fixed caret position issues.
211+
- Fixed caret position and formatting issues.
194212
- Lot of bugs and stability fixes ([See v3 tracker](https://github.com/s-yadav/react-number-format/issues/99))
195213

196214
### v2.0.0

dist/react-number-format.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* react-number-format - 3.0.0-beta3
2+
* react-number-format - 3.0.0
33
* Author : Sudhanshu Yadav
44
* Copyright (c) 2016,2017 to Sudhanshu Yadav - ignitersworld.com , released under the MIT license.
55
*/
@@ -922,17 +922,24 @@ return /******/ (function(modules) { // webpackBootstrap
922922
}, {
923923
key: 'onFocus',
924924
value: function onFocus(e) {
925-
var el = e.target;
926-
var selectionStart = el.selectionStart,
927-
value = el.value;
925+
var _this2 = this;
928926

927+
// Workaround Chrome and Safari bug https://bugs.chromium.org/p/chromium/issues/detail?id=779328
928+
// (onFocus event target selectionStart is always 0 before setTimeout)
929+
e.persist();
930+
setTimeout(function () {
931+
var el = e.target;
932+
var selectionStart = el.selectionStart,
933+
value = el.value;
929934

930-
var caretPostion = this.correctCaretPosition(value, selectionStart);
931-
if (caretPostion !== selectionStart) {
932-
this.setPatchedCaretPosition(el, caretPostion, value);
933-
}
934935

935-
this.props.onFocus(e);
936+
var caretPosition = _this2.correctCaretPosition(value, selectionStart);
937+
if (caretPosition !== selectionStart) {
938+
_this2.setPatchedCaretPosition(el, caretPosition, value);
939+
}
940+
941+
_this2.props.onFocus(e);
942+
});
936943
}
937944
}, {
938945
key: 'render',

dist/react-number-format.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/number_format.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -854,17 +854,24 @@ var NumberFormat = function (_React$Component) {
854854
}, {
855855
key: 'onFocus',
856856
value: function onFocus(e) {
857-
var el = e.target;
858-
var selectionStart = el.selectionStart,
859-
value = el.value;
857+
var _this2 = this;
860858

859+
// Workaround Chrome and Safari bug https://bugs.chromium.org/p/chromium/issues/detail?id=779328
860+
// (onFocus event target selectionStart is always 0 before setTimeout)
861+
e.persist();
862+
setTimeout(function () {
863+
var el = e.target;
864+
var selectionStart = el.selectionStart,
865+
value = el.value;
861866

862-
var caretPostion = this.correctCaretPosition(value, selectionStart);
863-
if (caretPostion !== selectionStart) {
864-
this.setPatchedCaretPosition(el, caretPostion, value);
865-
}
866867

867-
this.props.onFocus(e);
868+
var caretPosition = _this2.correctCaretPosition(value, selectionStart);
869+
if (caretPosition !== selectionStart) {
870+
_this2.setPatchedCaretPosition(el, caretPosition, value);
871+
}
872+
873+
_this2.props.onFocus(e);
874+
});
868875
}
869876
}, {
870877
key: 'render',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-number-format",
33
"description": "React component to format number in an input or as a text.",
4-
"version": "3.0.0-beta3",
4+
"version": "3.0.0",
55
"main": "lib/number_format.js",
66
"author": "Sudhanshu Yadav",
77
"license": "MIT",

0 commit comments

Comments
 (0)