Skip to content

Fix: Add mobile tap support for CustomTooltip #1031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

M-DEV-1
Copy link
Contributor

@M-DEV-1 M-DEV-1 commented Apr 30, 2025

Notes for Reviewers

This PR fixes #1005

Signed commits

  • Yes, I signed my commits.

Sorry, something went wrong.

Signed-off-by: M-DEV-1 <mahadevankizhakkedathu@gmail.com>
@M-DEV-1
Copy link
Contributor Author

M-DEV-1 commented Apr 30, 2025

Screencast.from.2025-04-30.18-36-57.webm

I tested the above changes, and it works for Modal Footer icon, CustomToolTips, InfoToolTips 👍🏼

@leecalcote leecalcote requested a review from sudhanshutech May 1, 2025 02:54
@leecalcote
Copy link
Member

Thank k you, @M-DEV-1

Copy link
Member

@sudhanshutech sudhanshutech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good change . @M-DEV-1 do you mind taking look to the reviews

@@ -27,6 +27,21 @@ function CustomTooltip({
componentsProps = {},
...props
}: CustomTooltipProps): JSX.Element {
const [isOpen, setIsOpen] = useState(false);

const isTouchDevice = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think isTouchDevice will run on every render. This is not good. Do you mind move it to useMemo .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right. I'll move to useMemo

setIsOpen(true);
};

const handleTouchEnd = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@M-DEV-1 i think this can wrapped with debounce because if user touches frequently within timeout might not be a good behaviour. What do you say @M-DEV-1 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, adding debounce will prevent bad behavior @sudhanshutech

Signed-off-by: M-DEV-1 <mahadevankizhakkedathu@gmail.com>
@M-DEV-1 M-DEV-1 requested a review from sudhanshutech May 2, 2025 08:37

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Comment on lines +32 to +48
const isTouchDevice = useMemo(() => {
return 'ontouchstart' in window || navigator.maxTouchPoints > 0;
}, []);

const handleTouchStart = (event: React.TouchEvent<HTMLDivElement>) => {
event.preventDefault();
setIsOpen(true);
};

const handleTouchEnd = useMemo(
() =>
_.debounce(() => {
setIsOpen(false);
}, 1500),
[setIsOpen]
);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@M-DEV-1 why we required debounce and ontouchstart things

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use this sort of implmentation for mobile view

 <ClickAwayListener onClickAway={handleTooltipClose}>
            <div>
              <Tooltip
                onClose={handleTooltipClose}
                open={open}
                disableFocusListener
                disableHoverListener
                disableTouchListener
                title="Add"
                slotProps={{
                  popper: {
                    disablePortal: true,
                  },
                }}
              >
                <Button onClick={handleTooltipOpen}>Click</Button>
              </Tooltip>
            </div>
          </ClickAwayListener>
         

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added debounce and useMemo because I had implemented isTouchDevice for mobile device detection. I'll use a different approach, one with using MUI's default touch delay and the implementation you have given. Thanks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try to do same thing that implemented in mui tooltip click varient

@amitamrutiya
Copy link
Contributor

@M-DEV-1 any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[UI] InfoToolTip, Modal InfoIcon usability in Mobile View
4 participants