Skip to content
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

Tooltip trigger onMobile #86

Open
jozefdrabik opened this issue Feb 15, 2023 · 11 comments
Open

Tooltip trigger onMobile #86

jozefdrabik opened this issue Feb 15, 2023 · 11 comments

Comments

@jozefdrabik
Copy link

I would like to ask how does tooltip work on mobile devices? Because when i tried to use it there it does not work. Is there some solution for this to trigger tooltip when user clicks on trigger?

@jackblackCH
Copy link

Also the tooltip only opens when you hover the border, does not work on the surface: E.g here: https://ui.shadcn.com/docs/primitives/tooltip

@codingcodax
Copy link

I would like to ask how does tooltip work on mobile devices? Because when i tried to use it there it does not work. Is there some solution for this to trigger tooltip when user clicks on trigger?

This is a design decision from Radix UI team, see #955 and the answer by Benoît Grélard.
He said:

This is by design. Tooltips are problematic on touch devices because there is no hover interaction, so if it was on tap it would fight with the general button action, or require 2 taps. That's also why tooltips should just be used generally for extra information that isn't mandatory do use your interface.

In case you "need a tooltip" use a popover instead, as they do in their documentation.

@chadryja
Copy link

chadryja commented Feb 1, 2024

tooltip Not work on mobile view

@0xbid
Copy link

0xbid commented Feb 14, 2024

any progress?

@jozefdrabik
Copy link
Author

@0xbid the only solution is described above. So i use Tooltip for Desktop and for tablet and mobile i just change it to popover. Or u can make some own logic instead of using libraries(made one as well).

@Zwyx
Copy link
Contributor

Zwyx commented Mar 12, 2024

To summarise, they are three components:

Tooltip and Hover Card are only meant to be used on desktop. Popover is meant to be used on desktop and mobile.

This is a design choice by the Radix people. I think it wouldn't make sense to change it here at Shadcn-UI 🤔 so I reckon this issue can be closed.

If you need a hybrid solution, which mounts a popover on mobile and a tooltip by default, have a look at this suggestion 😉

@oxuk85
Copy link

oxuk85 commented Mar 28, 2024

Does it continue to make sense to be locked-in to radix for this scenario? I mean the Radix design choices shouldn't limit the capabilities offered by ShadCn.
Would it make sense to look at a better alternative for this case? Similar as how it was done for the carousel component.
I would say the https://floating-ui.com/ offers a great alternative to build something useful and fully configurable.

@jackblackCH
Copy link

jackblackCH commented Apr 10, 2024

To summarise, they are three components:

Tooltip and Hover Card are only meant to be used on desktop. Popover is meant to be used on desktop and mobile.

This is a design choice by the Radix people. I think it wouldn't make sense to change it here at Shadcn-UI 🤔 so I reckon this issue can be closed.

If you need a hybrid solution, which mounts a popover on mobile and a tooltip by default, have a look at this suggestion 😉

I am surprised, that in 2024, we are still trying to differentiate between "desktop", "touch", "pointer down". When do we realize that everything is hybrid? We will never know if a user is touching only and within the next minute using a pointer device on the same screen? Simple example: I am on an iPad with an iPencil, how should the tooltip behave?

Shouldn't responsive components always work consistently on any "device" with and without "touch"? 🙏

@oxuk85
Copy link

oxuk85 commented Apr 10, 2024

To summarise, they are three components:

Tooltip and Hover Card are only meant to be used on desktop. Popover is meant to be used on desktop and mobile.
This is a design choice by the Radix people. I think it wouldn't make sense to change it here at Shadcn-UI 🤔 so I reckon this issue can be closed.
If you need a hybrid solution, which mounts a popover on mobile and a tooltip by default, have a look at this suggestion 😉

I am surprised, that in 2024, we are still trying to differentiate between "desktop", "touch", "pointer down". When do we realize that everything is hybrid? We will never know if a user is touching only and within the next minute using a pointer device on the same screen? Simple example: I am on an iPad with an iPencil, how should the tooltip behave?

Shouldn't responsive components always work consistently on any "device" with and without "touch"? 🙏

I ended up using @floating-ui/react
I found it was used by Radix in a component.

Here is the demo I found and used as the template for my own re-usable component. It works great on touch devices.

https://codesandbox.io/p/sandbox/xenodochial-grass-js3bo9?file=%2Fsrc%2FTooltip.tsx

In case you are curious here is a gist with the component I build:
https://gist.github.com/oxuk85/34e6969d6ec3971f4561d69f26571bb4

@techlism
Copy link

techlism commented Apr 12, 2024

'use client'
import { Button } from "@/components/ui/button"
import {
  Tooltip,
  TooltipContent,
  TooltipProvider,
  TooltipTrigger,
} from "@/components/ui/tooltip"
import { InfoIcon } from "lucide-react"
import { useState } from "react"
export default function InfoTooltip({information}:{information : string}) {
    const [open, setOpen] = useState(false);
    function handleOpenClose(){
        if(open){
            setOpen(false);
        }
        else{
            setOpen(true);
            setTimeout(() => {
                setOpen(false);
            }, 2500);
        }
    }
    return (
        <>
        <TooltipProvider>
            <Tooltip>
                <TooltipTrigger asChild className="collapse lg:visible xl:visible 2xl:visible">
                    <InfoIcon className="opacity-15 dark:opacity-50 hover:opacity-80 ml-2"/>
                </TooltipTrigger>
                <TooltipContent className="max-w-[40vw] p-2">
                    <p>{information}</p>
                </TooltipContent>
            </Tooltip>
        </TooltipProvider>
        {open && <p className="absolute z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2">
            {information}
        </p>}
        <Button onClick={handleOpenClose} className="bg-transparent lg:collapse xl:collapse 2xl:collapse m-2" variant={'ghost'}><InfoIcon className="opacity-15 dark:opacity-50 hover:opacity-80"/></Button>
        </>
    )
}

This is what I have settled for. I know not the most elegant but mostly works.

@alberduris
Copy link

In case you "need a tooltip" use a popover instead, as they do in their documentation.

This is the correct solution, and it works like a charm. But honestly I don't understand the point of having both the <Tooltip> and the <Popover>. It seems the <Tooltip> can be deprecated in favor of the <Popover>.

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

No branches or pull requests

9 participants