-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearchInput.js
41 lines (38 loc) · 1.06 KB
/
SearchInput.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import React from 'react';
import ReactDOM from 'react-dom';
export class SearchInput extends React.Component {
constructor() {
super();
this.onSubmit = this.onSubmit.bind(this);
}
componentDidMount(){
ReactDOM.findDOMNode(this.refs.username).focus();
}
onSubmit(e) {
e.preventDefault();
let username = ReactDOM.findDOMNode(this.refs.username).value;
this.props.onSubmit(username);
ReactDOM.findDOMNode(this.refs.username).value = '';
}
render() {
var divStyle = {
paddingLeft: '15px',
paddingRight: '15px'
};
return (
<form onSubmit={this.onSubmit} style={divStyle}>
<div className="mdl-textfield mdl-js-textfield">
<input className="mdl-textfield__input"
type="text"
ref="username"
placeholder="Enter a string to search for a user ..."/>
<label className="mdl-textfield__label">Type Username + Enter</label>
</div>
</form>
)
}
}
SearchInput.defaultProps = {
onSubmit: (s) => console.log(s)
}
export default SearchInput;