3
3
import { isIE9 } from 'web/util/index'
4
4
import { enter , leave } from '../modules/transition'
5
5
6
- // recursively search for possible transition defined inside the component root
7
- function locateNode ( vnode : VNode ) : VNodeWithData {
8
- return vnode . child && ( ! vnode . data || ! vnode . data . transition )
9
- ? locateNode ( vnode . child . _vnode )
10
- : vnode
6
+ // The v-show directive may appear on a component's parent vnode or its
7
+ // inner vnode, and the transition wrapper may be defined outside or inside
8
+ // the component. To cater for all possible cases, recursively search for
9
+ // possible transition defined on component parent placeholder or inside
10
+ // child component.
11
+ function detectTransitionNode ( vnode : VNode ) : VNodeWithData {
12
+ let parent = vnode
13
+ while ( ( parent = parent . parent ) ) {
14
+ if ( hasTransition ( parent ) ) {
15
+ return parent
16
+ }
17
+ }
18
+ if ( hasTransition ( vnode ) ) {
19
+ return vnode
20
+ }
21
+ while ( vnode . child && ( vnode = vnode . child . _vnode ) ) {
22
+ if ( hasTransition ( vnode ) ) {
23
+ return vnode
24
+ }
25
+ }
26
+ return vnode
27
+ }
28
+
29
+ function hasTransition ( vnode ) {
30
+ return vnode . data && vnode . data . transition
11
31
}
12
32
13
33
export default {
14
34
bind ( el : any , { value } : VNodeDirective, vnode : VNodeWithData ) {
15
- vnode = locateNode ( vnode )
35
+ vnode = detectTransitionNode ( vnode )
16
36
const transition = vnode . data && vnode . data . transition
17
37
if ( value && transition && transition . appear && ! isIE9 ) {
18
38
enter ( vnode )
@@ -24,7 +44,7 @@ export default {
24
44
update ( el : any , { value, oldValue } : VNodeDirective , vnode : VNodeWithData ) {
25
45
/* istanbul ignore if */
26
46
if ( value === oldValue ) return
27
- vnode = locateNode ( vnode )
47
+ vnode = detectTransitionNode ( vnode )
28
48
const transition = vnode . data && vnode . data . transition
29
49
if ( transition && ! isIE9 ) {
30
50
if ( value ) {
0 commit comments