Skip to content

Commit acbc615

Browse files
committed
update dialog to 7.5.5
1 parent 154e246 commit acbc615

File tree

9 files changed

+114
-91
lines changed

9 files changed

+114
-91
lines changed

components/_util/switchScrollingEffect.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import getScrollBarSize from './getScrollBarSize';
22

3-
export default (close) => {
4-
const bodyIsOverflowing = document.body.scrollHeight >
5-
(window.innerHeight || document.documentElement.clientHeight) &&
3+
export default close => {
4+
const bodyIsOverflowing =
5+
document.body.scrollHeight > (window.innerHeight || document.documentElement.clientHeight) &&
66
window.innerWidth > document.body.offsetWidth;
77
if (!bodyIsOverflowing) {
88
return;

components/_util/warning.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ export function resetWarned() {
1919
warned = {};
2020
}
2121

22-
export function call(
23-
method,
24-
valid,
25-
message,
26-
) {
22+
export function call(method, valid, message) {
2723
if (!valid && !warned[message]) {
2824
method(false, message);
2925
warned[message] = true;

components/config-provider/index.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ function getWatch(keys = []) {
1414
return watch;
1515
}
1616

17-
1817
const ConfigProvider = {
1918
name: 'AConfigProvider',
2019
props: {

components/modal/__tests__/__snapshots__/Modal.test.js.snap

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ exports[`Modal render correctly 1`] = `
88
<div class="ant-modal-mask"></div>
99
<div tabindex="-1" role="dialog" class="ant-modal-wrap ">
1010
<div role="document" class="ant-modal" style="width: 520px;">
11-
<div tabindex="0" style="width: 0px; height: 0px; overflow: hidden;">sentinelStart</div>
12-
<div class="ant-modal-content"><button aria-label="Close" class="ant-modal-close"><span class="ant-modal-close-x"><i aria-label="icon: close" class="ant-modal-close-icon anticon anticon-close"><svg viewBox="64 64 896 896" data-icon="close" width="1em" height="1em" fill="currentColor" aria-hidden="true" class=""><path d="M563.8 512l262.5-312.9c4.4-5.2.7-13.1-6.1-13.1h-79.8c-4.7 0-9.2 2.1-12.3 5.7L511.6 449.8 295.1 191.7c-3-3.6-7.5-5.7-12.3-5.7H203c-6.8 0-10.5 7.9-6.1 13.1L459.4 512 196.9 824.9A7.95 7.95 0 0 0 203 838h79.8c4.7 0 9.2-2.1 12.3-5.7l216.5-258.1 216.5 258.1c3 3.6 7.5 5.7 12.3 5.7h79.8c6.8 0 10.5-7.9 6.1-13.1L563.8 512z"></path></svg></i></span></button>
11+
<div tabindex="0" aria-hidden="true" style="width: 0px; height: 0px; overflow: hidden;"></div>
12+
<div class="ant-modal-content"><button type="button" aria-label="Close" class="ant-modal-close"><span class="ant-modal-close-x"><i aria-label="icon: close" class="ant-modal-close-icon anticon anticon-close"><svg viewBox="64 64 896 896" data-icon="close" width="1em" height="1em" fill="currentColor" aria-hidden="true" class=""><path d="M563.8 512l262.5-312.9c4.4-5.2.7-13.1-6.1-13.1h-79.8c-4.7 0-9.2 2.1-12.3 5.7L511.6 449.8 295.1 191.7c-3-3.6-7.5-5.7-12.3-5.7H203c-6.8 0-10.5 7.9-6.1 13.1L459.4 512 196.9 824.9A7.95 7.95 0 0 0 203 838h79.8c4.7 0 9.2-2.1 12.3-5.7l216.5-258.1 216.5 258.1c3 3.6 7.5 5.7 12.3 5.7h79.8c6.8 0 10.5-7.9 6.1-13.1L563.8 512z"></path></svg></i></span></button>
1313
<div class="ant-modal-body">Here is content of Modal</div>
1414
<div class="ant-modal-footer">
1515
<div><button type="button" class="ant-btn ant-btn-default"><span>Cancel</span></button><button type="button" class="ant-btn ant-btn-primary"><span>OK</span></button></div>
1616
</div>
1717
</div>
18-
<div tabindex="0" style="width: 0px; height: 0px; overflow: hidden;">sentinelEnd</div>
18+
<div tabindex="0" aria-hidden="true" style="width: 0px; height: 0px; overflow: hidden;"></div>
1919
</div>
2020
</div>
2121
</div>
@@ -33,14 +33,14 @@ exports[`Modal render correctly 2`] = `
3333
<div class="ant-modal-mask"></div>
3434
<div tabindex="-1" role="dialog" class="ant-modal-wrap ">
3535
<div role="document" class="ant-modal" style="width: 520px;">
36-
<div tabindex="0" style="width: 0px; height: 0px; overflow: hidden;">sentinelStart</div>
37-
<div class="ant-modal-content"><button aria-label="Close" class="ant-modal-close"><span class="ant-modal-close-x"><i aria-label="icon: close" class="ant-modal-close-icon anticon anticon-close"><svg viewBox="64 64 896 896" data-icon="close" width="1em" height="1em" fill="currentColor" aria-hidden="true" class=""><path d="M563.8 512l262.5-312.9c4.4-5.2.7-13.1-6.1-13.1h-79.8c-4.7 0-9.2 2.1-12.3 5.7L511.6 449.8 295.1 191.7c-3-3.6-7.5-5.7-12.3-5.7H203c-6.8 0-10.5 7.9-6.1 13.1L459.4 512 196.9 824.9A7.95 7.95 0 0 0 203 838h79.8c4.7 0 9.2-2.1 12.3-5.7l216.5-258.1 216.5 258.1c3 3.6 7.5 5.7 12.3 5.7h79.8c6.8 0 10.5-7.9 6.1-13.1L563.8 512z"></path></svg></i></span></button>
36+
<div tabindex="0" aria-hidden="true" style="width: 0px; height: 0px; overflow: hidden;"></div>
37+
<div class="ant-modal-content"><button type="button" aria-label="Close" class="ant-modal-close"><span class="ant-modal-close-x"><i aria-label="icon: close" class="ant-modal-close-icon anticon anticon-close"><svg viewBox="64 64 896 896" data-icon="close" width="1em" height="1em" fill="currentColor" aria-hidden="true" class=""><path d="M563.8 512l262.5-312.9c4.4-5.2.7-13.1-6.1-13.1h-79.8c-4.7 0-9.2 2.1-12.3 5.7L511.6 449.8 295.1 191.7c-3-3.6-7.5-5.7-12.3-5.7H203c-6.8 0-10.5 7.9-6.1 13.1L459.4 512 196.9 824.9A7.95 7.95 0 0 0 203 838h79.8c4.7 0 9.2-2.1 12.3-5.7l216.5-258.1 216.5 258.1c3 3.6 7.5 5.7 12.3 5.7h79.8c6.8 0 10.5-7.9 6.1-13.1L563.8 512z"></path></svg></i></span></button>
3838
<div class="ant-modal-body">Here is content of Modal</div>
3939
<div class="ant-modal-footer">
4040
<div><button type="button" class="ant-btn ant-btn-default"><span>Cancel</span></button><button type="button" class="ant-btn ant-btn-primary"><span>OK</span></button></div>
4141
</div>
4242
</div>
43-
<div tabindex="0" style="width: 0px; height: 0px; overflow: hidden;">sentinelEnd</div>
43+
<div tabindex="0" aria-hidden="true" style="width: 0px; height: 0px; overflow: hidden;"></div>
4444
</div>
4545
</div>
4646
</div>
@@ -58,11 +58,11 @@ exports[`Modal render without footer 1`] = `
5858
<div class="ant-modal-mask"></div>
5959
<div tabindex="-1" role="dialog" class="ant-modal-wrap ">
6060
<div role="document" class="ant-modal" style="width: 520px;">
61-
<div tabindex="0" style="width: 0px; height: 0px; overflow: hidden;">sentinelStart</div>
62-
<div class="ant-modal-content"><button aria-label="Close" class="ant-modal-close"><span class="ant-modal-close-x"><i aria-label="icon: close" class="ant-modal-close-icon anticon anticon-close"><svg viewBox="64 64 896 896" data-icon="close" width="1em" height="1em" fill="currentColor" aria-hidden="true" class=""><path d="M563.8 512l262.5-312.9c4.4-5.2.7-13.1-6.1-13.1h-79.8c-4.7 0-9.2 2.1-12.3 5.7L511.6 449.8 295.1 191.7c-3-3.6-7.5-5.7-12.3-5.7H203c-6.8 0-10.5 7.9-6.1 13.1L459.4 512 196.9 824.9A7.95 7.95 0 0 0 203 838h79.8c4.7 0 9.2-2.1 12.3-5.7l216.5-258.1 216.5 258.1c3 3.6 7.5 5.7 12.3 5.7h79.8c6.8 0 10.5-7.9 6.1-13.1L563.8 512z"></path></svg></i></span></button>
61+
<div tabindex="0" aria-hidden="true" style="width: 0px; height: 0px; overflow: hidden;"></div>
62+
<div class="ant-modal-content"><button type="button" aria-label="Close" class="ant-modal-close"><span class="ant-modal-close-x"><i aria-label="icon: close" class="ant-modal-close-icon anticon anticon-close"><svg viewBox="64 64 896 896" data-icon="close" width="1em" height="1em" fill="currentColor" aria-hidden="true" class=""><path d="M563.8 512l262.5-312.9c4.4-5.2.7-13.1-6.1-13.1h-79.8c-4.7 0-9.2 2.1-12.3 5.7L511.6 449.8 295.1 191.7c-3-3.6-7.5-5.7-12.3-5.7H203c-6.8 0-10.5 7.9-6.1 13.1L459.4 512 196.9 824.9A7.95 7.95 0 0 0 203 838h79.8c4.7 0 9.2-2.1 12.3-5.7l216.5-258.1 216.5 258.1c3 3.6 7.5 5.7 12.3 5.7h79.8c6.8 0 10.5-7.9 6.1-13.1L563.8 512z"></path></svg></i></span></button>
6363
<div class="ant-modal-body">Here is content of Modal</div>
6464
</div>
65-
<div tabindex="0" style="width: 0px; height: 0px; overflow: hidden;">sentinelEnd</div>
65+
<div tabindex="0" aria-hidden="true" style="width: 0px; height: 0px; overflow: hidden;"></div>
6666
</div>
6767
</div>
6868
</div>

components/vc-dialog/Dialog.jsx

Lines changed: 80 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import { getComponentFromProp } from '../_util/props-util';
1+
import { getComponentFromProp, initDefaultProps } from '../_util/props-util';
22
import KeyCode from '../_util/KeyCode';
33
import contains from '../_util/Dom/contains';
44
import LazyRenderBox from './LazyRenderBox';
55
import BaseMixin from '../_util/BaseMixin';
66
import getTransitionProps from '../_util/getTransitionProps';
7-
import getScrollBarSize from '../_util/getScrollBarSize';
7+
import switchScrollingEffect from '../_util/switchScrollingEffect';
88
import getDialogPropTypes from './IDialogPropTypes';
99
const IDialogPropTypes = getDialogPropTypes();
1010

1111
let uuid = 0;
12-
let openCount = 0;
1312

1413
/* eslint react/no-is-mounted:0 */
1514
function noop() {}
@@ -46,23 +45,19 @@ function offset(el) {
4645
pos.top += getScroll(w, true);
4746
return pos;
4847
}
49-
const initDefaultProps = (propTypes, defaultProps) => {
50-
return Object.keys(defaultProps).map(k => propTypes[k].def(defaultProps[k]));
51-
};
48+
5249
export default {
5350
mixins: [BaseMixin],
54-
props: {
55-
...IDialogPropTypes,
56-
...initDefaultProps(IDialogPropTypes, {
57-
mask: true,
58-
visible: false,
59-
keyboard: true,
60-
closable: true,
61-
maskClosable: true,
62-
destroyOnClose: false,
63-
prefixCls: 'rc-dialog',
64-
}),
65-
},
51+
props: initDefaultProps(IDialogPropTypes, {
52+
mask: true,
53+
visible: false,
54+
keyboard: true,
55+
closable: true,
56+
maskClosable: true,
57+
destroyOnClose: false,
58+
prefixCls: 'rc-dialog',
59+
getOpenCount: () => null,
60+
}),
6661
data() {
6762
return {
6863
destroyPopup: false,
@@ -97,12 +92,18 @@ export default {
9792
mounted() {
9893
this.$nextTick(() => {
9994
this.updatedCallback(false);
95+
// if forceRender is true, set element style display to be none;
96+
if ((this.forceRender || (this.getContainer === false && !this.visible)) && this.$refs.wrap) {
97+
this.$refs.wrap.style.display = 'none';
98+
}
10099
});
101100
},
102101
beforeDestroy() {
103-
if (this.visible || this.inTransition) {
102+
const { visible, getOpenCount } = this;
103+
if ((visible || this.inTransition) && !getOpenCount()) {
104104
this.removeScrollingEffect();
105105
}
106+
clearTimeout(this.timeoutId);
106107
},
107108
methods: {
108109
updatedCallback(visible) {
@@ -160,12 +161,23 @@ export default {
160161
afterClose();
161162
}
162163
},
164+
onDialogMouseDown() {
165+
this.dialogMouseDown = true;
166+
},
167+
168+
onMaskMouseUp() {
169+
if (this.dialogMouseDown) {
170+
this.timeoutId = setTimeout(() => {
171+
this.dialogMouseDown = false;
172+
}, 0);
173+
}
174+
},
163175
onMaskClick(e) {
164176
// android trigger click on open (fastclick??)
165177
if (Date.now() - this.openTime < 300) {
166178
return;
167179
}
168-
if (e.target === e.currentTarget) {
180+
if (e.target === e.currentTarget && !this.dialogMouseDown) {
169181
this.close(e);
170182
}
171183
},
@@ -236,6 +248,7 @@ export default {
236248
const closeIcon = getComponentFromProp(this, 'closeIcon');
237249
closer = (
238250
<button
251+
type="button"
239252
key="close"
240253
onClick={this.close || noop}
241254
aria-label="Close"
@@ -261,10 +274,9 @@ export default {
261274
ref="dialog"
262275
style={style}
263276
class={cls}
277+
onMousedown={this.onDialogMouseDown}
264278
>
265-
<div tabIndex={0} ref="sentinelStart" style={sentinelStyle}>
266-
sentinelStart
267-
</div>
279+
<div tabIndex={0} ref="sentinelStart" style={sentinelStyle} aria-hidden="true" />
268280
<div class={`${prefixCls}-content`}>
269281
{closer}
270282
{header}
@@ -273,9 +285,7 @@ export default {
273285
</div>
274286
{footer}
275287
</div>
276-
<div tabIndex={0} ref="sentinelEnd" style={sentinelStyle}>
277-
sentinelEnd
278-
</div>
288+
<div tabIndex={0} ref="sentinelEnd" style={sentinelStyle} aria-hidden="true" />
279289
</LazyRenderBox>
280290
);
281291
const dialogTransitionProps = getTransitionProps(transitionName, {
@@ -344,65 +354,65 @@ export default {
344354
}
345355
return transitionName;
346356
},
347-
setScrollbar() {
348-
if (this.bodyIsOverflowing && this.scrollbarWidth !== undefined) {
349-
document.body.style.paddingRight = `${this.scrollbarWidth}px`;
350-
}
351-
},
357+
// setScrollbar() {
358+
// if (this.bodyIsOverflowing && this.scrollbarWidth !== undefined) {
359+
// document.body.style.paddingRight = `${this.scrollbarWidth}px`;
360+
// }
361+
// },
352362
addScrollingEffect() {
353-
openCount++;
363+
const { getOpenCount } = this;
364+
const openCount = getOpenCount();
354365
if (openCount !== 1) {
355366
return;
356367
}
357-
this.checkScrollbar();
358-
this.setScrollbar();
368+
switchScrollingEffect();
359369
document.body.style.overflow = 'hidden';
360-
// this.adjustDialog();
361370
},
362371
removeScrollingEffect() {
363-
openCount--;
372+
const { getOpenCount } = this;
373+
const openCount = getOpenCount();
364374
if (openCount !== 0) {
365375
return;
366376
}
367377
document.body.style.overflow = '';
368-
this.resetScrollbar();
378+
switchScrollingEffect(true);
369379
// this.resetAdjustments();
370380
},
371381
close(e) {
372382
this.__emit('close', e);
373383
},
374-
checkScrollbar() {
375-
let fullWindowWidth = window.innerWidth;
376-
if (!fullWindowWidth) {
377-
// workaround for missing window.innerWidth in IE8
378-
const documentElementRect = document.documentElement.getBoundingClientRect();
379-
fullWindowWidth = documentElementRect.right - Math.abs(documentElementRect.left);
380-
}
381-
this.bodyIsOverflowing = document.body.clientWidth < fullWindowWidth;
382-
if (this.bodyIsOverflowing) {
383-
this.scrollbarWidth = getScrollBarSize();
384-
}
385-
},
386-
resetScrollbar() {
387-
document.body.style.paddingRight = '';
388-
},
389-
adjustDialog() {
390-
if (this.$refs.wrap && this.scrollbarWidth !== undefined) {
391-
const modalIsOverflowing =
392-
this.$refs.wrap.scrollHeight > document.documentElement.clientHeight;
393-
this.$refs.wrap.style.paddingLeft = `${
394-
!this.bodyIsOverflowing && modalIsOverflowing ? this.scrollbarWidth : ''
395-
}px`;
396-
this.$refs.wrap.style.paddingRight = `${
397-
this.bodyIsOverflowing && !modalIsOverflowing ? this.scrollbarWidth : ''
398-
}px`;
399-
}
400-
},
401-
resetAdjustments() {
402-
if (this.$refs.wrap) {
403-
this.$refs.wrap.style.paddingLeft = this.$refs.wrap.style.paddingLeft = '';
404-
}
405-
},
384+
// checkScrollbar() {
385+
// let fullWindowWidth = window.innerWidth;
386+
// if (!fullWindowWidth) {
387+
// // workaround for missing window.innerWidth in IE8
388+
// const documentElementRect = document.documentElement.getBoundingClientRect();
389+
// fullWindowWidth = documentElementRect.right - Math.abs(documentElementRect.left);
390+
// }
391+
// this.bodyIsOverflowing = document.body.clientWidth < fullWindowWidth;
392+
// if (this.bodyIsOverflowing) {
393+
// this.scrollbarWidth = getScrollBarSize();
394+
// }
395+
// },
396+
// resetScrollbar() {
397+
// document.body.style.paddingRight = '';
398+
// },
399+
// adjustDialog() {
400+
// if (this.$refs.wrap && this.scrollbarWidth !== undefined) {
401+
// const modalIsOverflowing =
402+
// this.$refs.wrap.scrollHeight > document.documentElement.clientHeight;
403+
// this.$refs.wrap.style.paddingLeft = `${
404+
// !this.bodyIsOverflowing && modalIsOverflowing ? this.scrollbarWidth : ''
405+
// }px`;
406+
// this.$refs.wrap.style.paddingRight = `${
407+
// this.bodyIsOverflowing && !modalIsOverflowing ? this.scrollbarWidth : ''
408+
// }px`;
409+
// }
410+
// },
411+
// resetAdjustments() {
412+
// if (this.$refs.wrap) {
413+
// this.$refs.wrap.style.paddingLeft = this.$refs.wrap.style.paddingLeft = '';
414+
// }
415+
// },
406416
},
407417
render() {
408418
const { prefixCls, maskClosable, visible, wrapClassName, title, wrapProps } = this;
@@ -421,6 +431,7 @@ export default {
421431
class={`${prefixCls}-wrap ${wrapClassName || ''}`}
422432
ref="wrap"
423433
onClick={maskClosable ? this.onMaskClick : noop}
434+
onMouseup={maskClosable ? this.onMaskMouseUp : noop}
424435
role="dialog"
425436
aria-labelledby={title ? this.titleId : null}
426437
style={style}

components/vc-dialog/IDialogPropTypes.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ function IDialogPropTypes() {
3131
bodyProps: PropTypes.any,
3232
maskProps: PropTypes.any,
3333
wrapProps: PropTypes.any,
34-
getContainer: PropTypes.func,
34+
getContainer: PropTypes.any,
3535
dialogStyle: PropTypes.object.def({}),
3636
dialogClass: PropTypes.object.def({}),
3737
closeIcon: PropTypes.any,
38+
forceRender: PropTypes.bool,
39+
getOpenCount: PropTypes.func,
3840
};
3941
}
4042

components/vc-dialog/LazyRenderBox.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ const ILazyRenderBoxPropTypes = {
88
export default {
99
props: ILazyRenderBoxPropTypes,
1010
render() {
11-
return <div>{this.$slots.default}</div>;
11+
return <div {...{ on: this.$listeners }}>{this.$slots.default}</div>;
1212
},
1313
};

components/vc-dialog/demo/ant-design.vue

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ export default {
1818
width: 600,
1919
destroyOnClose: false,
2020
center: false,
21-
mousePosition: {},
21+
mousePosition: undefined,
2222
useIcon: false,
23+
forceRender: false,
2324
};
2425
},
2526
methods: {
@@ -55,6 +56,10 @@ export default {
5556
this.destroyOnClose = e.target.checked;
5657
},
5758
59+
onForceRenderChange (e) {
60+
this.forceRender = e.target.checked;
61+
},
62+
5863
changeWidth () {
5964
this.width = this.width === 600 ? 800 : 600;
6065
},
@@ -87,6 +92,7 @@ export default {
8792
mousePosition={this.mousePosition}
8893
destroyOnClose={this.destroyOnClose}
8994
closeIcon={this.useIcon ? this.getSvg(clearPath, {}, true) : undefined}
95+
forceRender={this.forceRender}
9096
>
9197
<input autoFocus/>
9298
<p>basic modal</p>
@@ -132,6 +138,15 @@ export default {
132138
onChange={this.handleCenter}
133139
/>
134140
</label>
141+
&nbsp;
142+
<label>
143+
force render
144+
<input
145+
type="checkbox"
146+
checked={this.forceRender}
147+
onChange={this.onForceRenderChange}
148+
/>
149+
</label>
135150
</p>
136151
{dialog}
137152
</div>

0 commit comments

Comments
 (0)