Skip to content

Commit

Permalink
Fixed #217
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yadav committed Sep 2, 2018
1 parent e4266af commit b5b81ab
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 10 deletions.
4 changes: 3 additions & 1 deletion dist/react-number-format.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* react-number-format - 3.5.1
* react-number-format - 3.5.2
* Author : Sudhanshu Yadav
* Copyright (c) 2016,2018 to Sudhanshu Yadav - ignitersworld.com , released under the MIT license.
*/
Expand Down Expand Up @@ -952,6 +952,8 @@ return /******/ (function(modules) { // webpackBootstrap
var _numAsString2 = this.removeFormatting(newValue);
var valueObj = this.getValueObject(newValue, _numAsString2);

//persist event before performing async task
e.persist();
this.setState({ value: newValue, numAsString: _numAsString2 }, function () {
_this3.setPatchedCaretPosition(el, newCaretPosition, newValue);
onValueChange(valueObj, e);
Expand Down
4 changes: 2 additions & 2 deletions dist/react-number-format.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/number_format.js
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,8 @@ var NumberFormat = function (_React$Component) {
var _numAsString2 = this.removeFormatting(newValue);
var valueObj = this.getValueObject(newValue, _numAsString2);

//persist event before performing async task
e.persist();
this.setState({ value: newValue, numAsString: _numAsString2 }, function () {
_this3.setPatchedCaretPosition(el, newCaretPosition, newValue);
onValueChange(valueObj, e);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-number-format",
"description": "React component to format number in an input or as a text.",
"version": "3.5.1",
"version": "3.5.2",
"main": "lib/number_format.js",
"author": "Sudhanshu Yadav",
"license": "MIT",
Expand Down
2 changes: 2 additions & 0 deletions src/number_format.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,8 @@ class NumberFormat extends React.Component {
const numAsString = this.removeFormatting(newValue);
const valueObj = this.getValueObject(newValue, numAsString);

//persist event before performing async task
e.persist();
this.setState({value: newValue, numAsString}, () => {
this.setPatchedCaretPosition(el, newCaretPosition, newValue);
onValueChange(valueObj, e);
Expand Down
6 changes: 5 additions & 1 deletion test/library/keypress_and_caret.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import NumberFormat from '../../src/number_format';

import {simulateKeyInput, simulateMousUpEvent, simulateFocusEvent, shallow} from '../test_util';
import {simulateKeyInput, simulateMousUpEvent, simulateFocusEvent, shallow, persist} from '../test_util';
import {cardExpiry} from '../../custom_formatters/card_expiry';

describe('Test character insertion', () => {
Expand Down Expand Up @@ -106,6 +106,7 @@ describe('Test delete/backspace with format pattern', () => {

beforeEach(() => {
caretPos = 0;
persist.calls.reset();
})

it('caret position should not change if its on starting of input area', () => {
Expand Down Expand Up @@ -148,6 +149,7 @@ describe('Test delete/backspace with numeric format', () => {

beforeEach(() => {
caretPos = 0;
persist.calls.reset();
})

it('should not remove prefix', () => {
Expand Down Expand Up @@ -220,6 +222,7 @@ describe('Test delete/backspace with numeric format', () => {
expect(wrapper.state().value).toEqual('$1,000');
expect(caretPos).toEqual(1);
expect(spy).toHaveBeenCalled();
expect(persist).toHaveBeenCalledWith('keydown');
});
})

Expand Down Expand Up @@ -281,6 +284,7 @@ describe('Test click / focus on input', () => {

beforeEach(() => {
caretPos = 0;
persist.calls.reset();
})

it('should always keep caret on typable area when we click on the input', () => {
Expand Down
13 changes: 8 additions & 5 deletions test/test_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ Enzyme.configure({ adapter: new Adapter() });

const noop = function(){};

export const persist = jasmine.createSpy();

export function getCustomEvent(value, selectionStart, selectionEnd) {
let event = new Event('custom');
const el = document.createElement('input');
event = Object.assign({}, event, {target: el, persist: noop});
event = Object.assign({}, event, {target: el, persist});
event.target = el;
el.value = value;
el.selectionStart = selectionStart;
Expand Down Expand Up @@ -49,7 +51,8 @@ export function simulateKeyInput(input, key, selectionStart, selectionEnd, setSe
defaultPrevented = true;
},
key,
isUnitTestRun: true
isUnitTestRun: true,
persist: persist.bind(null, 'keydown')
}, {
value: currentValue,
selectionStart,
Expand Down Expand Up @@ -85,7 +88,7 @@ export function simulateKeyInput(input, key, selectionStart, selectionEnd, setSe
}

const changeEvent = getEvent({
persist: noop,
persist: persist.bind(null, 'change'),
key
}, {
value: newValue,
Expand Down Expand Up @@ -121,7 +124,7 @@ export function simulateFocusEvent(input, selectionStart, setSelectionRange) {
const currentValue = input.prop('value');

const focusEvent = getEvent({
persist: noop,
persist: persist.bind(null, 'focus')
}, {
value: currentValue,
selectionStart,
Expand All @@ -138,7 +141,7 @@ export function simulateBlurEvent(input) {
const currentValue = input.prop('value');

const blurEvent = getEvent({
persist: noop
persist: persist.bind(null, 'blur')
}, {
value: currentValue,
});
Expand Down

0 comments on commit b5b81ab

Please sign in to comment.