From d081d090895d13f6e286b1eb8921683561cd18c6 Mon Sep 17 00:00:00 2001 From: bnau Date: Mon, 27 Nov 2017 14:51:29 +0100 Subject: [PATCH] Popin - Close popin on Esc press --- src/application/popin/index.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/application/popin/index.js b/src/application/popin/index.js index 1f9c58b20..905a79844 100644 --- a/src/application/popin/index.js +++ b/src/application/popin/index.js @@ -144,8 +144,23 @@ const popin = { }); }, timeout); }, + componentDidMount() { + document.addEventListener('keydown', this.closeOnEscape); + }, componentWillUnmount() { window.clearTimeout(this._openTimeoutID); + document.removeEventListener('keydown', this.closeOnEscape); + }, + /** + * Close the popin on Esc press. + * @param e The trigger event + */ + closeOnEscape(e) { + if (this.state.opened && e.keyCode === 27) { + e.preventDefault(); + e.stopPropagation(); + this.toggleOpen(); + } }, /** * Render the component