@@ -149,12 +149,29 @@ return /******/ (function(modules) { // webpackBootstrap
149
149
ariaAppHider . show ( this . props . appElement ) ;
150
150
}
151
151
152
+ var state = this . portal . state ;
153
+ var now = Date . now ( ) ;
154
+ var closesAt = state . isOpen && this . props . closeTimeoutMS && ( state . closesAt || now + this . props . closeTimeoutMS ) ;
155
+
156
+ if ( closesAt ) {
157
+ if ( ! state . beforeClose ) {
158
+ this . portal . closeWithTimeout ( ) ;
159
+ }
160
+
161
+ setTimeout ( this . removePortal . bind ( this ) , closesAt - now ) ;
162
+ } else {
163
+ this . removePortal ( ) ;
164
+ }
165
+ } ,
166
+
167
+ removePortal : function removePortal ( ) {
152
168
ReactDOM . unmountComponentAtNode ( this . node ) ;
153
169
var parent = getParentElement ( this . props . parentSelector ) ;
154
170
parent . removeChild ( this . node ) ;
155
171
elementClass ( document . body ) . remove ( 'ReactModal__Body--open' ) ;
156
172
} ,
157
173
174
+
158
175
renderPortal : function renderPortal ( props ) {
159
176
if ( props . isOpen ) {
160
177
elementClass ( document . body ) . add ( 'ReactModal__Body--open' ) ;
@@ -338,6 +355,11 @@ return /******/ (function(modules) { // webpackBootstrap
338
355
this . focusAfterRender = focus ;
339
356
} ,
340
357
358
+ afterClose : function afterClose ( ) {
359
+ focusManager . returnFocus ( ) ;
360
+ focusManager . teardownScopedFocus ( ) ;
361
+ } ,
362
+
341
363
open : function open ( ) {
342
364
if ( this . state . afterOpen && this . state . beforeClose ) {
343
365
clearTimeout ( this . closeTimer ) ;
@@ -355,6 +377,7 @@ return /******/ (function(modules) { // webpackBootstrap
355
377
}
356
378
} ,
357
379
380
+
358
381
close : function close ( ) {
359
382
if ( this . props . closeTimeoutMS > 0 ) this . closeWithTimeout ( ) ; else this . closeWithoutTimeout ( ) ;
360
383
} ,
@@ -367,24 +390,21 @@ return /******/ (function(modules) { // webpackBootstrap
367
390
} ,
368
391
369
392
closeWithTimeout : function closeWithTimeout ( ) {
370
- this . setState ( { beforeClose : true } , function ( ) {
371
- this . closeTimer = setTimeout ( this . closeWithoutTimeout , this . props . closeTimeoutMS ) ;
393
+ var closesAt = Date . now ( ) + this . props . closeTimeoutMS ;
394
+ this . setState ( { beforeClose : true , closesAt : closesAt } , function ( ) {
395
+ this . closeTimer = setTimeout ( this . closeWithoutTimeout , this . state . closesAt - Date . now ( ) ) ;
372
396
} . bind ( this ) ) ;
373
397
} ,
374
398
375
399
closeWithoutTimeout : function closeWithoutTimeout ( ) {
376
400
this . setState ( {
377
401
beforeClose : false ,
378
402
isOpen : false ,
379
- afterOpen : false
403
+ afterOpen : false ,
404
+ closesAt : null
380
405
} , this . afterClose ) ;
381
406
} ,
382
407
383
- afterClose : function afterClose ( ) {
384
- focusManager . returnFocus ( ) ;
385
- focusManager . teardownScopedFocus ( ) ;
386
- } ,
387
-
388
408
handleKeyDown : function handleKeyDown ( event ) {
389
409
if ( event . keyCode == 9 /*tab*/ ) scopeTab ( this . refs . content , event ) ;
390
410
if ( event . keyCode == 27 /*esc*/ ) {
@@ -393,24 +413,18 @@ return /******/ (function(modules) { // webpackBootstrap
393
413
}
394
414
} ,
395
415
396
- handleOverlayMouseDown : function handleOverlayMouseDown ( event ) {
416
+ handleOverlayOnClick : function handleOverlayOnClick ( event ) {
397
417
if ( this . shouldClose === null ) {
398
418
this . shouldClose = true ;
399
419
}
400
- } ,
401
420
402
- handleOverlayMouseUp : function handleOverlayMouseUp ( event ) {
403
421
if ( this . shouldClose && this . props . shouldCloseOnOverlayClick ) {
404
422
if ( this . ownerHandlesClose ( ) ) this . requestClose ( event ) ; else this . focusContent ( ) ;
405
423
}
406
424
this . shouldClose = null ;
407
425
} ,
408
426
409
- handleContentMouseDown : function handleContentMouseDown ( event ) {
410
- this . shouldClose = false ;
411
- } ,
412
-
413
- handleContentMouseUp : function handleContentMouseUp ( event ) {
427
+ handleContentOnClick : function handleContentOnClick ( ) {
414
428
this . shouldClose = false ;
415
429
} ,
416
430
@@ -423,7 +437,7 @@ return /******/ (function(modules) { // webpackBootstrap
423
437
} ,
424
438
425
439
shouldBeClosed : function shouldBeClosed ( ) {
426
- return ! this . props . isOpen && ! this . state . beforeClose ;
440
+ return ! this . state . isOpen && ! this . state . beforeClose ;
427
441
} ,
428
442
429
443
contentHasFocus : function contentHasFocus ( ) {
@@ -445,16 +459,14 @@ return /******/ (function(modules) { // webpackBootstrap
445
459
ref : "overlay" ,
446
460
className : this . buildClassName ( 'overlay' , this . props . overlayClassName ) ,
447
461
style : Assign ( { } , overlayStyles , this . props . style . overlay || { } ) ,
448
- onMouseDown : this . handleOverlayMouseDown ,
449
- onMouseUp : this . handleOverlayMouseUp
462
+ onClick : this . handleOverlayOnClick
450
463
} , div ( {
451
464
ref : "content" ,
452
465
style : Assign ( { } , contentStyles , this . props . style . content || { } ) ,
453
466
className : this . buildClassName ( 'content' , this . props . className ) ,
454
467
tabIndex : "-1" ,
455
468
onKeyDown : this . handleKeyDown ,
456
- onMouseDown : this . handleContentMouseDown ,
457
- onMouseUp : this . handleContentMouseUp ,
469
+ onClick : this . handleContentOnClick ,
458
470
role : this . props . role ,
459
471
"aria-label" : this . props . contentLabel
460
472
} , this . props . children ) ) ;
@@ -468,8 +480,8 @@ return /******/ (function(modules) { // webpackBootstrap
468
480
'use strict' ;
469
481
470
482
var findTabbable = __webpack_require__ ( 7 ) ;
483
+ var focusLaterElements = [ ] ;
471
484
var modalElement = null ;
472
- var focusLaterElement = null ;
473
485
var needToFocus = false ;
474
486
475
487
function handleBlur ( event ) {
@@ -484,8 +496,8 @@ return /******/ (function(modules) { // webpackBootstrap
484
496
}
485
497
// need to see how jQuery shims document.on('focusin') so we don't need the
486
498
// setTimeout, firefox doesn't support focusin, if it did, we could focus
487
- // the element outside of a setTimeout. Side-effect of this implementation
488
- // is that the document.body gets focus, and then we focus our element right
499
+ // the element outside of a setTimeout. Side-effect of this implementation
500
+ // is that the document.body gets focus, and then we focus our element right
489
501
// after, seems fine.
490
502
setTimeout ( function ( ) {
491
503
if ( modalElement . contains ( document . activeElement ) ) return ;
@@ -496,16 +508,18 @@ return /******/ (function(modules) { // webpackBootstrap
496
508
}
497
509
498
510
exports . markForFocusLater = function ( ) {
499
- focusLaterElement = document . activeElement ;
511
+ focusLaterElements . push ( document . activeElement ) ;
500
512
} ;
501
513
502
514
exports . returnFocus = function ( ) {
515
+ var toFocus = null ;
503
516
try {
504
- focusLaterElement . focus ( ) ;
517
+ toFocus = focusLaterElements . pop ( ) ;
518
+ toFocus . focus ( ) ;
519
+ return ;
505
520
} catch ( e ) {
506
- console . warn ( 'You tried to return focus to ' + focusLaterElement + ' but it is not in the DOM anymore' ) ;
521
+ console . warn ( 'You tried to return focus to ' + toFocus + ' but it is not in the DOM anymore' ) ;
507
522
}
508
- focusLaterElement = null ;
509
523
} ;
510
524
511
525
exports . setupScopedFocus = function ( element ) {
0 commit comments