Skip to content

Commit 0f7e76b

Browse files
committed
fix: can not scroll when close dialog #5096
1 parent 81ab68f commit 0f7e76b

27 files changed

+654
-2018
lines changed

components/_util/switchScrollingEffect.js

-20
This file was deleted.
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import getScrollBarSize from './getScrollBarSize';
2+
import setStyle from './setStyle';
3+
4+
function isBodyOverflowing() {
5+
return (
6+
document.body.scrollHeight > (window.innerHeight || document.documentElement.clientHeight) &&
7+
window.innerWidth > document.body.offsetWidth
8+
);
9+
}
10+
11+
let cacheStyle = {};
12+
13+
export default (close?: boolean) => {
14+
if (!isBodyOverflowing() && !close) {
15+
return;
16+
}
17+
18+
// https://github.com/ant-design/ant-design/issues/19729
19+
const scrollingEffectClassName = 'ant-scrolling-effect';
20+
const scrollingEffectClassNameReg = new RegExp(`${scrollingEffectClassName}`, 'g');
21+
const bodyClassName = document.body.className;
22+
23+
if (close) {
24+
if (!scrollingEffectClassNameReg.test(bodyClassName)) return;
25+
setStyle(cacheStyle);
26+
cacheStyle = {};
27+
document.body.className = bodyClassName.replace(scrollingEffectClassNameReg, '').trim();
28+
return;
29+
}
30+
31+
const scrollBarSize = getScrollBarSize();
32+
if (scrollBarSize) {
33+
cacheStyle = setStyle({
34+
position: 'relative',
35+
width: `calc(100% - ${scrollBarSize}px)`,
36+
});
37+
if (!scrollingEffectClassNameReg.test(bodyClassName)) {
38+
const addClassName = `${bodyClassName} ${scrollingEffectClassName}`;
39+
document.body.className = addClassName.trim();
40+
}
41+
}
42+
};

components/modal/style/confirm.less

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
}
99

1010
.@{ant-prefix}-modal-body {
11-
padding: 32px 32px 24px;
11+
padding: @modal-confirm-body-padding;
1212
}
1313

1414
&-body-wrapper {
@@ -49,7 +49,7 @@
4949
float: right;
5050
margin-top: 24px;
5151

52-
button + button {
52+
.@{ant-prefix}-btn + .@{ant-prefix}-btn {
5353
margin-bottom: 0;
5454
margin-left: 8px;
5555
}

components/modal/style/index.less

+3
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
@import '../../style/mixins/index';
33
@import './modal';
44
@import './confirm';
5+
@import './rtl';
6+
7+
.popover-customize-bg(@dialog-prefix-cls, @popover-background);
File renamed without changes.

components/modal/style/modal.less

+17-46
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,26 @@
11
@dialog-prefix-cls: ~'@{ant-prefix}-modal';
2-
@table-prefix-cls: ~'@{ant-prefix}-table';
3-
@modal-footer-padding-vertical: 10px;
4-
@modal-footer-padding-horizontal: 16px;
52

63
.@{dialog-prefix-cls} {
74
.reset-component();
5+
.modal-mask();
86

97
position: relative;
108
top: 100px;
119
width: auto;
10+
max-width: calc(100vw - 32px);
1211
margin: 0 auto;
1312
padding-bottom: 24px;
14-
pointer-events: none;
1513

1614
&-wrap {
17-
position: fixed;
18-
top: 0;
19-
right: 0;
20-
bottom: 0;
21-
left: 0;
2215
z-index: @zindex-modal;
23-
overflow: auto;
24-
outline: 0;
25-
-webkit-overflow-scrolling: touch;
2616
}
2717

2818
&-title {
2919
margin: 0;
3020
color: @modal-heading-color;
3121
font-weight: 500;
32-
font-size: @font-size-lg;
33-
line-height: 22px;
22+
font-size: @modal-header-title-font-size;
23+
line-height: @modal-header-title-line-height;
3424
word-wrap: break-word;
3525
}
3626

@@ -50,7 +40,7 @@
5040
right: 0;
5141
z-index: @zindex-popup-close;
5242
padding: 0;
53-
color: @text-color-secondary;
43+
color: @modal-close-color;
5444
font-weight: 700;
5545
line-height: 1;
5646
text-decoration: none;
@@ -62,11 +52,11 @@
6252

6353
&-x {
6454
display: block;
65-
width: 56px;
66-
height: 56px;
55+
width: @modal-header-close-size;
56+
height: @modal-header-close-size;
6757
font-size: @font-size-lg;
6858
font-style: normal;
69-
line-height: 56px;
59+
line-height: @modal-header-close-size;
7060
text-align: center;
7161
text-transform: none;
7262
text-rendering: auto;
@@ -80,10 +70,11 @@
8070
}
8171

8272
&-header {
83-
padding: 16px 24px;
73+
padding: @modal-header-padding;
8474
color: @text-color;
8575
background: @modal-header-bg;
86-
border-bottom: @border-width-base @border-style-base @modal-header-border-color-split;
76+
border-bottom: @modal-header-border-width @modal-header-border-style
77+
@modal-header-border-color-split;
8778
border-radius: @border-radius-base @border-radius-base 0 0;
8879
}
8980

@@ -98,45 +89,24 @@
9889
padding: @modal-footer-padding-vertical @modal-footer-padding-horizontal;
9990
text-align: right;
10091
background: @modal-footer-bg;
101-
border-top: @border-width-base @border-style-base @modal-footer-border-color-split;
92+
border-top: @modal-footer-border-width @modal-footer-border-style
93+
@modal-footer-border-color-split;
10294
border-radius: 0 0 @border-radius-base @border-radius-base;
103-
button + button {
95+
96+
.@{ant-prefix}-btn + .@{ant-prefix}-btn:not(.@{ant-prefix}-dropdown-trigger) {
10497
margin-bottom: 0;
10598
margin-left: 8px;
10699
}
107100
}
108101

109-
&.zoom-enter,
110-
&.zoom-appear {
111-
transform: none; // reset scale avoid mousePosition bug
112-
opacity: 0;
113-
animation-duration: @animation-duration-slow;
114-
user-select: none; // https://github.com/ant-design/ant-design/issues/11777
115-
}
116-
117-
&-mask {
118-
position: fixed;
119-
top: 0;
120-
right: 0;
121-
bottom: 0;
122-
left: 0;
123-
z-index: @zindex-modal-mask;
124-
height: 100%;
125-
background-color: @modal-mask-bg;
126-
filter: ~'alpha(opacity=50)';
127-
128-
&-hidden {
129-
display: none;
130-
}
131-
}
132-
133102
&-open {
134103
overflow: hidden;
135104
}
136105
}
137106

138107
.@{dialog-prefix-cls}-centered {
139108
text-align: center;
109+
140110
&::before {
141111
display: inline-block;
142112
width: 0;
@@ -147,6 +117,7 @@
147117
.@{dialog-prefix-cls} {
148118
top: 0;
149119
display: inline-block;
120+
padding-bottom: 0;
150121
text-align: left;
151122
vertical-align: middle;
152123
}

components/modal/style/rtl.less

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
@import '../../style/themes/index';
2+
@import '../../style/mixins/index';
3+
4+
@dialog-prefix-cls: ~'@{ant-prefix}-modal';
5+
@confirm-prefix-cls: ~'@{ant-prefix}-modal-confirm';
6+
@dialog-wrap-rtl-cls: ~'@{dialog-prefix-cls}-wrap-rtl';
7+
8+
.@{dialog-prefix-cls} {
9+
&-wrap {
10+
&-rtl {
11+
direction: rtl;
12+
}
13+
}
14+
15+
&-close {
16+
.@{dialog-wrap-rtl-cls} & {
17+
right: initial;
18+
left: 0;
19+
}
20+
}
21+
22+
&-footer {
23+
.@{dialog-wrap-rtl-cls} & {
24+
text-align: left;
25+
}
26+
.@{ant-prefix}-btn + .@{ant-prefix}-btn {
27+
.@{dialog-wrap-rtl-cls} & {
28+
margin-right: 8px;
29+
margin-left: 0;
30+
}
31+
}
32+
}
33+
34+
&-confirm {
35+
&-body {
36+
.@{dialog-wrap-rtl-cls} & {
37+
direction: rtl;
38+
}
39+
> .@{iconfont-css-prefix} {
40+
.@{dialog-wrap-rtl-cls} & {
41+
float: right;
42+
margin-right: 0;
43+
margin-left: 16px;
44+
}
45+
+ .@{confirm-prefix-cls}-title + .@{confirm-prefix-cls}-content {
46+
.@{dialog-wrap-rtl-cls} & {
47+
margin-right: 38px;
48+
margin-left: 0;
49+
}
50+
}
51+
}
52+
}
53+
54+
&-btns {
55+
.@{dialog-wrap-rtl-cls} & {
56+
float: left;
57+
}
58+
.@{ant-prefix}-btn + .@{ant-prefix}-btn {
59+
.@{dialog-wrap-rtl-cls} & {
60+
margin-right: 8px;
61+
margin-left: 0;
62+
}
63+
}
64+
}
65+
}
66+
}
67+
68+
.@{dialog-prefix-cls}-centered {
69+
.@{dialog-prefix-cls} {
70+
.@{dialog-wrap-rtl-cls}& {
71+
text-align: right;
72+
}
73+
}
74+
}

components/style/themes/default.less

+14-3
Original file line numberDiff line numberDiff line change
@@ -522,17 +522,28 @@
522522

523523
// Modal
524524
// --
525-
@modal-body-padding: 24px;
525+
@modal-header-padding-vertical: @padding-md;
526+
@modal-header-padding-horizontal: @padding-lg;
527+
@modal-body-padding: @padding-lg;
526528
@modal-header-bg: @component-background;
529+
@modal-header-padding: @modal-header-padding-vertical @modal-header-padding-horizontal;
530+
@modal-header-border-width: @border-width-base;
531+
@modal-header-border-style: @border-style-base;
532+
@modal-header-title-line-height: 22px;
533+
@modal-header-title-font-size: @font-size-lg;
527534
@modal-header-border-color-split: @border-color-split;
535+
@modal-header-close-size: 56px;
528536
@modal-content-bg: @component-background;
529537
@modal-heading-color: @heading-color;
538+
@modal-close-color: @text-color-secondary;
530539
@modal-footer-bg: transparent;
531540
@modal-footer-border-color-split: @border-color-split;
532-
@modal-mask-bg: fade(@black, 45%);
533-
@modal-close-color: @text-color-secondary;
541+
@modal-footer-border-style: @border-style-base;
534542
@modal-footer-padding-vertical: 10px;
535543
@modal-footer-padding-horizontal: 16px;
544+
@modal-footer-border-width: @border-width-base;
545+
@modal-mask-bg: fade(@black, 45%);
546+
@modal-confirm-body-padding: 32px 32px 24px;
536547

537548
// Progress
538549
// --

0 commit comments

Comments
 (0)