Skip to content

Commit cf70338

Browse files
Dali Zhengclaydiffrient
Dali Zheng
authored andcommitted
Avoid stopPropagation
* avoid using stopPropagation * add test for avoiding stopPropagation
1 parent f9871c6 commit cf70338

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

Diff for: lib/components/ModalPortal.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ var defaultStyles = {
4444
}
4545
};
4646

47-
function stopPropagation(event) {
48-
event.stopPropagation();
49-
}
50-
5147
var ModalPortal = module.exports = React.createClass({
5248

5349
displayName: 'ModalPortal',
@@ -148,7 +144,14 @@ var ModalPortal = module.exports = React.createClass({
148144
}
149145
},
150146

151-
handleOverlayClick: function() {
147+
handleOverlayClick: function(event) {
148+
var node = event.target
149+
150+
while (node) {
151+
if (node === this.refs.content) return
152+
node = node.parentNode
153+
}
154+
152155
if (this.props.shouldCloseOnOverlayClick) {
153156
if (this.ownerHandlesClose())
154157
this.requestClose();
@@ -195,7 +198,6 @@ var ModalPortal = module.exports = React.createClass({
195198
style: Assign({}, contentStyles, this.props.style.content || {}),
196199
className: this.buildClassName('content', this.props.className),
197200
tabIndex: "-1",
198-
onClick: stopPropagation,
199201
onKeyDown: this.handleKeyDown
200202
},
201203
this.props.children

Diff for: specs/Modal.spec.js

+12
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,18 @@ describe('Modal', function () {
237237
Simulate.click(overlay[0]); // click the overlay
238238
ok(requestCloseCallback.called)
239239
});
240+
241+
it('should not stop event propagation', function() {
242+
var hasPropagated = false
243+
var modal = renderModal({
244+
isOpen: true,
245+
shouldCloseOnOverlayClick: true
246+
});
247+
var overlay = TestUtils.scryRenderedDOMComponentsWithClass(modal.portal, 'ReactModal__Overlay');
248+
window.addEventListener('click', function () { hasPropagated = true })
249+
overlay[0].dispatchEvent(new MouseEvent('click', { bubbles: true }))
250+
ok(hasPropagated)
251+
});
240252
});
241253
});
242254

0 commit comments

Comments
 (0)