Skip to content

Commit b86ed66

Browse files
committed
Release 3.1.0
1 parent 07f1db3 commit b86ed66

File tree

4 files changed

+57
-43
lines changed

4 files changed

+57
-43
lines changed

dist/react-number-format.js

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* react-number-format - 3.0.3
2+
* react-number-format - 3.1.0
33
* Author : Sudhanshu Yadav
44
* Copyright (c) 2016,2017 to Sudhanshu Yadav - ignitersworld.com , released under the MIT license.
55
*/
@@ -113,7 +113,8 @@ return /******/ (function(modules) { // webpackBootstrap
113113
onBlur: _propTypes2.default.func,
114114
type: _propTypes2.default.oneOf(['text', 'tel']),
115115
isAllowed: _propTypes2.default.func,
116-
renderText: _propTypes2.default.func
116+
renderText: _propTypes2.default.func,
117+
getInputRef: _propTypes2.default.func
117118
};
118119

119120
var defaultProps = {
@@ -131,7 +132,8 @@ return /******/ (function(modules) { // webpackBootstrap
131132
onMouseUp: _utils.noop,
132133
onFocus: _utils.noop,
133134
onBlur: _utils.noop,
134-
isAllowed: _utils.returnTrue
135+
isAllowed: _utils.returnTrue,
136+
getInputRef: _utils.noop
135137
};
136138

137139
var NumberFormat = function (_React$Component) {
@@ -708,7 +710,9 @@ return /******/ (function(modules) { // webpackBootstrap
708710
}, {
709711
key: 'correctInputValue',
710712
value: function correctInputValue(caretPos, lastValue, value) {
711-
var format = this.props.format;
713+
var _props9 = this.props,
714+
format = _props9.format,
715+
decimalSeparator = _props9.decimalSeparator;
712716

713717
var lastNumStr = this.state.numAsString || '';
714718

@@ -742,7 +746,8 @@ return /******/ (function(modules) { // webpackBootstrap
742746
//clear only if something got deleted
743747

744748

745-
if (numericString.length < lastNumStr.length && beforeDecimal === '' && !parseFloat(afterDecimal)) {
749+
var isBeforeDecimalPoint = caretPos < value.indexOf(decimalSeparator) + 1;
750+
if (numericString.length < lastNumStr.length && isBeforeDecimalPoint && beforeDecimal === '' && !parseFloat(afterDecimal)) {
746751
return addNegation ? '-' : '';
747752
}
748753
}
@@ -840,13 +845,13 @@ return /******/ (function(modules) { // webpackBootstrap
840845
var selectionStart = el.selectionStart;
841846

842847
var expectedCaretPosition = void 0;
843-
var _props9 = this.props,
844-
decimalScale = _props9.decimalScale,
845-
fixedDecimalScale = _props9.fixedDecimalScale,
846-
prefix = _props9.prefix,
847-
suffix = _props9.suffix,
848-
format = _props9.format,
849-
onKeyDown = _props9.onKeyDown;
848+
var _props10 = this.props,
849+
decimalScale = _props10.decimalScale,
850+
fixedDecimalScale = _props10.fixedDecimalScale,
851+
prefix = _props10.prefix,
852+
suffix = _props10.suffix,
853+
format = _props10.format,
854+
onKeyDown = _props10.onKeyDown;
850855

851856
var ignoreDecimalSeparator = decimalScale !== undefined && fixedDecimalScale;
852857
var numRegex = this.getNumberRegex(false, ignoreDecimalSeparator);
@@ -941,16 +946,17 @@ return /******/ (function(modules) { // webpackBootstrap
941946
}
942947

943948
_this2.props.onFocus(e);
944-
});
949+
}, 0);
945950
}
946951
}, {
947952
key: 'render',
948953
value: function render() {
949-
var _props10 = this.props,
950-
type = _props10.type,
951-
displayType = _props10.displayType,
952-
customInput = _props10.customInput,
953-
renderText = _props10.renderText;
954+
var _props11 = this.props,
955+
type = _props11.type,
956+
displayType = _props11.displayType,
957+
customInput = _props11.customInput,
958+
renderText = _props11.renderText,
959+
getInputRef = _props11.getInputRef;
954960
var value = this.state.value;
955961

956962

@@ -963,13 +969,14 @@ return /******/ (function(modules) { // webpackBootstrap
963969
onKeyDown: this.onKeyDown,
964970
onMouseUp: this.onMouseUp,
965971
onFocus: this.onFocus,
966-
onBlur: this.onBlur
972+
onBlur: this.onBlur,
973+
ref: getInputRef
967974
});
968975

969976
if (displayType === 'text') {
970977
return renderText ? renderText(value) || null : _react2.default.createElement(
971978
'span',
972-
otherProps,
979+
_extends({}, otherProps, { ref: getInputRef }),
973980
value
974981
);
975982
} else if (customInput) {

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: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ var propTypes = {
4545
onBlur: _propTypes2.default.func,
4646
type: _propTypes2.default.oneOf(['text', 'tel']),
4747
isAllowed: _propTypes2.default.func,
48-
renderText: _propTypes2.default.func
48+
renderText: _propTypes2.default.func,
49+
getInputRef: _propTypes2.default.func
4950
};
5051

5152
var defaultProps = {
@@ -63,7 +64,8 @@ var defaultProps = {
6364
onMouseUp: _utils.noop,
6465
onFocus: _utils.noop,
6566
onBlur: _utils.noop,
66-
isAllowed: _utils.returnTrue
67+
isAllowed: _utils.returnTrue,
68+
getInputRef: _utils.noop
6769
};
6870

6971
var NumberFormat = function (_React$Component) {
@@ -640,7 +642,9 @@ var NumberFormat = function (_React$Component) {
640642
}, {
641643
key: 'correctInputValue',
642644
value: function correctInputValue(caretPos, lastValue, value) {
643-
var format = this.props.format;
645+
var _props9 = this.props,
646+
format = _props9.format,
647+
decimalSeparator = _props9.decimalSeparator;
644648

645649
var lastNumStr = this.state.numAsString || '';
646650

@@ -674,7 +678,8 @@ var NumberFormat = function (_React$Component) {
674678
//clear only if something got deleted
675679

676680

677-
if (numericString.length < lastNumStr.length && beforeDecimal === '' && !parseFloat(afterDecimal)) {
681+
var isBeforeDecimalPoint = caretPos < value.indexOf(decimalSeparator) + 1;
682+
if (numericString.length < lastNumStr.length && isBeforeDecimalPoint && beforeDecimal === '' && !parseFloat(afterDecimal)) {
678683
return addNegation ? '-' : '';
679684
}
680685
}
@@ -772,13 +777,13 @@ var NumberFormat = function (_React$Component) {
772777
var selectionStart = el.selectionStart;
773778

774779
var expectedCaretPosition = void 0;
775-
var _props9 = this.props,
776-
decimalScale = _props9.decimalScale,
777-
fixedDecimalScale = _props9.fixedDecimalScale,
778-
prefix = _props9.prefix,
779-
suffix = _props9.suffix,
780-
format = _props9.format,
781-
onKeyDown = _props9.onKeyDown;
780+
var _props10 = this.props,
781+
decimalScale = _props10.decimalScale,
782+
fixedDecimalScale = _props10.fixedDecimalScale,
783+
prefix = _props10.prefix,
784+
suffix = _props10.suffix,
785+
format = _props10.format,
786+
onKeyDown = _props10.onKeyDown;
782787

783788
var ignoreDecimalSeparator = decimalScale !== undefined && fixedDecimalScale;
784789
var numRegex = this.getNumberRegex(false, ignoreDecimalSeparator);
@@ -873,16 +878,17 @@ var NumberFormat = function (_React$Component) {
873878
}
874879

875880
_this2.props.onFocus(e);
876-
});
881+
}, 0);
877882
}
878883
}, {
879884
key: 'render',
880885
value: function render() {
881-
var _props10 = this.props,
882-
type = _props10.type,
883-
displayType = _props10.displayType,
884-
customInput = _props10.customInput,
885-
renderText = _props10.renderText;
886+
var _props11 = this.props,
887+
type = _props11.type,
888+
displayType = _props11.displayType,
889+
customInput = _props11.customInput,
890+
renderText = _props11.renderText,
891+
getInputRef = _props11.getInputRef;
886892
var value = this.state.value;
887893

888894

@@ -895,13 +901,14 @@ var NumberFormat = function (_React$Component) {
895901
onKeyDown: this.onKeyDown,
896902
onMouseUp: this.onMouseUp,
897903
onFocus: this.onFocus,
898-
onBlur: this.onBlur
904+
onBlur: this.onBlur,
905+
ref: getInputRef
899906
});
900907

901908
if (displayType === 'text') {
902909
return renderText ? renderText(value) || null : _react2.default.createElement(
903910
'span',
904-
otherProps,
911+
_extends({}, otherProps, { ref: getInputRef }),
905912
value
906913
);
907914
} else if (customInput) {

package.json

Lines changed: 2 additions & 2 deletions
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.3",
4+
"version": "3.1.0",
55
"main": "lib/number_format.js",
66
"author": "Sudhanshu Yadav",
77
"license": "MIT",
@@ -24,7 +24,7 @@
2424
],
2525
"scripts": {
2626
"start": "webpack-dev-server --content-base example/ --config webpack.dev.config.js --watch-poll --progress --inline --hot",
27-
"bundle": "cross-env NODE_ENV=production npm run compile && cross-env NODE_ENV=production webpack --config webpack.bundle.config.js && cross-env NODE_ENV=production karma start",
27+
"bundle": "cross-env NODE_ENV=production npm run compile && cross-env NODE_ENV=production webpack --config webpack.bundle.config.js && cross-env NODE_ENV=production TEST_BROWSER=ChromeHeadless karma start",
2828
"compile": "cross-env NODE_ENV=production babel src --out-dir lib",
2929
"test": "cross-env NODE_ENV=test karma start",
3030
"lint": "cross-env eslint src/**"

0 commit comments

Comments
 (0)