Add example for keypress in editors
https://github.com/ag-grid/ag-grid-react/issues/60
This commit is contained in:
@@ -18,9 +18,21 @@ export default class MoodEditor extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
this.refs.container.addEventListener('keydown', this.checkAndToggleMoodIfLeftRight);
|
||||||
this.focus();
|
this.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
this.refs.container.removeEventListener('keydown', this.checkAndToggleMoodIfLeftRight);
|
||||||
|
}
|
||||||
|
|
||||||
|
checkAndToggleMoodIfLeftRight = (event) => {
|
||||||
|
if ([37, 39].indexOf(event.keyCode) > -1) { // left and right
|
||||||
|
this.toggleMood();
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
componentDidUpdate() {
|
componentDidUpdate() {
|
||||||
this.focus();
|
this.focus();
|
||||||
}
|
}
|
||||||
@@ -75,12 +87,11 @@ export default class MoodEditor extends Component {
|
|||||||
background: "#e6e6e6",
|
background: "#e6e6e6",
|
||||||
padding: 15,
|
padding: 15,
|
||||||
textAlign: "center",
|
textAlign: "center",
|
||||||
display: "inline-block",
|
display: "inline-block"
|
||||||
// outline: "none"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let unselected = {
|
let unselected = {
|
||||||
paddingLleft: 10,
|
paddingLeft: 10,
|
||||||
paddingRight: 10,
|
paddingRight: 10,
|
||||||
border: "1px solid transparent",
|
border: "1px solid transparent",
|
||||||
padding: 4
|
padding: 4
|
||||||
@@ -93,12 +104,14 @@ export default class MoodEditor extends Component {
|
|||||||
padding: 4
|
padding: 4
|
||||||
};
|
};
|
||||||
|
|
||||||
let happyStyle = this.state.value === 'Happy' ? selected : unselected;
|
let happyStyle = this.state.happy ? selected : unselected;
|
||||||
let sadStyle = this.state.value !== 'Happy' ? selected : unselected;
|
let sadStyle = !this.state.happy ? selected : unselected;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref="container"
|
<div ref="container"
|
||||||
style={mood}>
|
style={mood}
|
||||||
|
tabIndex={1} // important - without this the keypresses wont be caught
|
||||||
|
>
|
||||||
<img src="images/smiley.png" onClick={this.onHappyClick} style={happyStyle}/>
|
<img src="images/smiley.png" onClick={this.onHappyClick} style={happyStyle}/>
|
||||||
<img src="images/smiley-sad.png" onClick={this.onSadClick} style={sadStyle}/>
|
<img src="images/smiley-sad.png" onClick={this.onSadClick} style={sadStyle}/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user