-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCellFormula.jsx
50 lines (45 loc) · 1.03 KB
/
CellFormula.jsx
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
44
45
46
47
48
49
50
CellFormula = React.createClass({
getInitialState () {
return {
cellFormula: this.props.formula
};
},
handleCellInput () {
const text = this.formulaInput.value;
this.setState({cellFormula: text});
},
handleInputKeyUp (event) {
switch (event.which) {
case 13:
this.submitFormula();
break;
case 27:
this.props.clearSelection();
break;
default:
break;
}
},
submitFormula () {
const text = this.formulaInput.value.trim();
this.props.updateFormula(text);
},
componentDidMount () {
this.formulaInput.select();
},
render() {
return (
<span className="cell selected" onClick={(e) => e.stopPropagation()}>
<input
type="text"
className="textInput"
ref={(c) => this.formulaInput = c}
value={this.state.cellFormula}
onChange={this.handleCellInput}
onBlur={this.submitFormula}
onKeyUp={this.handleInputKeyUp}
/>
</span>
);
}
});