Skip to content

Commit 4232477

Browse files
oisuclaydiffrient
authored andcommitted
[fixed] Enable click to close in iOS (#301) (#304) (#313)
1 parent 3ada4fb commit 4232477

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

lib/components/ModalPortal.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,11 @@ var ModalPortal = module.exports = React.createClass({
130130
}
131131
},
132132

133-
handleOverlayMouseDown: function(event) {
133+
handleOverlayOnClick: function (event) {
134134
if (this.shouldClose === null) {
135135
this.shouldClose = true;
136136
}
137-
},
138137

139-
handleOverlayMouseUp: function(event) {
140138
if (this.shouldClose && this.props.shouldCloseOnOverlayClick) {
141139
if (this.ownerHandlesClose())
142140
this.requestClose(event);
@@ -146,11 +144,7 @@ var ModalPortal = module.exports = React.createClass({
146144
this.shouldClose = null;
147145
},
148146

149-
handleContentMouseDown: function(event) {
150-
this.shouldClose = false;
151-
},
152-
153-
handleContentMouseUp: function(event) {
147+
handleContentOnClick: function () {
154148
this.shouldClose = false;
155149
},
156150

@@ -189,17 +183,15 @@ var ModalPortal = module.exports = React.createClass({
189183
ref: "overlay",
190184
className: this.buildClassName('overlay', this.props.overlayClassName),
191185
style: Assign({}, overlayStyles, this.props.style.overlay || {}),
192-
onMouseDown: this.handleOverlayMouseDown,
193-
onMouseUp: this.handleOverlayMouseUp
186+
onClick: this.handleOverlayOnClick
194187
},
195188
div({
196189
ref: "content",
197190
style: Assign({}, contentStyles, this.props.style.content || {}),
198191
className: this.buildClassName('content', this.props.className),
199192
tabIndex: "-1",
200193
onKeyDown: this.handleKeyDown,
201-
onMouseDown: this.handleContentMouseDown,
202-
onMouseUp: this.handleContentMouseUp,
194+
onClick: this.handleContentOnClick,
203195
role: this.props.role,
204196
"aria-label": this.props.contentLabel
205197
},

specs/Modal.spec.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,7 @@ describe('Modal', function () {
295295
expect(modal.props.isOpen).toEqual(true);
296296
var overlay = TestUtils.scryRenderedDOMComponentsWithClass(modal.portal, 'ReactModal__Overlay');
297297
expect(overlay.length).toEqual(1);
298-
Simulate.mouseDown(overlay[0]); // click the overlay
299-
Simulate.mouseUp(overlay[0]);
298+
Simulate.click(overlay[0]); // click the overlay
300299
expect(!requestCloseCallback.called).toBeTruthy();
301300
});
302301

@@ -312,8 +311,7 @@ describe('Modal', function () {
312311
expect(modal.props.isOpen).toEqual(true);
313312
var overlay = TestUtils.scryRenderedDOMComponentsWithClass(modal.portal, 'ReactModal__Overlay');
314313
expect(overlay.length).toEqual(1);
315-
Simulate.mouseDown(overlay[0]); // click the overlay
316-
Simulate.mouseUp(overlay[0]);
314+
Simulate.click(overlay[0]); // click the overlay
317315
expect(requestCloseCallback.called).toBeTruthy();
318316
});
319317

@@ -378,8 +376,11 @@ describe('Modal', function () {
378376
expect(modal.props.isOpen).toEqual(true);
379377
var overlay = TestUtils.scryRenderedDOMComponentsWithClass(modal.portal, 'ReactModal__Overlay');
380378
expect(overlay.length).toEqual(1);
381-
Simulate.mouseDown(overlay[0]); // click the overlay
382-
Simulate.mouseUp(overlay[0]);
379+
// click the overlay
380+
Simulate.click(overlay[0], {
381+
// Used to test that this was the event received
382+
fakeData: 'ABC'
383+
});
383384
expect(requestCloseCallback.called).toBeTruthy();
384385
// Check if event is passed to onRequestClose callback.
385386
var event = requestCloseCallback.getCall(0).args[0];

0 commit comments

Comments
 (0)