Skip to content

Commit 6ba1c8d

Browse files
oisuclaydiffrient
authored andcommitted
[fixed] Enable click to close in iOS (#301) (#304) (#313)
1 parent 75a1aa3 commit 6ba1c8d

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

lib/components/ModalPortal.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,10 @@ export default class ModalPortal extends Component {
153153
}
154154
}
155155

156-
handleOverlayMouseDown = () => {
156+
handleOverlayOnClick = (event) => {
157157
if (this.shouldClose === null) {
158158
this.shouldClose = true;
159159
}
160-
}
161-
162-
handleOverlayMouseUp = (event) => {
163160
if (this.shouldClose && this.props.shouldCloseOnOverlayClick) {
164161
if (this.ownerHandlesClose()) {
165162
this.requestClose(event);
@@ -170,11 +167,7 @@ export default class ModalPortal extends Component {
170167
this.shouldClose = null;
171168
}
172169

173-
handleContentMouseDown = () => {
174-
this.shouldClose = false;
175-
}
176-
177-
handleContentMouseUp = () => {
170+
handleContentOnClick = () => {
178171
this.shouldClose = false;
179172
}
180173

@@ -217,17 +210,15 @@ export default class ModalPortal extends Component {
217210
ref={(c) => { this.overlay = c; }}
218211
className={this.buildClassName('overlay', this.props.overlayClassName)}
219212
style={Assign({}, overlayStyles, this.props.style.overlay || {})}
220-
onMouseDown={this.handleOverlayMouseDown}
221-
onMouseUp={this.handleOverlayMouseUp}
213+
onClick={this.handleOverlayOnClick}
222214
>
223215
<div
224216
ref={(c) => { this.content = c; }}
225217
style={Assign({}, contentStyles, this.props.style.content || {})}
226218
className={this.buildClassName('content', this.props.className)}
227219
tabIndex={-1}
228220
onKeyDown={this.handleKeyDown}
229-
onMouseDown={this.handleContentMouseDown}
230-
onMouseUp={this.handleContentMouseUp}
221+
onClick={this.handleContentOnClick}
231222
role={this.props.role}
232223
aria-label={this.props.contentLabel}
233224
>

specs/Modal.spec.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,7 @@ describe('Modal', () => {
321321
expect(modal.props.isOpen).toEqual(true);
322322
const overlay = TestUtils.scryRenderedDOMComponentsWithClass(modal.portal, 'ReactModal__Overlay');
323323
expect(overlay.length).toEqual(1);
324-
Simulate.mouseDown(overlay[0]); // click the overlay
325-
Simulate.mouseUp(overlay[0]);
324+
Simulate.click(overlay[0]); // click the overlay
326325
expect(!requestCloseCallback.called).toBeTruthy();
327326
});
328327

@@ -338,8 +337,7 @@ describe('Modal', () => {
338337
expect(modal.props.isOpen).toEqual(true);
339338
const overlay = TestUtils.scryRenderedDOMComponentsWithClass(modal.portal, 'ReactModal__Overlay');
340339
expect(overlay.length).toEqual(1);
341-
Simulate.mouseDown(overlay[0]); // click the overlay
342-
Simulate.mouseUp(overlay[0]);
340+
Simulate.click(overlay[0]); // click the overlay
343341
expect(requestCloseCallback.called).toBeTruthy();
344342
});
345343

@@ -413,8 +411,7 @@ describe('Modal', () => {
413411
const overlay = TestUtils.scryRenderedDOMComponentsWithClass(modal.portal, 'ReactModal__Overlay');
414412
expect(overlay.length).toEqual(1);
415413
// click the overlay
416-
Simulate.mouseDown(overlay[0]);
417-
Simulate.mouseUp(overlay[0], {
414+
Simulate.click(overlay[0], {
418415
// Used to test that this was the event received
419416
fakeData: 'ABC'
420417
});

0 commit comments

Comments
 (0)