Skip to content

Commit

Permalink
Merge pull request tajo#57 from PeteJodo/master
Browse files Browse the repository at this point in the history
Portal should close with only a left button click
  • Loading branch information
tajo committed Mar 7, 2016
2 parents 0c8c97d + f023691 commit 9049f11
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export default class Portal extends React.Component {
if (!this.state.active) { return; }

const root = findDOMNode(this.portal);
if (root.contains(e.target) || e.target.tagName === 'HTML') { return; }
if (root.contains(e.target) || e.target.tagName === 'HTML' || e.button !== 0) { return; }

e.stopPropagation();
this.closePortal();
Expand Down
11 changes: 9 additions & 2 deletions test/portal_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,15 @@ describe('react-portal', () => {
it('closeOnOutsideClick', () => {
mount(<Portal closeOnOutsideClick isOpened><p>Hi</p></Portal>);
assert.equal(document.body.childElementCount, 1);
const mouseEvent = new window.MouseEvent('mousedown', {view: window});
document.dispatchEvent(mouseEvent);

// Should not close when outside click isn't a main click
const rightClickMouseEvent = new window.MouseEvent('mousedown', {view: window, button: 2});
document.dispatchEvent(rightClickMouseEvent);
assert.equal(document.body.childElementCount, 1);

// Should close when outside click is a main click (typically left button click)
const leftClickMouseEvent = new window.MouseEvent('mousedown', {view: window, button: 0});
document.dispatchEvent(leftClickMouseEvent);
assert.equal(document.body.childElementCount, 0);
});
});
Expand Down

0 comments on commit 9049f11

Please sign in to comment.