From eb6c8dfd4e55cdf9302bd3fffdf58e3bf4bacaf7 Mon Sep 17 00:00:00 2001 From: Vi Pro Date: Tue, 6 Feb 2018 00:38:21 +0800 Subject: [PATCH] fix(MdMenuItem): fix router (#1474) fix #1471 --- .../MdList/MdListItem/MdListItem.vue | 4 +++ src/components/MdMenu/MdMenuItem.vue | 35 +++++++++++++++---- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/components/MdList/MdListItem/MdListItem.vue b/src/components/MdList/MdListItem/MdListItem.vue index e9fd09f6d..d16bd0497 100644 --- a/src/components/MdList/MdListItem/MdListItem.vue +++ b/src/components/MdList/MdListItem/MdListItem.vue @@ -44,6 +44,10 @@ return MdListItemExpand } + if (props.disabled) { + return MdListItemButton + } + if (isRouterLink(parent, props)) { MdListItemRouter.props = MdRouterLinkProps(parent, { target: String diff --git a/src/components/MdMenu/MdMenuItem.vue b/src/components/MdMenu/MdMenuItem.vue index 2a3ce4b1e..1c8993ff4 100644 --- a/src/components/MdMenu/MdMenuItem.vue +++ b/src/components/MdMenu/MdMenuItem.vue @@ -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 { @@ -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) } })