@@ -46,6 +46,8 @@ function offset(el) {
46
46
return pos ;
47
47
}
48
48
49
+ let cacheOverflow = { } ;
50
+
49
51
export default {
50
52
mixins : [ BaseMixin ] ,
51
53
props : initDefaultProps ( IDialogPropTypes , {
@@ -57,6 +59,7 @@ export default {
57
59
destroyOnClose : false ,
58
60
prefixCls : 'rc-dialog' ,
59
61
getOpenCount : ( ) => null ,
62
+ focusTriggerAfterClose : true ,
60
63
} ) ,
61
64
data ( ) {
62
65
return {
@@ -81,16 +84,6 @@ export default {
81
84
} ,
82
85
} ,
83
86
84
- // private inTransition: boolean;
85
- // private titleId: string;
86
- // private openTime: number;
87
- // private lastOutSideFocusNode: HTMLElement | null;
88
- // private wrap: HTMLElement;
89
- // private dialog: any;
90
- // private sentinel: HTMLElement;
91
- // private bodyIsOverflowing: boolean;
92
- // private scrollbarWidth: number;
93
-
94
87
beforeMount ( ) {
95
88
this . inTransition = false ;
96
89
this . titleId = `rcDialogTitle${ uuid ++ } ` ;
@@ -107,7 +100,7 @@ export default {
107
100
beforeDestroy ( ) {
108
101
const { visible, getOpenCount } = this ;
109
102
if ( ( visible || this . inTransition ) && ! getOpenCount ( ) ) {
110
- this . removeScrollingEffect ( ) ;
103
+ this . switchScrollingEffect ( ) ;
111
104
}
112
105
clearTimeout ( this . timeoutId ) ;
113
106
} ,
@@ -118,12 +111,13 @@ export default {
118
111
} ,
119
112
updatedCallback ( visible ) {
120
113
const mousePosition = this . mousePosition ;
114
+ const { mask, focusTriggerAfterClose} = this ;
121
115
if ( this . visible ) {
122
116
// first show
123
117
if ( ! visible ) {
124
118
this . openTime = Date . now ( ) ;
125
119
// this.lastOutSideFocusNode = document.activeElement
126
- this . addScrollingEffect ( ) ;
120
+ this . switchScrollingEffect ( ) ;
127
121
// this.$refs.wrap.focus()
128
122
this . tryFocus ( ) ;
129
123
const dialogNode = this . $refs . dialog . $el ;
@@ -139,7 +133,7 @@ export default {
139
133
}
140
134
} else if ( visible ) {
141
135
this . inTransition = true ;
142
- if ( this . mask && this . lastOutSideFocusNode ) {
136
+ if ( mask && this . lastOutSideFocusNode && focusTriggerAfterClose ) {
143
137
try {
144
138
this . lastOutSideFocusNode . focus ( ) ;
145
139
} catch ( e ) {
@@ -166,7 +160,7 @@ export default {
166
160
this . destroyPopup = true ;
167
161
}
168
162
this . inTransition = false ;
169
- this . removeScrollingEffect ( ) ;
163
+ this . switchScrollingEffect ( ) ;
170
164
if ( afterClose ) {
171
165
afterClose ( ) ;
172
166
}
@@ -224,6 +218,7 @@ export default {
224
218
bodyStyle,
225
219
visible,
226
220
bodyProps,
221
+ forceRender,
227
222
} = this ;
228
223
const dest = { } ;
229
224
if ( width !== undefined ) {
@@ -284,6 +279,7 @@ export default {
284
279
ref = "dialog"
285
280
style = { style }
286
281
class = { cls }
282
+ forceRender = { forceRender }
287
283
onMousedown = { this . onDialogMouseDown }
288
284
>
289
285
< div tabIndex = { 0 } ref = "sentinelStart" style = { sentinelStyle } aria-hidden = "true" />
@@ -369,60 +365,50 @@ export default {
369
365
// document.body.style.paddingRight = `${this.scrollbarWidth}px`;
370
366
// }
371
367
// },
372
- addScrollingEffect ( ) {
368
+ switchScrollingEffect ( ) {
373
369
const { getOpenCount } = this ;
374
370
const openCount = getOpenCount ( ) ;
375
- if ( openCount !== 1 ) {
376
- return ;
377
- }
378
- switchScrollingEffect ( ) ;
379
- document . body . style . overflow = 'hidden' ;
380
- } ,
381
- removeScrollingEffect ( ) {
382
- const { getOpenCount } = this ;
383
- const openCount = getOpenCount ( ) ;
384
- if ( openCount !== 0 ) {
385
- return ;
371
+ if ( openCount === 1 ) {
372
+ if ( cacheOverflow . hasOwnProperty ( 'overflowX' ) ) {
373
+ return ;
374
+ }
375
+ cacheOverflow = {
376
+ overflowX : document . body . style . overflowX ,
377
+ overflowY : document . body . style . overflowY ,
378
+ overflow : document . body . style . overflow ,
379
+ } ;
380
+ switchScrollingEffect ( ) ;
381
+ // Must be set after switchScrollingEffect
382
+ document . body . style . overflow = 'hidden' ;
383
+ } else if ( ! openCount ) {
384
+ // IE browser doesn't merge overflow style, need to set it separately
385
+ // https://github.com/ant-design/ant-design/issues/19393
386
+ if ( cacheOverflow . overflow !== undefined ) {
387
+ document . body . style . overflow = cacheOverflow . overflow ;
388
+ }
389
+ if ( cacheOverflow . overflowX !== undefined ) {
390
+ document . body . style . overflowX = cacheOverflow . overflowX ;
391
+ }
392
+ if ( cacheOverflow . overflowY !== undefined ) {
393
+ document . body . style . overflowY = cacheOverflow . overflowY ;
394
+ }
395
+ cacheOverflow = { } ;
396
+ switchScrollingEffect ( true ) ;
386
397
}
387
- document . body . style . overflow = '' ;
388
- switchScrollingEffect ( true ) ;
389
- // this.resetAdjustments();
390
398
} ,
399
+ // removeScrollingEffect() {
400
+ // const { getOpenCount } = this;
401
+ // const openCount = getOpenCount();
402
+ // if (openCount !== 0) {
403
+ // return;
404
+ // }
405
+ // document.body.style.overflow = '';
406
+ // switchScrollingEffect(true);
407
+ // // this.resetAdjustments();
408
+ // },
391
409
close ( e ) {
392
410
this . __emit ( 'close' , e ) ;
393
411
} ,
394
- // checkScrollbar() {
395
- // let fullWindowWidth = window.innerWidth;
396
- // if (!fullWindowWidth) {
397
- // // workaround for missing window.innerWidth in IE8
398
- // const documentElementRect = document.documentElement.getBoundingClientRect();
399
- // fullWindowWidth = documentElementRect.right - Math.abs(documentElementRect.left);
400
- // }
401
- // this.bodyIsOverflowing = document.body.clientWidth < fullWindowWidth;
402
- // if (this.bodyIsOverflowing) {
403
- // this.scrollbarWidth = getScrollBarSize();
404
- // }
405
- // },
406
- // resetScrollbar() {
407
- // document.body.style.paddingRight = '';
408
- // },
409
- // adjustDialog() {
410
- // if (this.$refs.wrap && this.scrollbarWidth !== undefined) {
411
- // const modalIsOverflowing =
412
- // this.$refs.wrap.scrollHeight > document.documentElement.clientHeight;
413
- // this.$refs.wrap.style.paddingLeft = `${
414
- // !this.bodyIsOverflowing && modalIsOverflowing ? this.scrollbarWidth : ''
415
- // }px`;
416
- // this.$refs.wrap.style.paddingRight = `${
417
- // this.bodyIsOverflowing && !modalIsOverflowing ? this.scrollbarWidth : ''
418
- // }px`;
419
- // }
420
- // },
421
- // resetAdjustments() {
422
- // if (this.$refs.wrap) {
423
- // this.$refs.wrap.style.paddingLeft = this.$refs.wrap.style.paddingLeft = '';
424
- // }
425
- // },
426
412
} ,
427
413
render ( ) {
428
414
const { prefixCls, maskClosable, visible, wrapClassName, title, wrapProps } = this ;
@@ -433,7 +419,7 @@ export default {
433
419
style . display = null ;
434
420
}
435
421
return (
436
- < div >
422
+ < div class = { ` ${ prefixCls } -root` } >
437
423
{ this . getMaskElement ( ) }
438
424
< div
439
425
tabIndex = { - 1 }
0 commit comments