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

Close the apps menu when users click anywhere else in the page #69

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions components/Elements/Dropdown.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<template>
<div class="dropdown">
<div class="dropdown-link">
<button class="dropdown-button" v-if="show" key="on" @click="show = false">
<i class="ri-close-fill"></i>
</button>
<button class="dropdown-button" v-else key="off" @click="show = true">
<i class="ri-list-settings-fill"></i>
<button class="dropdown-button" @click="show = !show">
<i class="ri-close-fill" v-if="show"></i>
<i class="ri-list-settings-fill" v-else></i>
</button>
<h4 @click="show = !show" class="flex-grow ltr:ml-4 rtl:mr-4">{{ getTitle }}</h4>
</div>
Expand Down Expand Up @@ -41,10 +39,21 @@
required: true
}
},
mounted() {
this.$nuxt.$on('routeChanged', () => {
this.show = false
})
document.addEventListener('click', this.closeMenu)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thread-koder I think using document here is breaking the Vue lifecycle somehow. Can you please her with some resources on how to attach the event listener?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alsahawneh Hello I hope you are doing well, this way of handling events definitely breaks the Vue lifecycle, I will attach some resources for event handling in Vue:
Event Handling, explains "Listening to Events", "Event Modifiers" etc...
Component Events, explains "Emitting and Listening to Events", "Declaring Emitted Events", "Events Validation" etc...
Please don't hesitate to tell me if you need any help.

},
methods: {
setActive(value, title) {
this.show = false
this.$emit('setActive', value, title)
},
closeMenu(e) {
if (!this.$el.contains(e.target)) {
this.show = false
}
}
},
computed: {
Expand Down Expand Up @@ -120,4 +129,4 @@
transform: translateY(30px);
}

</style>
</style>