Added method of adding a ref without interfering with components created outside of a context, i.e. when opening a modal on demand.

This commit is contained in:
Tim Brandin 2016-04-16 11:13:58 +02:00
parent 5078f6b2ce
commit b0a0c8a25e

View file

@ -14,8 +14,8 @@ export class Field extends React.Component {
// Trigger an onChange on inital load, to support browser prefilled values. // Trigger an onChange on inital load, to support browser prefilled values.
const { onChange } = this.props; const { onChange } = this.props;
let node = ReactDOM.findDOMNode(this); let node = ReactDOM.findDOMNode(this);
if (this.refs.input) { if (this.input) {
onChange({ target: { value: this.refs.input.value } }); onChange({ target: { value: this.input.value } });
} }
// Backward compat. // Backward compat.
else if (node) { else if (node) {
@ -55,7 +55,7 @@ export class Field extends React.Component {
<div className={ className }> <div className={ className }>
<label htmlFor={ id }>{ label }</label> <label htmlFor={ id }>{ label }</label>
<input id={ id } <input id={ id }
ref="input" ref={ (ref) => this.input = ref }
type={ type } type={ type }
onChange={ onChange } onChange={ onChange }
placeholder={ hint } placeholder={ hint }