fix clone events

pull/9/head
tangjinzhou 2018-02-05 11:18:50 +08:00
parent 2df0dec687
commit 93c3a70056
4 changed files with 25 additions and 35 deletions

View File

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

View File

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

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