Skip to content
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

Merged
merged 9 commits into from
May 25, 2024
Merged

Conversation

LaNinja06
Copy link
Contributor

No description provided.

Copy link
Member

@pnrgenc pnrgenc left a 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
@LaNinja06 LaNinja06 requested a review from pnrgenc May 14, 2024 20:38
@LaNinja06
Copy link
Contributor Author

Thank you for the suggestions, Pinar! I modified it as mentioned. Now, it looks more aligned with the existing code. :)

@Cookiezaurs Cookiezaurs merged commit fd8c5f1 into next May 25, 2024
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants