Skip to content

Commit addd10e

Browse files
authored
Merge pull request bootstrap-vue#142 from mosinve/master
Update modal.vue
2 parents db7c01f + 8c201b7 commit addd10e

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

components/modal.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ export default {
110110
},
111111
created() {
112112
const hub = this.$root;
113-
hub.$on('show::modal', id => id === this.id && this.show());
114-
hub.$on('hide::modal', id => id === this.id && this.hide());
113+
hub.$on('show::modal', id => id === this.id && this.show()).bind(this);
114+
hub.$on('hide::modal', id => id === this.id && this.hide()).bind(this);
115115
},
116116
mounted() {
117117
document.addEventListener('keydown', this.pressedButton);

components/nav-item-dropdown.vue

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<template>
22
<li :class="{'nav-item': true, show: show,
33
dropdown: !dropup, dropup: dropup}">
4-
<a @click.stop="toggle($event)"
4+
<a @click.stop.prevent="toggle($event)"
55
:class="['nav-link', dropdownToggle]"
6-
href="" v-on:click.prevent=""
7-
aria-haspopup="true"
6+
href="" aria-haspopup="true"
87
:aria-expanded="show"
98
:disabled="disabled">
109
<slot>{{ text }}</slot>
@@ -52,27 +51,35 @@
5251
class: ['class']
5352
},
5453
methods: {
55-
toggle(e) {
56-
// return if disabled
57-
if (this.disabled) {
54+
setShow(state) {
55+
if (this.show === state) {
5856
return;
59-
}
60-
// hide an alert
61-
this.show = !this.show;
62-
// Dispatch an event from the current vm that propagates all the way up to its $root
57+
} // Avoid duplicated emits
58+
this.show = state;
59+
6360
if (this.show) {
6461
this.$root.$emit('shown::dropdown');
65-
e.stopPropagation();
6662
} else {
6763
this.$root.$emit('hidden::dropdown');
6864
}
69-
}
65+
},
66+
toggle() {
67+
this.setShow(!this.show);
68+
},
69+
clickOut() {
70+
this.setShow(false);
71+
},
7072
},
7173
created() {
7274
const hub = this.$root;
7375
hub.$on('hide::dropdown', () => {
7476
this.show = false;
7577
});
78+
},
79+
mounted() {
80+
if (typeof document !== 'undefined') {
81+
document.documentElement.addEventListener('click', this.clickOut);
82+
}
7683
}
7784
};
7885
</script>

0 commit comments

Comments
 (0)