Skip to content

Commit 0e25264

Browse files
committed
fix erratic behaviour on iOS
1 parent 71de794 commit 0e25264

File tree

5 files changed

+366
-256
lines changed

5 files changed

+366
-256
lines changed

.size-snapshot.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
{
22
"dist/cjs/react-popper-tooltip.js": {
3-
"bundled": 13954,
4-
"minified": 7653,
5-
"gzipped": 2137
3+
"bundled": 14340,
4+
"minified": 7879,
5+
"gzipped": 2190
66
},
77
"dist/esm/react-popper-tooltip.js": {
8-
"bundled": 13902,
9-
"minified": 7620,
10-
"gzipped": 2132,
8+
"bundled": 14288,
9+
"minified": 7846,
10+
"gzipped": 2185,
1111
"treeshaked": {
1212
"rollup": {
13-
"code": 7059,
13+
"code": 7271,
1414
"import_statements": 331
1515
},
1616
"webpack": {
17-
"code": 8293
17+
"code": 8505
1818
}
1919
}
2020
}

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-popper-tooltip",
3-
"version": "2.7.2",
3+
"version": "2.7.3",
44
"description": "React tooltip library built around react-popper",
55
"homepage": "https://mohsinulhaq.github.io/react-popper-tooltip/",
66
"repository": {
@@ -56,7 +56,7 @@
5656
"@babel/plugin-transform-runtime": "^7.2.0",
5757
"@babel/preset-env": "^7.2.3",
5858
"@babel/preset-react": "^7.0.0",
59-
"@types/jest": "^23.3.10",
59+
"@types/jest": "^23.3.12",
6060
"@types/react": "^16.7.18",
6161
"@types/react-dom": "^16.0.11",
6262
"babel-core": "^7.0.0-bridge.0",
@@ -66,23 +66,23 @@
6666
"docz": "^0.13.7",
6767
"docz-plugin-css": "^0.11.0",
6868
"docz-theme-default": "^0.13.7",
69-
"eslint": "^5.11.1",
69+
"eslint": "^5.12.0",
7070
"eslint-config-prettier": "^3.3.0",
71-
"eslint-plugin-jest": "^22.1.2",
71+
"eslint-plugin-jest": "^22.1.3",
7272
"eslint-plugin-jsx-a11y": "^6.1.2",
7373
"eslint-plugin-prettier": "^3.0.1",
74-
"eslint-plugin-react": "^7.12.0",
74+
"eslint-plugin-react": "^7.12.3",
7575
"gh-pages": "^2.0.1",
7676
"jest": "^23.6.0",
7777
"pre-commit": "^1.2.2",
7878
"prettier": "^1.15.3",
7979
"prop-types": "^15.6.2",
8080
"react": "^16.7.0",
8181
"react-dom": "^16.7.0",
82-
"react-testing-library": "^5.4.2",
83-
"rimraf": "^2.6.2",
82+
"react-testing-library": "^5.4.4",
83+
"rimraf": "^2.6.3",
8484
"rollup": "^0.68.2",
85-
"rollup-plugin-babel": "^4.1.0",
85+
"rollup-plugin-babel": "^4.3.0",
8686
"rollup-plugin-size-snapshot": "^0.7.0"
8787
}
8888
}

src/Tooltip.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,18 @@ export default class Tooltip extends Component {
6262
}
6363
};
6464

65-
_addOutsideClickHandler = () =>
66-
document.addEventListener('click', this._handleOutsideClick);
65+
_addOutsideClickHandler = () => {
66+
if ('ontouchend' in window) {
67+
document.addEventListener('touchend', this._handleOutsideClick);
68+
} else {
69+
document.addEventListener('click', this._handleOutsideClick);
70+
}
71+
};
6772

68-
_removeOutsideClickHandler = () =>
73+
_removeOutsideClickHandler = () => {
74+
document.removeEventListener('touchend', this._handleOutsideClick);
6975
document.removeEventListener('click', this._handleOutsideClick);
76+
};
7077

7178
_addOutsideRightClickHandler = () =>
7279
document.addEventListener('contextmenu', this._handleOutsideRightClick);

src/TooltipTrigger.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,18 @@ export default class TooltipTrigger extends Component {
185185
const isClickTriggered = this.props.trigger === 'click';
186186
const isHoverTriggered = this.props.trigger === 'hover';
187187
const isRightClickTriggered = this.props.trigger === 'right-click';
188+
const isTouchEnabled = canUseDOM() && 'ontouchend' in window;
188189

189190
return {
190191
...props,
191-
onClick: callAll(isClickTriggered && this._clickToggle, props.onClick),
192+
onTouchEnd: callAll(
193+
isClickTriggered && isTouchEnabled && this._clickToggle,
194+
props.onTouchEnd
195+
),
196+
onClick: callAll(
197+
isClickTriggered && !isTouchEnabled && this._clickToggle,
198+
props.onClick
199+
),
192200
onContextMenu: callAll(
193201
isRightClickTriggered && this._contextMenuToggle,
194202
props.onContextMenu

0 commit comments

Comments
 (0)