Skip to content

Commit ea18550

Browse files
committed
add: touch support for CustomTooltip on mobile devices
Signed-off-by: M-DEV-1 <mahadevankizhakkedathu@gmail.com>
1 parent d43e72c commit ea18550

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

src/custom/CustomTooltip/customTooltip.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import _ from 'lodash';
2-
import React from 'react';
2+
import React, { useState } from 'react';
33
import { Tooltip, TooltipProps } from '../../base';
44
import { WHITE } from '../../theme';
55
import { RenderMarkdownTooltip } from '../Markdown';
@@ -27,6 +27,21 @@ function CustomTooltip({
2727
componentsProps = {},
2828
...props
2929
}: CustomTooltipProps): JSX.Element {
30+
const [isOpen, setIsOpen] = useState(false);
31+
32+
const isTouchDevice = () => {
33+
return 'ontouchstart' in window || navigator.maxTouchPoints > 0;
34+
};
35+
36+
const handleTouchStart = (event: React.TouchEvent<HTMLDivElement>) => {
37+
event.preventDefault();
38+
setIsOpen(true);
39+
};
40+
41+
const handleTouchEnd = () => {
42+
setTimeout(() => setIsOpen(false), 1500);
43+
};
44+
3045
return (
3146
<Tooltip
3247
componentsProps={_.merge(
@@ -57,13 +72,16 @@ function CustomTooltip({
5772
},
5873
componentsProps
5974
)}
75+
open={isTouchDevice() ? isOpen : undefined}
6076
title={typeof title === 'string' ? <RenderMarkdownTooltip content={title} /> : title}
6177
placement={placement}
6278
arrow
6379
onClick={onClick}
6480
{...props}
6581
>
66-
{children}
82+
<div onTouchStart={handleTouchStart} onTouchEnd={handleTouchEnd}>
83+
{children}
84+
</div>
6785
</Tooltip>
6886
);
6987
}

0 commit comments

Comments
 (0)