File tree 2 files changed +36
-3
lines changed
2 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -269,9 +269,12 @@ const Modal = React.createClass({
269
269
} ,
270
270
271
271
focusModalContent ( ) {
272
- this . lastFocus = domUtils . activeElement ( this ) ;
273
- let modalContent = React . findDOMNode ( this . refs . modal ) ;
274
- modalContent . focus ( ) ;
272
+ if ( this . props . enforceFocus ) {
273
+ this . lastFocus = domUtils . activeElement ( this ) ;
274
+
275
+ let modalContent = React . findDOMNode ( this . refs . modal ) ;
276
+ modalContent . focus ( ) ;
277
+ }
275
278
} ,
276
279
277
280
restoreLastFocus ( ) {
Original file line number Diff line number Diff line change @@ -156,6 +156,36 @@ describe('Modal', function () {
156
156
} , 0 ) ;
157
157
} ) ;
158
158
159
+ it ( 'Should not focus on the Modal when enforceFocus is false' , function ( done ) {
160
+
161
+ document . activeElement . should . equal ( focusableContainer ) ;
162
+
163
+ let Container = React . createClass ( {
164
+ getInitialState ( ) {
165
+ return { modalOpen : true } ;
166
+ } ,
167
+ render ( ) {
168
+ if ( this . state . modalOpen ) {
169
+ return (
170
+ < Modal enforceFocus = { false } onRequestHide = { ( ) => { } } container = { this } >
171
+ < strong > Message</ strong >
172
+ </ Modal >
173
+ ) ;
174
+ } else {
175
+ return < span /> ;
176
+ }
177
+ }
178
+ } ) ;
179
+
180
+ React . render ( < Container /> , focusableContainer ) ;
181
+
182
+ setTimeout ( function ( ) {
183
+ // modal should be focused when opened
184
+ document . activeElement . should . equal ( focusableContainer ) ;
185
+ done ( ) ;
186
+ } , 0 ) ;
187
+ } ) ;
159
188
} ) ;
160
189
190
+
161
191
} ) ;
You can’t perform that action at this time.
0 commit comments