@@ -32,6 +32,8 @@ function defaultPropFactory (prop: string) {
32
32
}
33
33
}
34
34
35
+ const PROVIDE_KEY = '__floating-vue__popper'
36
+
35
37
export default ( ) => ( {
36
38
name : 'VPopper' ,
37
39
@@ -240,6 +242,18 @@ export default () => ({
240
242
} ,
241
243
} ,
242
244
245
+ provide ( ) {
246
+ return {
247
+ [ PROVIDE_KEY ] : {
248
+ parentPopper : this ,
249
+ } ,
250
+ }
251
+ } ,
252
+
253
+ inject : {
254
+ [ PROVIDE_KEY ] : { default : null } ,
255
+ } ,
256
+
243
257
data ( ) {
244
258
return {
245
259
isShown : false ,
@@ -263,6 +277,7 @@ export default () => ({
263
277
} ,
264
278
transformOrigin : null ,
265
279
} ,
280
+ shownChildren : new Set ( ) ,
266
281
}
267
282
} ,
268
283
@@ -293,6 +308,10 @@ export default () => ({
293
308
result : this . positioningDisabled ? null : this . result ,
294
309
}
295
310
} ,
311
+
312
+ parentPopper ( ) {
313
+ return this [ PROVIDE_KEY ] ?. parentPopper
314
+ } ,
296
315
} ,
297
316
298
317
watch : {
@@ -369,6 +388,7 @@ export default () => ({
369
388
370
389
methods : {
371
390
show ( { event = null , skipDelay = false , force = false } = { } ) {
391
+ this . $_pendingHide = false
372
392
if ( force || ! this . disabled ) {
373
393
this . $_scheduleShow ( event , skipDelay )
374
394
this . $emit ( 'show' )
@@ -384,6 +404,11 @@ export default () => ({
384
404
385
405
hide ( { event = null , skipDelay = false } = { } ) {
386
406
if ( this . $_hideInProgress ) return
407
+ if ( this . shownChildren . size > 0 ) {
408
+ this . $_pendingHide = true
409
+ return
410
+ }
411
+ this . $_pendingHide = false
387
412
this . $_scheduleHide ( event , skipDelay )
388
413
389
414
this . $emit ( 'hide' )
@@ -427,6 +452,8 @@ export default () => ({
427
452
this . isMounted = false
428
453
this . isShown = false
429
454
455
+ this . $_updateParentShownChildren ( false )
456
+
430
457
this . $_swapTargetAttrs ( 'data-original-title' , 'title' )
431
458
432
459
this . $emit ( 'dispose' )
@@ -574,10 +601,11 @@ export default () => ({
574
601
} ,
575
602
576
603
$_scheduleShow ( event = null , skipDelay = false ) {
604
+ this . $_updateParentShownChildren ( true )
577
605
this . $_hideInProgress = false
578
606
clearTimeout ( this . $_scheduleTimer )
579
607
580
- if ( hidingPopper && this . instantMove && hidingPopper . instantMove ) {
608
+ if ( hidingPopper && this . instantMove && hidingPopper . instantMove && hidingPopper !== this . parentPopper ) {
581
609
hidingPopper . $_applyHide ( true )
582
610
this . $_applyShow ( true )
583
611
return
@@ -591,6 +619,11 @@ export default () => ({
591
619
} ,
592
620
593
621
$_scheduleHide ( event = null , skipDelay = false ) {
622
+ if ( this . shownChildren . size > 0 ) {
623
+ this . $_pendingHide = true
624
+ return
625
+ }
626
+ this . $_updateParentShownChildren ( false )
594
627
this . $_hideInProgress = true
595
628
clearTimeout ( this . $_scheduleTimer )
596
629
@@ -683,6 +716,11 @@ export default () => ({
683
716
} ,
684
717
685
718
async $_applyHide ( skipTransition = false ) {
719
+ if ( this . shownChildren . size > 0 ) {
720
+ this . $_pendingHide = true
721
+ this . $_hideInProgress = false
722
+ return
723
+ }
686
724
clearTimeout ( this . $_scheduleTimer )
687
725
688
726
// Already hidden
@@ -847,6 +885,12 @@ export default () => ({
847
885
this . $_preventShow = false
848
886
} , 300 )
849
887
}
888
+
889
+ let parent = this . parentPopper
890
+ while ( parent ) {
891
+ parent . $_handleGlobalClose ( event , touch )
892
+ parent = parent . parentPopper
893
+ }
850
894
} ,
851
895
852
896
$_detachPopperNode ( ) {
@@ -875,6 +919,22 @@ export default () => ({
875
919
}
876
920
}
877
921
} ,
922
+
923
+ $_updateParentShownChildren ( value ) {
924
+ let parent = this . parentPopper
925
+ while ( parent ) {
926
+ if ( value ) {
927
+ parent . shownChildren . add ( this . randomId )
928
+ } else {
929
+ parent . shownChildren . delete ( this . randomId )
930
+
931
+ if ( parent . $_pendingHide ) {
932
+ parent . hide ( )
933
+ }
934
+ }
935
+ parent = parent . parentPopper
936
+ }
937
+ } ,
878
938
} ,
879
939
880
940
render ( ) {
0 commit comments