2
2
3
3
import React from 'react' ;
4
4
import { Component , View , Transition , PropTypes } from '../../libs' ;
5
+ import { cleanScrollBar } from '../table/utils' ;
5
6
6
7
type State = {
7
8
bodyOverflow : string ,
@@ -24,17 +25,19 @@ export default class Dialog extends Component {
24
25
25
26
constructor ( props : Object ) {
26
27
super ( props ) ;
27
-
28
+ this . wrap = React . createRef ( ) ;
28
29
this . state = {
29
30
bodyOverflow : ''
30
31
}
31
32
}
32
33
33
34
componentWillReceiveProps ( nextProps : Object ) : void {
34
-
35
+ const { bodyOverflow } = this . state ;
36
+ const { lockScroll, modal } = this . props ;
35
37
if ( this . willOpen ( this . props , nextProps ) ) {
36
- if ( this . props . lockScroll && document . body && document . body . style ) {
37
- if ( ! this . state . bodyOverflow ) {
38
+ cleanScrollBar ( ) ;
39
+ if ( lockScroll && document . body && document . body . style ) {
40
+ if ( ! bodyOverflow ) {
38
41
this . setState ( {
39
42
bodyOverflow : document . body . style . overflow
40
43
} ) ;
@@ -43,35 +46,38 @@ export default class Dialog extends Component {
43
46
}
44
47
}
45
48
46
- if ( this . willClose ( this . props , nextProps ) && this . props . lockScroll ) {
47
- if ( this . props . modal && this . state . bodyOverflow !== 'hidden' && document . body && document . body . style ) {
48
- document . body . style . overflow = this . state . bodyOverflow ;
49
+ if ( this . willClose ( this . props , nextProps ) && lockScroll ) {
50
+ if ( modal && bodyOverflow !== 'hidden' && document . body && document . body . style ) {
51
+ document . body . style . overflow = bodyOverflow ;
49
52
}
50
53
}
51
54
52
55
}
53
56
54
57
componentDidUpdate ( prevProps : Object ) : void {
55
58
if ( this . willOpen ( prevProps , this . props ) ) {
56
- this . refs . wrap . focus ( ) ;
59
+ this . wrap . current . focus ( ) ;
57
60
}
58
61
}
59
62
60
63
componentWillUnmount ( ) : void {
61
- if ( this . props . lockScroll && document . body && document . body . style ) {
64
+ const { lockScroll } = this . props ;
65
+ if ( lockScroll && document . body && document . body . style ) {
62
66
document . body . style . removeProperty ( 'overflow' ) ;
63
67
}
64
68
}
65
69
66
70
onKeyDown ( e : SyntheticKeyboardEvent < any > ) : void {
67
- if ( this . props . closeOnPressEscape && e . keyCode === 27 ) {
71
+ const { closeOnPressEscape } = this . props ;
72
+ if ( closeOnPressEscape && e . keyCode === 27 ) {
68
73
this . close ( e ) ;
69
74
}
70
75
}
71
76
72
77
handleWrapperClick ( e : SyntheticEvent < HTMLDivElement > ) : void {
78
+ const { closeOnClickModal } = this . props ;
73
79
if ( e . target instanceof HTMLDivElement ) {
74
- if ( this . props . closeOnClickModal && e . target === e . currentTarget ) {
80
+ if ( closeOnClickModal && e . target === e . currentTarget ) {
75
81
this . close ( e ) ;
76
82
}
77
83
}
@@ -90,14 +96,14 @@ export default class Dialog extends Component {
90
96
}
91
97
92
98
render ( ) : React . DOM {
93
- const { visible, title, size, top, modal, customClass, showClose } = this . props ;
99
+ const { visible , title , size , top , modal , customClass , showClose , children } = this . props ;
94
100
95
101
return (
96
102
< div >
97
103
< Transition name = "dialog-fade" >
98
104
< View show = { visible } >
99
105
< div
100
- ref = " wrap"
106
+ ref = { this . wrap }
101
107
style = { { zIndex : 1013 } }
102
108
className = { this . classNames ( 'el-dialog__wrapper' ) }
103
109
onClick = { e => this . handleWrapperClick ( e ) }
@@ -118,15 +124,15 @@ export default class Dialog extends Component {
118
124
)
119
125
}
120
126
</ div >
121
- { this . props . children }
127
+ { children }
122
128
</ div >
123
129
</ div >
124
130
</ View >
125
131
</ Transition >
126
132
{
127
133
modal && (
128
134
< View show = { visible } >
129
- < div className = "v-modal" style = { { zIndex : 1012 } } > </ div >
135
+ < div className = "v-modal" style = { { zIndex : 1012 } } / >
130
136
</ View >
131
137
)
132
138
}
0 commit comments