2
0
mirror of https://github.com/frappe/books.git synced 2025-01-24 15:48:25 +00:00

Closing dropdown on document click (#91)

* Closing dropdown on document click

* Formatting
This commit is contained in:
sahil28297 2018-09-20 18:13:13 +05:30 committed by Faris Ansari
parent e5a4464167
commit 85bbd3fa0c
3 changed files with 19 additions and 5 deletions

View File

@ -1,5 +1,5 @@
<template> <template>
<div class="dropdown show"> <div class="dropdown show" ref="dropdownMenu">
<button <button
:id="_uid" :id="_uid"
class="btn btn-sm btn-light dropdown-toggle" class="btn btn-sm btn-light dropdown-toggle"
@ -29,7 +29,22 @@ export default {
return { return {
isShown: false isShown: false
} }
} },
methods:{
documentClick(e) {
let el = this.$refs.dropdownMenu;
let target = e.target;
if ((el !== target) && (!el.contains(target))) {
this.isShown = false;
}
}
},
created () {
document.addEventListener('click', this.documentClick);
},
destroyed () {
document.removeEventListener('click', this.documentClick);
}
}; };
</script> </script>
<style lang="scss"> <style lang="scss">
@ -44,4 +59,3 @@ $dropdown-link-active-bg: $gray-300;
} }
</style> </style>