Skip to content

Commit ad1f6ce

Browse files
committed
fix(transitions): correctly merge event listeners
fixes #9691
1 parent 2a3d380 commit ad1f6ce

File tree

1 file changed

+26
-46
lines changed

1 file changed

+26
-46
lines changed

packages/vuetify/src/util/helpers.ts

+26-46
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import Vue from 'vue'
1+
import Vue, { VNodeData } from 'vue'
22
import { VNode, VNodeDirective, FunctionalComponentOptions } from 'vue/types'
33
import { VuetifyIcon } from 'vuetify/types/services/icons'
4+
import mergeData from './mergeData'
45

56
export function createSimpleFunctional (
67
c: string,
@@ -20,15 +21,6 @@ export function createSimpleFunctional (
2021
})
2122
}
2223

23-
function mergeTransitions (
24-
transitions: undefined | Function | Function[],
25-
array: Function[]
26-
) {
27-
if (Array.isArray(transitions)) return transitions.concat(array)
28-
if (transitions) array.push(transitions)
29-
return array
30-
}
31-
3224
export function createSimpleTransition (
3325
name: string,
3426
origin = 'top center 0',
@@ -64,38 +56,27 @@ export function createSimpleTransition (
6456

6557
render (h, context): VNode {
6658
const tag = `transition${context.props.group ? '-group' : ''}`
67-
context.data = context.data || {}
68-
context.data.props = {
69-
name,
70-
mode: context.props.mode,
71-
}
72-
context.data.on = context.data.on || {}
73-
if (!Object.isExtensible(context.data.on)) {
74-
context.data.on = { ...context.data.on }
59+
const data: VNodeData = {
60+
props: {
61+
name,
62+
mode: context.props.mode,
63+
},
64+
on: {
65+
beforeEnter (el: HTMLElement) {
66+
el.style.transformOrigin = context.props.origin
67+
el.style.webkitTransformOrigin = context.props.origin
68+
},
69+
},
7570
}
7671

77-
const ourBeforeEnter: Function[] = []
78-
const ourLeave: Function[] = []
79-
const absolute = (el: HTMLElement) => (el.style.position = 'absolute')
80-
81-
ourBeforeEnter.push((el: HTMLElement) => {
82-
el.style.transformOrigin = context.props.origin
83-
el.style.webkitTransformOrigin = context.props.origin
84-
})
85-
86-
if (context.props.leaveAbsolute) ourLeave.push(absolute)
72+
if (context.props.leaveAbsolute) {
73+
data.on!.leave = [...data.on!.leave, (el: HTMLElement) => (el.style.position = 'absolute')]
74+
}
8775
if (context.props.hideOnLeave) {
88-
ourLeave.push((el: HTMLElement) => (el.style.display = 'none'))
76+
data.on!.leave = [...data.on!.leave, (el: HTMLElement) => (el.style.display = 'none')]
8977
}
9078

91-
const { beforeEnter, leave } = context.data.on
92-
93-
// Type says Function | Function[] but
94-
// will only work if provided a function
95-
context.data.on.beforeEnter = () => mergeTransitions(beforeEnter, ourBeforeEnter)
96-
context.data.on.leave = mergeTransitions(leave, ourLeave)
97-
98-
return h(tag, context.data, context.children)
79+
return h(tag, mergeData(context.data, data), context.children)
9980
},
10081
}
10182
}
@@ -118,15 +99,14 @@ export function createJavaScriptTransition (
11899
},
119100

120101
render (h, context): VNode {
121-
const data = {
122-
props: {
123-
...context.props,
124-
name,
125-
},
126-
on: functions,
127-
}
128-
129-
return h('transition', data, context.children)
102+
return h(
103+
'transition',
104+
mergeData(context.data, {
105+
props: { name },
106+
on: functions,
107+
}),
108+
context.children
109+
)
130110
},
131111
}
132112
}

0 commit comments

Comments
 (0)