Skip to content

React >= 14.0.0 support. fixes #19 #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Require:
```js
Input = require('react-input-placeholder')(React).Input;
Textarea = require('react-input-placeholder')(React).Textarea;

// React >= 14.0.0
Input = require('react-input-placeholder')(React, ReactDom).Input;
Textarea = require('react-input-placeholder')(React, ReactDom).Textarea;
```

### No module
Expand Down
23 changes: 16 additions & 7 deletions src/react-input-placeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var isPlaceholderSupported = (typeof document !== 'undefined')
* Input is a wrapper around React.DOM.input with a `placeholder` shim for IE9.
* NOTE: only supports "controlled" inputs (http://facebook.github.io/react/docs/forms.html#controlled-components)
*/
var createShimmedElement = function(React, elementConstructor, name) {
var createShimmedElement = function(React, _getDOMNode, elementConstructor, name) {
return React.createClass({
displayName: name,

Expand Down Expand Up @@ -97,7 +97,7 @@ var createShimmedElement = function(React, elementConstructor, name) {
},

componentDidUpdate: function() {
this.setSelectionIfNeeded(this.getDOMNode());
this.setSelectionIfNeeded(this.getDOMNode && this.getDOMNode() || _getDOMNode(this));
},

render: function() {
Expand Down Expand Up @@ -141,16 +141,25 @@ var createShimmedElement = function(React, elementConstructor, name) {
});
};

module.exports = function(React) {
module.exports = function(React, ReactDom) {
var _domNode;
if (React.findDOMNode) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking we should reduce the complexity a bit and just always require ReactDOM... what do you think?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with bumping the major version to enforce the change.

_domNode = React.findDOMNode;
} else if (ReactDom && ReactDom.findDOMNode) {
_domNode = ReactDom.findDOMNode;
} else {
throw new Error("constructor(): Seems you are using React >= 14.0.0. It requires ReactDom as second argument.");
}

if (!('createElement' in React)) { /* start -- to be removed in 2.0.0 */
return {
Input: createShimmedElement(React, React.DOM.input, 'Input'),
Textarea: createShimmedElement(React, React.DOM.textarea, 'Textarea')
Input: createShimmedElement(React, _domNode, React.DOM.input, 'Input'),
Textarea: createShimmedElement(React, _domNode, React.DOM.textarea, 'Textarea')
};
} else { /* -- end */
return {
Input: createShimmedElement(React, 'input', 'Input'),
Textarea: createShimmedElement(React, 'textarea', 'Textarea')
Input: createShimmedElement(React, _domNode, 'input', 'Input'),
Textarea: createShimmedElement(React, _domNode, 'textarea', 'Textarea')
};
}
};
8 changes: 4 additions & 4 deletions src/umd.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*global define*/
var reactInputPlaceholder = require('./react-input-placeholder');
if (typeof define === 'function' && define.amd) {
define(['react'], function (React) {
return reactInputPlaceholder(React);
define(['react', 'react-dom'], function (React, ReactDom) {
return reactInputPlaceholder(React, ReactDom);
});
} else {
window.PlaceholderShim = reactInputPlaceholder(window.React);
}
window.PlaceholderShim = reactInputPlaceholder(window.React, window.ReactDom);
}