Skip to content

Commit 9b80d11

Browse files
committed
fix(popper): account for touchstart
fixes dropdowns, tooltips, and popovers not triggers on touch events Closes #456 #458
1 parent 9b32cee commit 9b80d11

3 files changed

Lines changed: 18 additions & 6 deletions

File tree

src/Dropdown.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,15 @@ class Dropdown extends React.Component {
6666
}
6767

6868
addEvents() {
69-
document.addEventListener('click', this.handleDocumentClick, true);
69+
['click', 'touchstart'].forEach(event =>
70+
document.addEventListener(event, this.handleDocumentClick, true)
71+
);
7072
}
7173

7274
removeEvents() {
73-
document.removeEventListener('click', this.handleDocumentClick, true);
75+
['click', 'touchstart'].forEach(event =>
76+
document.removeEventListener(event, this.handleDocumentClick, true)
77+
);
7478
}
7579

7680
handleDocumentClick(e) {

src/Popover.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,15 @@ class Popover extends React.Component {
121121
}
122122

123123
addTargetEvents() {
124-
document.addEventListener('click', this.handleDocumentClick, true);
124+
['click', 'touchstart'].forEach(event =>
125+
document.addEventListener(event, this.handleDocumentClick, true)
126+
);
125127
}
126128

127129
removeTargetEvents() {
128-
document.removeEventListener('click', this.handleDocumentClick, true);
130+
['click', 'touchstart'].forEach(event =>
131+
document.removeEventListener(event, this.handleDocumentClick, true)
132+
);
129133
}
130134

131135
toggle(e) {

src/Tooltip.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,17 @@ class Tooltip extends React.Component {
144144
addTargetEvents() {
145145
this._target.addEventListener('mouseover', this.onMouseOverTooltip, true);
146146
this._target.addEventListener('mouseout', this.onMouseLeaveTooltip, true);
147-
document.addEventListener('click', this.handleDocumentClick, true);
147+
['click', 'touchstart'].forEach(event =>
148+
document.addEventListener(event, this.handleDocumentClick, true)
149+
);
148150
}
149151

150152
removeTargetEvents() {
151153
this._target.removeEventListener('mouseover', this.onMouseOverTooltip, true);
152154
this._target.removeEventListener('mouseout', this.onMouseLeaveTooltip, true);
153-
document.removeEventListener('click', this.handleDocumentClick, true);
155+
['click', 'touchstart'].forEach(event =>
156+
document.removeEventListener(event, this.handleDocumentClick, true)
157+
);
154158
}
155159

156160
toggle(e) {

0 commit comments

Comments
 (0)