From d9232959dff4f9408e9a31bdba4ea565ba292962 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Fri, 2 Dec 2016 14:37:00 +0100 Subject: Fix #298 - Esc to close modal --- app/assets/javascripts/components/components/lightbox.jsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'app') diff --git a/app/assets/javascripts/components/components/lightbox.jsx b/app/assets/javascripts/components/components/lightbox.jsx index 36f078a3a..29822ccb3 100644 --- a/app/assets/javascripts/components/components/lightbox.jsx +++ b/app/assets/javascripts/components/components/lightbox.jsx @@ -40,6 +40,18 @@ const Lightbox = React.createClass({ mixins: [PureRenderMixin], + componentDidMount () { + this._listener = window.addEventListener('keyup', e => { + if (e.key === 'Escape') { + this.props.onCloseClicked(); + } + }); + }, + + componentWillUnmount () { + window.removeEventListener(this._listener); + }, + render () { const { intl, isVisible, onOverlayClicked, onCloseClicked, children } = this.props; -- cgit