Allow focus on the last character in Text Input (#65)

This commit is contained in:
Daniil Khanin 2017-09-23 09:15:01 +03:00 committed by Allen
parent f6eea2f659
commit ba7c2e9bb7

View File

@ -1,21 +1,31 @@
/* eslint no-return-assign: 0 */
import React, { Component } from 'react';
import PropTypes from 'prop-types';
class TextEditor extends Component {
componentDidMount() {
const { defaultValue } = this.props;
this.text.value = defaultValue;
this.text.focus();
}
render() {
const { defaultValue, ...rest } = this.props;
return (
<input
ref={ node => this.text = node }
type="text"
className="form-control editor edit-text"
{ ...this.props }
{ ...rest }
/>
);
}
}
TextEditor.propTypes = {
defaultValue: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number
]).isRequired
};
export default TextEditor;