-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathtab_search_box.jsx
More file actions
43 lines (39 loc) · 943 Bytes
/
tab_search_box.jsx
File metadata and controls
43 lines (39 loc) · 943 Bytes
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
41
42
43
var KEY_ENTER = 13;
var KEY_ESC = 27;
var KEY_UP = 38;
var KEY_DOWN = 40;
module.exports = React.createClass({
componentDidUpdate: function() {
this.refs.input.getDOMNode().focus();
},
render: function() {
return (
/* jshint ignore:start */
<input type='text' ref='input' autoFocus='true'
onKeyDown={this.onKeydown} onChange={this.onChange} />
/* jshint ignore:end */
);
},
onKeydown: function(evt) {
switch (evt.which) {
case KEY_ESC:
this.props.exit();
break;
case KEY_ENTER:
this.props.activateSelected();
break;
case KEY_UP:
this.props.modifySelected(-1);
evt.preventDefault();
break;
case KEY_DOWN:
this.props.modifySelected(1);
evt.preventDefault();
break;
}
},
onChange: function(evt) {
if (event.target.value !== this.props.filter)
this.props.changeFilter(event.target.value);
}
});