fix clone events

This commit is contained in:
tangjinzhou 2018-02-05 11:18:50 +08:00
parent 8f7fc1f3ef
commit 42776ba79c
4 changed files with 25 additions and 35 deletions

View File

@ -1,19 +1,26 @@
import cloneDeep from 'lodash.clonedeep'
export function cloneVNode (vnode, deep) {
const componentOptions = vnode.componentOptions
// if (componentOptions && componentOptions.listeners) {
// componentOptions.listeners = cloneDeep(componentOptions.listeners)
// }
const data = vnode.data
let listeners = {}
if (componentOptions && componentOptions.listeners) {
listeners = cloneDeep(componentOptions.listeners)
}
let on = {}
if (data && data.on) {
on = cloneDeep(data.on)
}
// const data = vnode.data ? cloneDeep(vnode.data) : vnode.data
const cloned = new vnode.constructor(
vnode.tag,
vnode.data,
data ? { ...data, on } : data,
vnode.children,
vnode.text,
vnode.elm,
vnode.context,
componentOptions,
componentOptions ? { ...componentOptions, listeners } : componentOptions,
vnode.asyncFactory
)
cloned.ns = vnode.ns

View File

@ -4,7 +4,7 @@ import Trigger from '../../trigger'
import placements from './placements'
import { hasProp } from '../../_util/props-util'
import BaseMixin from '../../_util/BaseMixin'
import { cloneElement, getEvents } from '../../_util/vnode'
import { cloneElement, getEvents, cloneVNode } from '../../_util/vnode'
export default {
mixins: [BaseMixin],
@ -68,21 +68,14 @@ export default {
},
getMenuElement () {
const child = this.$slots.overlay[0]
const events = getEvents(child)
if (!events._ANT_DROPDOWN_EVENT_HACK) {
this.childOriginEvents = events
}
const { prefixCls } = this.$props
const extraOverlayProps = {
const { onClick, prefixCls, $slots } = this
this.childOriginEvents = getEvents($slots.overlay[0])
return cloneElement(cloneVNode($slots.overlay[0]), {
props: {
prefixCls: `${prefixCls}-menu`,
}
const overlay = this.$slots.overlay[0]
return cloneElement(overlay, {
props: extraOverlayProps,
},
on: {
click: this.onClick,
_ANT_DROPDOWN_EVENT_HACK: () => {},
click: onClick,
},
})
},

View File

@ -1,6 +0,0 @@
html {
overflow-y: auto !important;
}
body {
position: relative !important;
}

View File

@ -9,7 +9,7 @@ import warning from '../_util/warning'
import Popup from './Popup'
import { getAlignFromPlacement, getPopupClassNameFromAlign, noop } from './utils'
import BaseMixin from '../_util/BaseMixin'
import { cloneElement, filterEmpty, getEvents } from '../_util/vnode'
import { cloneElement, filterEmpty, getEvents, cloneVNode } from '../_util/vnode'
function returnEmptyString () {
return ''
@ -497,15 +497,11 @@ export default {
if (children.length > 1) {
warning(false, 'Trigger $slots.default.length > 1, just support only one default', true)
}
const child = children[0]
const events = getEvents(child)
// vue使_ANT_TRIGGER_EVENT_HACK
if (!events._ANT_TRIGGER_EVENT_HACK) {
this.childOriginEvents = events
}
const child = cloneVNode(children[0])
this.childOriginEvents = getEvents(children[0])
const newChildProps = {
props: {},
on: { _ANT_TRIGGER_EVENT_HACK: () => {} },
on: {},
key: 'trigger',
}