Skip to content

Commit 975e9ab

Browse files
committed
release v1.7.0
1 parent fb3eb5e commit 975e9ab

File tree

5 files changed

+54
-33
lines changed

5 files changed

+54
-33
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
v1.7.0 - Thu, 02 Mar 2017 03:54:08 GMT
2+
--------------------------------------
3+
4+
- [ea4f37a](../../commit/ea4f37a) [fixed] respect closeTimeoutMS during unmount
5+
- [4232477](../../commit/4232477) [fixed] Enable click to close in iOS (#301) (#304) (#313)
6+
7+
18
v1.6.5 - Sat, 31 Dec 2016 17:14:28 GMT
29
--------------------------------------
310

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-modal",
3-
"version": "1.6.5",
3+
"version": "1.7.0",
44
"homepage": "https://github.com/reactjs/react-modal",
55
"authors": [
66
"Ryan Florence",

dist/react-modal.js

+42-28
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,29 @@ return /******/ (function(modules) { // webpackBootstrap
149149
ariaAppHider.show(this.props.appElement);
150150
}
151151

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() {
152168
ReactDOM.unmountComponentAtNode(this.node);
153169
var parent = getParentElement(this.props.parentSelector);
154170
parent.removeChild(this.node);
155171
elementClass(document.body).remove('ReactModal__Body--open');
156172
},
157173

174+
158175
renderPortal: function renderPortal(props) {
159176
if (props.isOpen) {
160177
elementClass(document.body).add('ReactModal__Body--open');
@@ -338,6 +355,11 @@ return /******/ (function(modules) { // webpackBootstrap
338355
this.focusAfterRender = focus;
339356
},
340357

358+
afterClose: function afterClose() {
359+
focusManager.returnFocus();
360+
focusManager.teardownScopedFocus();
361+
},
362+
341363
open: function open() {
342364
if (this.state.afterOpen && this.state.beforeClose) {
343365
clearTimeout(this.closeTimer);
@@ -355,6 +377,7 @@ return /******/ (function(modules) { // webpackBootstrap
355377
}
356378
},
357379

380+
358381
close: function close() {
359382
if (this.props.closeTimeoutMS > 0) this.closeWithTimeout();else this.closeWithoutTimeout();
360383
},
@@ -367,24 +390,21 @@ return /******/ (function(modules) { // webpackBootstrap
367390
},
368391

369392
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());
372396
}.bind(this));
373397
},
374398

375399
closeWithoutTimeout: function closeWithoutTimeout() {
376400
this.setState({
377401
beforeClose: false,
378402
isOpen: false,
379-
afterOpen: false
403+
afterOpen: false,
404+
closesAt: null
380405
}, this.afterClose);
381406
},
382407

383-
afterClose: function afterClose() {
384-
focusManager.returnFocus();
385-
focusManager.teardownScopedFocus();
386-
},
387-
388408
handleKeyDown: function handleKeyDown(event) {
389409
if (event.keyCode == 9 /*tab*/) scopeTab(this.refs.content, event);
390410
if (event.keyCode == 27 /*esc*/) {
@@ -393,24 +413,18 @@ return /******/ (function(modules) { // webpackBootstrap
393413
}
394414
},
395415

396-
handleOverlayMouseDown: function handleOverlayMouseDown(event) {
416+
handleOverlayOnClick: function handleOverlayOnClick(event) {
397417
if (this.shouldClose === null) {
398418
this.shouldClose = true;
399419
}
400-
},
401420

402-
handleOverlayMouseUp: function handleOverlayMouseUp(event) {
403421
if (this.shouldClose && this.props.shouldCloseOnOverlayClick) {
404422
if (this.ownerHandlesClose()) this.requestClose(event);else this.focusContent();
405423
}
406424
this.shouldClose = null;
407425
},
408426

409-
handleContentMouseDown: function handleContentMouseDown(event) {
410-
this.shouldClose = false;
411-
},
412-
413-
handleContentMouseUp: function handleContentMouseUp(event) {
427+
handleContentOnClick: function handleContentOnClick() {
414428
this.shouldClose = false;
415429
},
416430

@@ -423,7 +437,7 @@ return /******/ (function(modules) { // webpackBootstrap
423437
},
424438

425439
shouldBeClosed: function shouldBeClosed() {
426-
return !this.props.isOpen && !this.state.beforeClose;
440+
return !this.state.isOpen && !this.state.beforeClose;
427441
},
428442

429443
contentHasFocus: function contentHasFocus() {
@@ -445,16 +459,14 @@ return /******/ (function(modules) { // webpackBootstrap
445459
ref: "overlay",
446460
className: this.buildClassName('overlay', this.props.overlayClassName),
447461
style: Assign({}, overlayStyles, this.props.style.overlay || {}),
448-
onMouseDown: this.handleOverlayMouseDown,
449-
onMouseUp: this.handleOverlayMouseUp
462+
onClick: this.handleOverlayOnClick
450463
}, div({
451464
ref: "content",
452465
style: Assign({}, contentStyles, this.props.style.content || {}),
453466
className: this.buildClassName('content', this.props.className),
454467
tabIndex: "-1",
455468
onKeyDown: this.handleKeyDown,
456-
onMouseDown: this.handleContentMouseDown,
457-
onMouseUp: this.handleContentMouseUp,
469+
onClick: this.handleContentOnClick,
458470
role: this.props.role,
459471
"aria-label": this.props.contentLabel
460472
}, this.props.children));
@@ -468,8 +480,8 @@ return /******/ (function(modules) { // webpackBootstrap
468480
'use strict';
469481

470482
var findTabbable = __webpack_require__(7);
483+
var focusLaterElements = [];
471484
var modalElement = null;
472-
var focusLaterElement = null;
473485
var needToFocus = false;
474486

475487
function handleBlur(event) {
@@ -484,8 +496,8 @@ return /******/ (function(modules) { // webpackBootstrap
484496
}
485497
// need to see how jQuery shims document.on('focusin') so we don't need the
486498
// 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
489501
// after, seems fine.
490502
setTimeout(function () {
491503
if (modalElement.contains(document.activeElement)) return;
@@ -496,16 +508,18 @@ return /******/ (function(modules) { // webpackBootstrap
496508
}
497509

498510
exports.markForFocusLater = function () {
499-
focusLaterElement = document.activeElement;
511+
focusLaterElements.push(document.activeElement);
500512
};
501513

502514
exports.returnFocus = function () {
515+
var toFocus = null;
503516
try {
504-
focusLaterElement.focus();
517+
toFocus = focusLaterElements.pop();
518+
toFocus.focus();
519+
return;
505520
} 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');
507522
}
508-
focusLaterElement = null;
509523
};
510524

511525
exports.setupScopedFocus = function (element) {

0 commit comments

Comments
 (0)