Autofocus first field on forms (#191)

This commit is contained in:
Mike Stone
2016-09-19 14:33:43 -04:00
committed by GitHub
parent 0e08a6e698
commit 09178a9ee8
4 changed files with 15 additions and 0 deletions
@@ -5,6 +5,7 @@ import componentStyles from './styles';
class InputFieldWithIcon extends Component {
static propTypes = {
autofocus: PropTypes.bool,
error: PropTypes.string,
iconName: PropTypes.string,
name: PropTypes.string,
@@ -15,6 +16,7 @@ class InputFieldWithIcon extends Component {
};
static defaultProps = {
autofocus: false,
style: {},
type: 'text',
};
@@ -24,6 +26,15 @@ class InputFieldWithIcon extends Component {
this.state = { value: null };
}
componentDidMount () {
const { autofocus } = this.props;
const { input } = this;
if (autofocus) input.focus();
return false;
}
onInputChange = (evt) => {
evt.preventDefault();
@@ -70,6 +81,7 @@ class InputFieldWithIcon extends Component {
name={name}
onChange={onInputChange}
placeholder={placeholder}
ref={(r) => { this.input = r; }}
style={[inputStyles(value), inputErrorStyles(error), style]}
type={type}
/>