*: add click away detection for dropdowns

This commit is contained in:
Simone Gotti 2019-05-17 17:00:46 +02:00
parent e25510e026
commit 3232d6db45
5 changed files with 35 additions and 4 deletions

12
package-lock.json generated
View File

@ -3421,7 +3421,8 @@
"version": "4.6.0", "version": "4.6.0",
"resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz",
"integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=", "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=",
"dev": true "dev": true,
"optional": true
}, },
"coa": { "coa": {
"version": "2.0.2", "version": "2.0.2",
@ -5742,7 +5743,8 @@
"ansi-regex": { "ansi-regex": {
"version": "2.1.1", "version": "2.1.1",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"aproba": { "aproba": {
"version": "1.2.0", "version": "1.2.0",
@ -6210,6 +6212,7 @@
"version": "3.0.1", "version": "3.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"ansi-regex": "^2.0.0" "ansi-regex": "^2.0.0"
} }
@ -12068,6 +12071,11 @@
"integrity": "sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==", "integrity": "sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==",
"dev": true "dev": true
}, },
"v-click-outside": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/v-click-outside/-/v-click-outside-2.1.3.tgz",
"integrity": "sha512-8d11/fN+nkSPeor87K8OtGc/lDbRwbUiFwdzxQEGidlXt6eko3gIgRM7ghgi4p/zohF3Ja9hAaydAajV3gnlPQ=="
},
"validate-npm-package-license": { "validate-npm-package-license": {
"version": "3.0.4", "version": "3.0.4",
"resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz",

View File

@ -15,6 +15,7 @@
"bulma": "^0.7.4", "bulma": "^0.7.4",
"moment": "^2.23.0", "moment": "^2.23.0",
"moment-duration-format": "^2.2.2", "moment-duration-format": "^2.2.2",
"v-click-outside": "^2.1.3",
"vue": "^2.6.10", "vue": "^2.6.10",
"vue-router": "^3.0.6", "vue-router": "^3.0.6",
"vue2-filters": "^0.4.1", "vue2-filters": "^0.4.1",

View File

@ -25,6 +25,7 @@
<div <div
v-if="user" v-if="user"
class="navbar-item has-dropdown" class="navbar-item has-dropdown"
v-click-outside="() => createDropdownActive = false"
v-bind:class="{ 'is-active': createDropdownActive }" v-bind:class="{ 'is-active': createDropdownActive }"
> >
<a class="navbar-link" @click="toggleCreateDropdown()"> <a class="navbar-link" @click="toggleCreateDropdown()">
@ -37,6 +38,7 @@
<div <div
v-if="user" v-if="user"
class="navbar-item has-dropdown" class="navbar-item has-dropdown"
v-click-outside="() => userDropdownActive = false"
v-bind:class="{ 'is-active': userDropdownActive }" v-bind:class="{ 'is-active': userDropdownActive }"
> >
<a class="navbar-link" @click="toggleUserDropdown()">{{user.username}}</a> <a class="navbar-link" @click="toggleUserDropdown()">{{user.username}}</a>
@ -86,10 +88,15 @@
<script> <script>
import vClickOutside from "v-click-outside";
import { mapGetters } from "vuex"; import { mapGetters } from "vuex";
export default { export default {
name: "App", name: "App",
directives: {
clickOutside: vClickOutside.directive
},
components: {}, components: {},
computed: { computed: {
...mapGetters(["error", "user"]) ...mapGetters(["error", "user"])

View File

@ -5,9 +5,13 @@
<button class="button" @click="clicked">{{ buttonValue }}</button> <button class="button" @click="clicked">{{ buttonValue }}</button>
</p> </p>
<div class="control"> <div class="control">
<div class="dropdown is-right" v-bind:class="{ 'is-active': dropdownActive }"> <div
class="dropdown is-right"
v-click-outside="() => dropdownActive = false"
v-bind:class="{ 'is-active': dropdownActive }"
>
<div class="dropdown-trigger"> <div class="dropdown-trigger">
<button class="button" @click="toggleDropdown()"> <button class="button" @click="toggleDropdown">
<span class="icon is-small"> <span class="icon is-small">
<i class="mdi mdi-chevron-down"></i> <i class="mdi mdi-chevron-down"></i>
</span> </span>
@ -26,8 +30,13 @@
</template> </template>
<script> <script>
import vClickOutside from "v-click-outside";
export default { export default {
components: {}, components: {},
directives: {
clickOutside: vClickOutside.directive
},
name: "createprojectbutton", name: "createprojectbutton",
props: {}, props: {},
data() { data() {

View File

@ -18,6 +18,7 @@
<div <div
v-if="run.can_restart_from_scratch || run.can_restart_from_failed_tasks" v-if="run.can_restart_from_scratch || run.can_restart_from_failed_tasks"
class="dropdown is-right" class="dropdown is-right"
v-click-outside="() => dropdownActive = false"
v-bind:class="{ 'is-active': dropdownActive }" v-bind:class="{ 'is-active': dropdownActive }"
> >
<div class="dropdown-trigger"> <div class="dropdown-trigger">
@ -106,10 +107,15 @@
</template> </template>
<script> <script>
import vClickOutside from "v-click-outside";
import { cancelRun, stopRun, restartRun } from "@/util/data.js"; import { cancelRun, stopRun, restartRun } from "@/util/data.js";
export default { export default {
name: "RunDetail", name: "RunDetail",
directives: {
clickOutside: vClickOutside.directive
},
props: { props: {
run: Object run: Object
}, },