Skip to content

Commit

Permalink
Avoid stopPropagation
Browse files Browse the repository at this point in the history
* avoid using stopPropagation

* add test for avoiding stopPropagation
  • Loading branch information
Dali Zheng authored and claydiffrient committed Apr 6, 2016
1 parent f9871c6 commit cf70338
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/components/ModalPortal.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ var defaultStyles = {
}
};

function stopPropagation(event) {
event.stopPropagation();
}

var ModalPortal = module.exports = React.createClass({

displayName: 'ModalPortal',
Expand Down Expand Up @@ -148,7 +144,14 @@ var ModalPortal = module.exports = React.createClass({
}
},

handleOverlayClick: function() {
handleOverlayClick: function(event) {
var node = event.target

while (node) {
if (node === this.refs.content) return
node = node.parentNode
}

if (this.props.shouldCloseOnOverlayClick) {
if (this.ownerHandlesClose())
this.requestClose();
Expand Down Expand Up @@ -195,7 +198,6 @@ var ModalPortal = module.exports = React.createClass({
style: Assign({}, contentStyles, this.props.style.content || {}),
className: this.buildClassName('content', this.props.className),
tabIndex: "-1",
onClick: stopPropagation,
onKeyDown: this.handleKeyDown
},
this.props.children
Expand Down
12 changes: 12 additions & 0 deletions specs/Modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,18 @@ describe('Modal', function () {
Simulate.click(overlay[0]); // click the overlay
ok(requestCloseCallback.called)
});

it('should not stop event propagation', function() {
var hasPropagated = false
var modal = renderModal({
isOpen: true,
shouldCloseOnOverlayClick: true
});
var overlay = TestUtils.scryRenderedDOMComponentsWithClass(modal.portal, 'ReactModal__Overlay');
window.addEventListener('click', function () { hasPropagated = true })
overlay[0].dispatchEvent(new MouseEvent('click', { bubbles: true }))
ok(hasPropagated)
});
});
});

Expand Down

0 comments on commit cf70338

Please sign in to comment.