File tree Expand file tree Collapse file tree 4 files changed +21
-4
lines changed Expand file tree Collapse file tree 4 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,8 @@ Accessible modal dialog component for React.JS
7
7
``` xml
8
8
<Modal
9
9
isOpen ={bool}
10
- onRequestClose ={fn}
10
+ onAfterOpen ={afterOpenFn}
11
+ onRequestClose ={requestOpenFn}
11
12
closeTimeoutMS ={n}
12
13
style ={customStyle}>
13
14
@@ -95,6 +96,11 @@ var App = React.createClass({
95
96
this .setState ({modalIsOpen: true });
96
97
},
97
98
99
+ afterOpenModal : function () {
100
+ // references are now sync'd and can be accessed.
101
+ this .refs .subtitle .style .color = ' #f00' ;
102
+ },
103
+
98
104
closeModal : function () {
99
105
this .setState ({modalIsOpen: false });
100
106
},
@@ -105,10 +111,11 @@ var App = React.createClass({
105
111
< button onClick= {this .openModal }> Open Modal< / button>
106
112
< Modal
107
113
isOpen= {this .state .modalIsOpen }
114
+ onAfterOpen= {this .afterOpenModal }
108
115
onRequestClose= {this .closeModal }
109
116
style= {customStyles} >
110
117
111
- < h2> Hello< / h2>
118
+ < h2 ref = " subtitle " > Hello< / h2>
112
119
< button onClick= {this .closeModal }> close< / button>
113
120
< div> I am a modal< / div>
114
121
< form>
@@ -137,7 +144,8 @@ pass the 'shouldCloseOnOverlayClick' prop with 'false' value.
137
144
``` xml
138
145
<Modal
139
146
isOpen ={bool}
140
- onRequestClose ={fn}
147
+ onAfterOpen ={afterOpenFn}
148
+ onRequestClose ={requestCloseFn}
141
149
closeTimeoutMS ={n}
142
150
shouldCloseOnOverlayClick ={false}
143
151
style ={customStyle}>
Original file line number Diff line number Diff line change @@ -60,17 +60,24 @@ var App = React.createClass({
60
60
this . setState ( { foo : 'bar' } ) ;
61
61
} ,
62
62
63
+ handleOnAfterOpenModal : function ( ) {
64
+ // when ready, we can access the available refs.
65
+ this . refs . title . style . color = '#F00' ;
66
+ } ,
67
+
63
68
render : function ( ) {
64
69
return (
65
70
< div >
66
71
< button onClick = { this . openModal } > Open Modal</ button >
67
72
< button onClick = { this . openModal2 } > Open Modal 2</ button >
68
73
< Modal
74
+ ref = "mymodal"
69
75
closeTimeoutMS = { 150 }
70
76
isOpen = { this . state . modalIsOpen }
77
+ onAfterOpen = { this . handleOnAfterOpenModal }
71
78
onRequestClose = { this . handleModalCloseRequest }
72
79
>
73
- < h1 > Hello</ h1 >
80
+ < h1 ref = "title" > Hello</ h1 >
74
81
< button onClick = { this . closeModal } > close</ button >
75
82
< div > I am a modal</ div >
76
83
< form >
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ var Modal = React.createClass({
31
31
overlay : React . PropTypes . object
32
32
} ) ,
33
33
appElement : React . PropTypes . instanceOf ( SafeHTMLElement ) ,
34
+ onAfterOpen : React . PropTypes . func ,
34
35
onRequestClose : React . PropTypes . func ,
35
36
closeTimeoutMS : React . PropTypes . number ,
36
37
ariaHideApp : React . PropTypes . bool ,
Original file line number Diff line number Diff line change @@ -76,6 +76,7 @@ var ModalPortal = module.exports = React.createClass({
76
76
focusManager . markForFocusLater ( ) ;
77
77
this . setState ( { isOpen : true } , function ( ) {
78
78
this . setState ( { afterOpen : true } ) ;
79
+ ( this . props . isOpen && this . props . onAfterOpen ) && this . props . onAfterOpen ( ) ;
79
80
} . bind ( this ) ) ;
80
81
} ,
81
82
You can’t perform that action at this time.
0 commit comments