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