UserInfo close by Esc fix

This commit is contained in:
Alexandr
2018-09-06 09:06:42 +05:00
parent 061ceb4f81
commit 2a3b380686
2 changed files with 14 additions and 3 deletions
@@ -24,6 +24,20 @@ class UserInfo extends Component {
.getUserComments({ user: id, limit: 10 })
.then(({ comments = [] }) => this.setState({ comments }))
.finally(() => this.setState({ isLoading: false }));
document.addEventListener('keydown', this.globalOnKeyDown);
}
componentWillUnmount() {
document.removeEventListener('keydown', this.globalOnKeyDown);
}
globalOnKeyDown(e) {
// ESCAPE key pressed
if (e.keyCode == 27) {
const data = JSON.stringify({ isUserInfoShown: false });
window.parent.postMessage(data, '*');
}
}
render(props, { comments, isLoading }) {
-3
View File
@@ -151,9 +151,6 @@ function init() {
horizontalscrolling="no"
/>`;
this.iframe = this.node.querySelector('iframe');
this.iframe.onload = () => {
this.iframe.contentDocument.addEventListener('keydown', this.onKeyDown);
};
this.node.appendChild(this.closeEl);
document.body.appendChild(this.style);
document.body.appendChild(this.back);