Skip to content

Commit

Permalink
fix(MdMenuItem): fix router (#1474)
Browse files Browse the repository at this point in the history
fix #1471
  • Loading branch information
VdustR authored and marcosmoura committed Feb 5, 2018
1 parent 1286120 commit eb6c8df
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/components/MdList/MdListItem/MdListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
return MdListItemExpand
}
if (props.disabled) {
return MdListItemButton
}
if (isRouterLink(parent, props)) {
MdListItemRouter.props = MdRouterLinkProps(parent, {
target: String
Expand Down
35 changes: 29 additions & 6 deletions src/components/MdMenu/MdMenuItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,31 @@
}
}
},
methods: {
closeMenu () {
this.MdMenu.active = false
if (this.MdMenu.eventObserver) {
this.MdMenu.eventObserver.destroy()
}
},
triggerCloseMenu () {
if (!this.disabled) {
this.closeMenu()
}
}
},
created () {
if (this.MdMenu.closeOnSelect) {
let listenerNames = Object.keys(this.$listeners)
let hasInteraction = false
listenerNames.forEach(listener => {
if (MdInteractionEvents.includes(listener)) {
this.listeners[listener] = $event => {
if (!this.disabled) {
this.$listeners[listener]($event)
this.MdMenu.active = false
if (this.MdMenu.eventObserver) {
this.MdMenu.eventObserver.destroy()
}
this.closeMenu()
}
}
} else {
Expand All @@ -50,6 +60,19 @@
} else {
this.listeners = this.$listeners
}
},
mounted () {
if (this.$el.children && this.$el.children[0]) {
let listItem = this.$el.children[0]
if (listItem.tagName.toUpperCase() === 'A') {
this.$el.addEventListener('click', this.triggerCloseMenu)
}
}
},
beforeDestroy () {
this.$el.removeEventListener('click', this.triggerCloseMenu)
}
})
</script>

0 comments on commit eb6c8df

Please sign in to comment.