Merge pull request #199 from Clearic/userinfo-close-by-esc

UserInfo close by Esc fix, issue #187
This commit is contained in:
Igor Adamenko
2018-09-14 14:26:54 +03:00
committed by GitHub
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);