Skip to content
This repository has been archived by the owner on May 25, 2018. It is now read-only.

Emit "collapse" event on Navbar click or blur (issue #487) #494

Open
wants to merge 2 commits into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/example/navbarDocs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@
<p></p>
</div>
</doc-table>
<doc-table type="Events">
<div>
<p>collapse</p>
<p></p>
<p>Return if the menu was collapsed, e.g. on click of menu pick or click outside of menu.</p>
</div>
</doc-table>
</doc-section>
</template>

Expand Down
5 changes: 3 additions & 2 deletions src/Navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export default {
$dropdown.each(content => {
if (!content.contains(e.target))
content.classList.remove('open')
this.$emit('collapse')
})
})
}
Expand All @@ -82,9 +83,9 @@ export default {
}

$(this.$el).on('click touchstart','li:not(.dropdown)>a', e => {
setTimeout(() => { this.collapsed = true }, 200)
setTimeout(() => { this.collapsed = true; this.$emit('collapse'); }, 200)
}).onBlur(e => {
if (!this.$el.contains(e.target)) { this.collapsed = true }
if (!this.$el.contains(e.target)) { this.collapsed = true; this.$emit('collapse') }
})
let height = this.$el.offsetHeight
if (this.placement === 'top') {
Expand Down