2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 07:40:55 +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

@ -51,4 +51,4 @@ class Dropdown {
Dropdown.instances = 0;
module.exports = Dropdown;
module.exports = Dropdown;

View File

@ -1,5 +1,5 @@
<template>
<div class="dropdown show">
<div class="dropdown show" ref="dropdownMenu">
<button
:id="_uid"
class="btn btn-sm btn-light dropdown-toggle"
@ -29,7 +29,22 @@ export default {
return {
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>
<style lang="scss">
@ -44,4 +59,3 @@ $dropdown-link-active-bg: $gray-300;
}
</style>

View File

@ -35,4 +35,4 @@ export default function installFrappePlugin(Vue) {
}
}
});
}
}