-
Notifications
You must be signed in to change notification settings - Fork 963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SER-1199] - Close the guides modal with ESC key press #5204
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Gia,
Great job, I can only suggest this:
When adding an event listener in vue.js, we usually add it mounted and remove this listener before destroying. This way we can prevent possible memory leaks.
You may get better results if you try the following way
mounted: function() {
document.addEventListener('keydown', this.handleEscapeKey);
},
destroyed: function() { // or beforeDestroy
document.removeEventListener('keydown', this.handleEscapeKey);
},
methods: {
handleEscapeKey: function(event) {
if (event.keyCode === 27 || event.key === 'Escape') {
this.onClose()
}
}
}
If you're curious, life cycles in vue.js: https://v2.vuejs.org/v2/guide/instance
modified as per Pinar's suggestion: adding event listeners to mount and beforeDestroy
Thank you for the suggestions, Pinar! I modified it as mentioned. Now, it looks more aligned with the existing code. :) |
No description provided.