From 4232477489162511943be62dd20b2b72f28cd6d5 Mon Sep 17 00:00:00 2001 From: oisu Date: Thu, 2 Feb 2017 05:37:48 +0900 Subject: [PATCH] [fixed] Enable click to close in iOS (#301) (#304) (#313) --- lib/components/ModalPortal.js | 16 ++++------------ specs/Modal.spec.js | 13 +++++++------ 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/lib/components/ModalPortal.js b/lib/components/ModalPortal.js index e7d056a0..c1a07b54 100644 --- a/lib/components/ModalPortal.js +++ b/lib/components/ModalPortal.js @@ -130,13 +130,11 @@ var ModalPortal = module.exports = React.createClass({ } }, - handleOverlayMouseDown: function(event) { + handleOverlayOnClick: function (event) { if (this.shouldClose === null) { this.shouldClose = true; } - }, - handleOverlayMouseUp: function(event) { if (this.shouldClose && this.props.shouldCloseOnOverlayClick) { if (this.ownerHandlesClose()) this.requestClose(event); @@ -146,11 +144,7 @@ var ModalPortal = module.exports = React.createClass({ this.shouldClose = null; }, - handleContentMouseDown: function(event) { - this.shouldClose = false; - }, - - handleContentMouseUp: function(event) { + handleContentOnClick: function () { this.shouldClose = false; }, @@ -189,8 +183,7 @@ var ModalPortal = module.exports = React.createClass({ ref: "overlay", className: this.buildClassName('overlay', this.props.overlayClassName), style: Assign({}, overlayStyles, this.props.style.overlay || {}), - onMouseDown: this.handleOverlayMouseDown, - onMouseUp: this.handleOverlayMouseUp + onClick: this.handleOverlayOnClick }, div({ ref: "content", @@ -198,8 +191,7 @@ var ModalPortal = module.exports = React.createClass({ className: this.buildClassName('content', this.props.className), tabIndex: "-1", onKeyDown: this.handleKeyDown, - onMouseDown: this.handleContentMouseDown, - onMouseUp: this.handleContentMouseUp, + onClick: this.handleContentOnClick, role: this.props.role, "aria-label": this.props.contentLabel }, diff --git a/specs/Modal.spec.js b/specs/Modal.spec.js index c4003609..34f06dc4 100644 --- a/specs/Modal.spec.js +++ b/specs/Modal.spec.js @@ -295,8 +295,7 @@ describe('Modal', function () { expect(modal.props.isOpen).toEqual(true); var overlay = TestUtils.scryRenderedDOMComponentsWithClass(modal.portal, 'ReactModal__Overlay'); expect(overlay.length).toEqual(1); - Simulate.mouseDown(overlay[0]); // click the overlay - Simulate.mouseUp(overlay[0]); + Simulate.click(overlay[0]); // click the overlay expect(!requestCloseCallback.called).toBeTruthy(); }); @@ -312,8 +311,7 @@ describe('Modal', function () { expect(modal.props.isOpen).toEqual(true); var overlay = TestUtils.scryRenderedDOMComponentsWithClass(modal.portal, 'ReactModal__Overlay'); expect(overlay.length).toEqual(1); - Simulate.mouseDown(overlay[0]); // click the overlay - Simulate.mouseUp(overlay[0]); + Simulate.click(overlay[0]); // click the overlay expect(requestCloseCallback.called).toBeTruthy(); }); @@ -378,8 +376,11 @@ describe('Modal', function () { expect(modal.props.isOpen).toEqual(true); var overlay = TestUtils.scryRenderedDOMComponentsWithClass(modal.portal, 'ReactModal__Overlay'); expect(overlay.length).toEqual(1); - Simulate.mouseDown(overlay[0]); // click the overlay - Simulate.mouseUp(overlay[0]); + // click the overlay + Simulate.click(overlay[0], { + // Used to test that this was the event received + fakeData: 'ABC' + }); expect(requestCloseCallback.called).toBeTruthy(); // Check if event is passed to onRequestClose callback. var event = requestCloseCallback.getCall(0).args[0];