Skip to content
This repository was archived by the owner on Aug 7, 2025. It is now read-only.

Commit b8adf83

Browse files
committed
Merge pull request #7 from Gusto/upgrade-react
Fix to work with React 15.0
2 parents bbddad5 + a4fa52f commit b8adf83

File tree

3 files changed

+28
-23
lines changed

3 files changed

+28
-23
lines changed

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"masked-input"
2727
],
2828
"peerDependencies": {
29-
"react": ">=0.13.0"
29+
"react": "^0.14 || ^15.0.0-rc || ^15.0",
30+
"react-dom": "^0.14 || ^15.0.0-rc || ^15.0"
3031
},
3132
"devDependencies": {
3233
"babel-cli": "^6.5.1",
@@ -46,7 +47,9 @@
4647
"karma-mocha": "^0.2.2",
4748
"karma-mocha-reporter": "^2.0.0",
4849
"mocha": "^2.4.5",
49-
"react": "^0.13.3",
50+
"react": "^15.0.1",
51+
"react-addons-test-utils": "^15.0.1",
52+
"react-dom": "^15.0.1",
5053
"sinon": "^1.17.1",
5154
"sinon-chai": "^2.8.0",
5255
"uglify-js": "^2.6.2",

spec/MaskedField_spec.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2-
import TestUtils from 'react/lib/ReactTestUtils';
2+
import ReactDOM from 'react-dom';
3+
import TestUtils from 'react-addons-test-utils';
34
import LinkedStateMixin from 'react/lib/LinkedStateMixin';
45
import MaskedField from '../src/MaskedField';
56
import * as EventUtils from './EventUtils';
@@ -20,8 +21,8 @@ describe('MaskedField', function() {
2021
// - undo?
2122

2223
function getFieldValue() {
23-
const inputComponent = TestUtils.findRenderedDOMComponentWithTag(getField(), 'input');
24-
return React.findDOMNode(inputComponent).value;
24+
const input = TestUtils.findRenderedDOMComponentWithTag(getField(), 'input');
25+
return input.value;
2526
}
2627

2728
function cursorPosShouldEql(pos) {
@@ -819,7 +820,7 @@ describe('MaskedField', function() {
819820
});
820821

821822
afterEach(function() {
822-
React.unmountComponentAtNode(container);
823+
ReactDOM.unmountComponentAtNode(container);
823824
});
824825

825826
context("when the component isn't controlled", function() {
@@ -832,8 +833,8 @@ describe('MaskedField', function() {
832833
if (props.value && !props.onChange) {
833834
props.readOnly = true;
834835
}
835-
component = React.render(<MaskedField {...props} />, container);
836-
domNode = React.findDOMNode(component);
836+
component = ReactDOM.render(<MaskedField {...props} />, container);
837+
domNode = ReactDOM.findDOMNode(component);
837838
});
838839

839840
afterEach(function() {
@@ -910,8 +911,8 @@ describe('MaskedField', function() {
910911
});
911912

912913
beforeEach(function() {
913-
component = React.render(<ControlledWrapper {...props} />, container);
914-
domNode = React.findDOMNode(component);
914+
component = ReactDOM.render(<ControlledWrapper {...props} />, container);
915+
domNode = ReactDOM.findDOMNode(component);
915916
});
916917

917918
setupTests(function() {
@@ -984,11 +985,11 @@ describe('MaskedField', function() {
984985
});
985986

986987
beforeEach(function() {
987-
component = React.render(
988+
component = ReactDOM.render(
988989
<LinkWrapper mask='99/99/9999' value={value} />,
989990
container
990991
);
991-
domNode = React.findDOMNode(component);
992+
domNode = ReactDOM.findDOMNode(component);
992993
return simulateFocus();
993994
});
994995

@@ -1032,12 +1033,14 @@ describe('MaskedField', function() {
10321033
});
10331034

10341035
context('when the parent component contains multiple inputs', function() {
1036+
let inputNode;
1037+
let fieldComponent;
10351038
const Parent = React.createClass({
10361039
render() {
10371040
return (
10381041
<div>
1039-
<input onChange={this._onChange} ref='input' />
1040-
<MaskedField mask='99-99-9999' ref='field' />
1042+
<input onChange={this._onChange} ref={c => (inputNode = c)} />
1043+
<MaskedField mask='99-99-9999' ref={c => (fieldComponent = c)} />
10411044
</div>
10421045
);
10431046
},
@@ -1047,21 +1050,21 @@ describe('MaskedField', function() {
10471050
});
10481051

10491052
beforeEach(function() {
1050-
component = React.render(
1053+
component = ReactDOM.render(
10511054
<Parent />,
10521055
container
10531056
);
1054-
return EventUtils.simulateFocus(React.findDOMNode(component.refs.input));
1057+
return EventUtils.simulateFocus(inputNode);
10551058
});
10561059

10571060
context('when the masked field does not have focus', function() {
10581061
let fieldNode;
10591062

10601063
describe('typing into a sibling input', function() {
10611064
beforeEach(function() {
1062-
fieldNode = React.findDOMNode(component.refs.field);
1065+
fieldNode = ReactDOM.findDOMNode(fieldComponent);
10631066
sinon.spy(fieldNode, 'setSelectionRange');
1064-
EventUtils.simulateChange(React.findDOMNode(component.refs.input), 'hello');
1067+
EventUtils.simulateChange(inputNode, 'hello');
10651068
});
10661069

10671070
afterEach(function() {

src/MaskedField.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,19 @@ const MaskedField = React.createClass({
7676
}
7777
}
7878

79-
return <input {...this.props} {...props} type='text' />;
79+
return <input ref={c => (this._input = c)} {...this.props} {...props} type='text' />;
8080
},
8181
_getSelection() {
8282
if (this._isMounted) {
83-
return getSelection(React.findDOMNode(this));
83+
return getSelection(this._input);
8484
} else {
8585
const cursorPos = (this._getPropsValue() || '').length;
8686
return {start: cursorPos, end: cursorPos};
8787
}
8888
},
8989
_setSelection(start, end = start) {
90-
const domNode = React.findDOMNode(this);
91-
if (domNode === document.activeElement) {
92-
setSelection(domNode, start, end);
90+
if (this._input === document.activeElement) {
91+
setSelection(this._input, start, end);
9392
}
9493
},
9594
_getPropsValue() {

0 commit comments

Comments
 (0)