Permalink
Browse files

fix(collapse): Close collapse when clicked in navbar (#803)

Closes the collapse when link/dropdown-item clicked in nav/navbar mode
  • Loading branch information...
tmorehouse committed Aug 11, 2017
1 parent a9bfbde commit 3fdfbff8dd70573b9ee33acce2a47540a813fcaa
Showing with 10 additions and 7 deletions.
  1. +10 −7 lib/components/collapse.vue
@@ -14,7 +14,7 @@
<div v-show="show"
:id="id || null"
:class="classObject"
@click.native="clickHandler"
@click="clickHandler"
><slot></slot></div>
</transition>
</template>
@@ -115,12 +115,15 @@
this.$root.$emit('accordion::toggle', this.id, this.accordion);
}
},
clickHandler() {
if (!this.isNav || typeof document === 'undefined') {
clickHandler(evt) {
// If we are in a nav/navbar, close the collapse when non-disabled link clicked
const el = evt.target;
if (!this.isNav || !el || getComputedStyle(this.$el).display !== 'block') {
return;
}
// If we are in a nav/navbar, close the collapse when clicked
this.toggle();
if (el.classList.contains('nav-link') || el.classList.contains('dropdown-item')) {
this.show = false;
}
},
handleToggleEvt(target) {
if (target !== this.id) {
@@ -145,8 +148,8 @@
}
},
handleResize() {
// Handler for orientation/resize to set collapsed state
this.show = (getComputedStyle(this.$el).display === 'block');
// Handler for orientation/resize to set collapsed state in nav/navbar
this.show = (getComputedStyle(this.$el).display === 'block');
},
},
created() {

0 comments on commit 3fdfbff

Please sign in to comment.