11
22import Vue from 'vue'
3+ import antRefDirective from '../_util/antRefDirective'
34import PropTypes from '../_util/vue-types'
45import contains from '../_util/Dom/contains'
56import { hasProp , getComponentFromProp , getEvents , filterEmpty } from '../_util/props-util'
@@ -10,6 +11,8 @@ import Popup from './Popup'
1011import { getAlignFromPlacement , getPopupClassNameFromAlign , noop } from './utils'
1112import BaseMixin from '../_util/BaseMixin'
1213import { cloneElement } from '../_util/vnode'
14+ import ContainerRender from '../_util/ContainerRender'
15+ Vue . use ( antRefDirective )
1316
1417function returnEmptyString ( ) {
1518 return ''
@@ -87,6 +90,7 @@ export default {
8790
8891 mounted ( ) {
8992 this . $nextTick ( ( ) => {
93+ this . renderComponent ( null )
9094 this . updatedCal ( )
9195 } )
9296 } ,
@@ -98,7 +102,9 @@ export default {
98102 } ,
99103 sPopupVisible ( val ) {
100104 this . $nextTick ( ( ) => {
101- this . afterPopupVisibleChange ( val )
105+ this . renderComponent ( null , ( ) => {
106+ this . afterPopupVisibleChange ( val )
107+ } )
102108 } )
103109 } ,
104110 } ,
@@ -112,11 +118,6 @@ export default {
112118 beforeDestroy ( ) {
113119 this . clearDelayTimer ( )
114120 this . clearOutsideHandler ( )
115- if ( this . _component ) {
116- this . _component . $destroy ( )
117- this . _component = null
118- this . popupContainer . remove ( )
119- }
120121 } ,
121122 methods : {
122123 updatedCal ( ) {
@@ -172,9 +173,8 @@ export default {
172173 onPopupMouseleave ( e ) {
173174 if ( e . relatedTarget && ! e . relatedTarget . setTimeout &&
174175 this . _component &&
175- this . _component . $refs . popup &&
176- this . _component . $refs . popup . getPopupDomNode &&
177- contains ( this . _component . $refs . popup . getPopupDomNode ( ) , e . relatedTarget ) ) {
176+ this . _component . getPopupDomNode &&
177+ contains ( this . _component . getPopupDomNode ( ) , e . relatedTarget ) ) {
178178 return
179179 }
180180 this . delaySetPopupVisible ( false , this . $props . mouseLeaveDelay )
@@ -261,8 +261,8 @@ export default {
261261 }
262262 } ,
263263 getPopupDomNode ( ) {
264- if ( this . _component && this . _component . $refs . popup && this . _component . $refs . popup . getPopupDomNode ) {
265- return this . _component . $refs . popup . getPopupDomNode ( )
264+ if ( this . _component && this . _component . getPopupDomNode ) {
265+ return this . _component . getPopupDomNode ( )
266266 }
267267 return null
268268 } ,
@@ -293,7 +293,10 @@ export default {
293293 }
294294 return popupAlign
295295 } ,
296- renderComponent ( ) {
296+ savePopup ( node ) {
297+ this . _component = node
298+ } ,
299+ getComponent ( ) {
297300 const self = this
298301 const mouseProps = { }
299302 if ( this . isMouseEnterToShow ( ) ) {
@@ -308,59 +311,42 @@ export default {
308311 mask, zIndex, popupTransitionName, getPopupAlign,
309312 maskAnimation, maskTransitionName, getContainer } = self
310313 const popupProps = {
311- prefixCls,
312- destroyPopupOnHide,
313- visible : sPopupVisible ,
314- action,
315- align : getPopupAlign ( ) ,
316- animation : popupAnimation ,
317- getClassNameFromAlign : handleGetPopupClassFromAlign ,
318- getRootDomNode,
319- mask,
320- zIndex,
321- transitionName : popupTransitionName ,
322- maskAnimation,
323- maskTransitionName,
324- getContainer,
325- popupClassName,
326- popupStyle,
327- popupEvents : {
314+ props : {
315+ prefixCls,
316+ destroyPopupOnHide,
317+ visible : sPopupVisible ,
318+ action,
319+ align : getPopupAlign ( ) ,
320+ animation : popupAnimation ,
321+ getClassNameFromAlign : handleGetPopupClassFromAlign ,
322+ getRootDomNode,
323+ mask,
324+ zIndex,
325+ transitionName : popupTransitionName ,
326+ maskAnimation,
327+ maskTransitionName,
328+ getContainer,
329+ popupClassName,
330+ popupStyle,
331+ } ,
332+ on : {
328333 align : self . $listeners . popupAlign || noop ,
329334 ...mouseProps ,
330335 } ,
331- }
332- if ( ! this . _component ) {
333- const div = document . createElement ( 'div' )
334- this . getContainer ( ) . appendChild ( div )
335- this . _component = new Vue ( {
336- data ( ) {
337- return {
338- popupProps : { ...popupProps } ,
339- }
336+ directives : [
337+ {
338+ name : 'ant-ref' ,
339+ value : this . savePopup ,
340340 } ,
341- parent : self ,
342- el : div ,
343- render ( ) {
344- const { popupEvents, ...otherProps } = this . popupProps
345- const p = {
346- props : otherProps ,
347- on : popupEvents ,
348- ref : 'popup' ,
349- // style: popupStyle,
350- }
351- return (
352- < Popup
353- { ...p }
354- >
355- { getComponentFromProp ( self , 'popup' ) }
356- </ Popup >
357- )
358- } ,
359- } )
360- } else {
361- this . _component . popupProps = popupProps
341+ ] ,
362342 }
363- return this . _component
343+ return (
344+ < Popup
345+ { ...popupProps }
346+ >
347+ { getComponentFromProp ( self , 'popup' ) }
348+ </ Popup >
349+ )
364350 } ,
365351
366352 getContainer ( ) {
@@ -479,8 +465,8 @@ export default {
479465 return action . indexOf ( 'focus' ) !== - 1 || hideAction . indexOf ( 'blur' ) !== - 1
480466 } ,
481467 forcePopupAlign ( ) {
482- if ( this . $data . sPopupVisible && this . _component && this . _component . $refs . popup && this . _component . $refs . popup . $refs . alignInstance ) {
483- this . _component . $refs . popup . $refs . alignInstance . forceAlign ( )
468+ if ( this . $data . sPopupVisible && this . _component && this . _component . alignInstance ) {
469+ this . _component . alignInstance . forceAlign ( )
484470 }
485471 } ,
486472 fireEvents ( type , e ) {
@@ -541,11 +527,22 @@ export default {
541527 newChildProps . on . blur = this . createTwoChains ( 'blur' )
542528 }
543529 const { sPopupVisible, forceRender } = this
544- if ( sPopupVisible || forceRender || this . _component ) {
545- this . renderComponent ( h )
546- }
547530 const trigger = cloneElement ( child , newChildProps )
548- return trigger
531+
532+ return (
533+ < ContainerRender
534+ parent = { this }
535+ visible = { sPopupVisible }
536+ autoMount = { false }
537+ forceRender = { forceRender }
538+ getComponent = { this . getComponent }
539+ getContainer = { this . getContainer }
540+ children = { ( { renderComponent } ) => {
541+ this . renderComponent = renderComponent
542+ return trigger
543+ } }
544+ />
545+ )
549546 } ,
550547}
551548
0 commit comments