Skip to content

Commit

Permalink
fix(popper): account for touchstart
Browse files Browse the repository at this point in the history
fixes dropdowns, tooltips, and popovers not triggers on touch events

Closes #456 #458
  • Loading branch information
TheSharpieOne committed Sep 16, 2017
1 parent 9b32cee commit 9b80d11
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,15 @@ class Dropdown extends React.Component {
}

addEvents() {
document.addEventListener('click', this.handleDocumentClick, true);
['click', 'touchstart'].forEach(event =>
document.addEventListener(event, this.handleDocumentClick, true)
);
}

removeEvents() {
document.removeEventListener('click', this.handleDocumentClick, true);
['click', 'touchstart'].forEach(event =>
document.removeEventListener(event, this.handleDocumentClick, true)
);
}

handleDocumentClick(e) {
Expand Down
8 changes: 6 additions & 2 deletions src/Popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,15 @@ class Popover extends React.Component {
}

addTargetEvents() {
document.addEventListener('click', this.handleDocumentClick, true);
['click', 'touchstart'].forEach(event =>
document.addEventListener(event, this.handleDocumentClick, true)
);
}

removeTargetEvents() {
document.removeEventListener('click', this.handleDocumentClick, true);
['click', 'touchstart'].forEach(event =>
document.removeEventListener(event, this.handleDocumentClick, true)
);
}

toggle(e) {
Expand Down
8 changes: 6 additions & 2 deletions src/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,17 @@ class Tooltip extends React.Component {
addTargetEvents() {
this._target.addEventListener('mouseover', this.onMouseOverTooltip, true);
this._target.addEventListener('mouseout', this.onMouseLeaveTooltip, true);
document.addEventListener('click', this.handleDocumentClick, true);
['click', 'touchstart'].forEach(event =>
document.addEventListener(event, this.handleDocumentClick, true)
);
}

removeTargetEvents() {
this._target.removeEventListener('mouseover', this.onMouseOverTooltip, true);
this._target.removeEventListener('mouseout', this.onMouseLeaveTooltip, true);
document.removeEventListener('click', this.handleDocumentClick, true);
['click', 'touchstart'].forEach(event =>
document.removeEventListener(event, this.handleDocumentClick, true)
);
}

toggle(e) {
Expand Down

0 comments on commit 9b80d11

Please sign in to comment.