escape key to cancel imageview popup

This commit is contained in:
Matthew Hodgson 2015-08-14 15:50:37 +01:00
parent 24630f598f
commit 1176168960

View File

@ -24,6 +24,23 @@ module.exports = React.createClass({
displayName: 'ImageView', displayName: 'ImageView',
mixins: [ImageViewController], mixins: [ImageViewController],
// XXX: keyboard shortcuts for managing dialogs should be done by the modal dialog base class omehow, surely...
componentDidMount: function() {
document.addEventListener("keydown", this.onKeyDown);
},
componentWillUnmount: function() {
document.removeEventListener("keydown", this.onKeyDown);
},
onKeyDown: function(ev) {
if (ev.keyCode == 27) { // escape
ev.stopPropagation();
ev.preventDefault();
this.props.onFinished();
}
},
render: function() { render: function() {
// XXX: can't we just do max-width: 80%, max-height: 80% on the CSS? // XXX: can't we just do max-width: 80%, max-height: 80% on the CSS?