-
Notifications
You must be signed in to change notification settings - Fork 864
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] Tooltip component doesn't work on iOS Safari (14.4) #955
Comments
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. |
I wonder if it is worth looking into this though. Material UI provide a "touch" option for this which appears to be a longpress: https://mui.com/components/tooltips/#triggers Perhaps we can do something similar? |
Tooltips aren't usually just superfluous information, they generally important information just hidden away until required. I do typically see the hover ability on desktop replaced with a tap action on mobile. I mean, here, on your own documentation page you've made the tooltips accessible on mobile devices. Why would you do that if it wasn't important information? I'd suggest one or more of the following actions:
|
I personally don't think that makes much sense (for the reasons highlighted below). A tooltip is usually used to provide more info about a trigger that already does something. How would you know you can long press it?
That is not a tooltip, that's a popover, the interaction for those is pointer down. So it looks like perhaps we need to emphasize more in the docs the differences between the patterns? |
AHHHH I see. That makes so much more sense now. I guess I didn't think about the popover being used in that way, I figured it was always for more complex use cases. Thanks for the clarification. I think perhaps a note on the Tooltip page referencing the Popover might help silly people like me who generalise what a Tooltip is? |
True. Plus, I just realised that the WAI ARIA tooltip docs (wip) suggest they're intended for focus/hover only.
Agreed. We have spoken about having a "When to use" section for the components as these patterns can appear to overlap, it's all a bit confusing. I'll let the team know that we've had another request for this 👍 EDIT: I created a new issue on the website repo instead radix-ui/website#272 |
I found a naive way to make Tooltip working on both pointing device and touch device. In my use case, it's just an info icon like your website, it's not a general button, so there will be no event conflict. Not sure any downside of this solution. https://codesandbox.io/s/smoosh-forest-553n1q?file=/App.js And it let me thinking, can we add an option to make Tooltip working on both pointing device and touch device, but it can not be a general button, so we can avoid event conflict? 🤔 |
You are a god |
@benoitgrelard Sorry to ping you, but what's your thoughts? |
Hey @yangmingshan,
In that case, a
No that's not possible, a tooltip is here to display a "tip" regarding a given "tool", there should always be an action behind this, so it's not possible to avoid event conflicts. |
@benoitgrelard hi! sorry for ping, but what else I need opens popover on hover event on desktop and on click event on mobile devices, what I must use popover or tooltip? |
@kaptn3 If you want an interaction that works on mobile (touch) then it would have to be popover. That said, it doesn't open on hover on desktop as that's not the intended behaviour of a popover, so you'd have to override that behaviour if that's what you wanted, I'd warn you against it though as that's not really natural as focus moves into the popover when it opens for accessibility reasons. |
@benoitgrelard got it, thank you! |
@benoitgrelard I think that the convention for mobile is that tooltips appear... |
There are no such convention in the existing accessibility guidelines as touch is problematic. This is because a tooltip is a "tip" for a "tool", that tool is an interactive element (99% of the time should be a Hopefully this makes sense why they are ignored on touch. See here where it specifically only mentions hover and focus: https://www.w3.org/WAI/ARIA/apg/patterns/tooltip/ |
Instead of using the clue list at the bottom, click on an answered clue to show a popover with its answer. Radix popover: https://www.radix-ui.com/docs/primitives/components/popover Use a popover instead of a tooltip because Radix tooltips do not show up on mobile (no hover events). See discussion: radix-ui/primitives#955 To make clue button a popover trigger, pass a ref with React.forwardRef like so: - radix-ui/primitives#953 - https://buildui.com/videos/do-your-react-components-compose
Unfortunately Radix tooltips do not work on mobile (no hover events). See discussion: radix-ui/primitives#955
Instead of using the clue list at the bottom, click on an answered clue to show a popover with its answer. Radix popover: https://www.radix-ui.com/docs/primitives/components/popover Use a popover instead of a tooltip because Radix tooltips do not show up on mobile (no hover events). See discussion: radix-ui/primitives#955 To make clue button a popover trigger, pass a ref with React.forwardRef like so: - radix-ui/primitives#953 - https://buildui.com/videos/do-your-react-components-compose
Unfortunately Radix tooltips do not work on mobile (no hover events). See discussion: radix-ui/primitives#955
Unfortunately Radix tooltips do not work on mobile (no hover events). See discussion: radix-ui/primitives#955
Instead of using the clue list at the bottom, click on an answered clue to show a popover with its answer. Radix popover: https://www.radix-ui.com/docs/primitives/components/popover Use a popover instead of a tooltip because Radix tooltips do not show up on mobile (no hover events). See discussion: radix-ui/primitives#955 To make clue button a popover trigger, pass a ref with React.forwardRef like so: - radix-ui/primitives#953 - https://buildui.com/videos/do-your-react-components-compose
Unfortunately Radix tooltips do not work on mobile (no hover events). See discussion: radix-ui/primitives#955
I've came across this issue as well and ended up modifying the Popover component to fit my requirements. When using the exported components, the Popover is touchable and hoverable.
|
Simple implementation for both - mobile and desktop:
|
To add to solution above, there was still an issue where on mobile I needed to click twice to get the tooltip, because Here is the final code:
|
How would this work for multiple tooltips tho? |
for those using shadcn: "use client";
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
import * as React from "react";
import { cn } from "@/lib/utils";
const TooltipProvider = TooltipPrimitive.Provider;
const Tooltip = ({
alwaysOpen,
children,
}: {
alwaysOpen?: boolean;
children: React.ReactNode;
}) => {
const [open, setOpen] = React.useState(false);
return (
<TooltipPrimitive.Root open={alwaysOpen || open} onOpenChange={setOpen}>
<div
onClick={(e) => {
setOpen(true);
}}
onKeyUp={(e) => {
if (e.key === "Enter" || e.key === " ") {
setOpen(true);
}
}}
onKeyDown={(e) => {
if (e.key === "Enter" || e.key === " ") {
setOpen(true);
}
}}
>
{children}
</div>
</TooltipPrimitive.Root>
);
};
const TooltipTrigger = ({
onClick,
onFocus,
onBlur,
onKeyUp,
onKeyDown,
children,
}: {
onClick?: React.MouseEventHandler<HTMLDivElement>;
onFocus?: React.FocusEventHandler<HTMLDivElement>;
onBlur?: React.FocusEventHandler<HTMLDivElement>;
onKeyUp?: React.KeyboardEventHandler<HTMLDivElement>;
onKeyDown?: React.KeyboardEventHandler<HTMLDivElement>;
children: React.ReactNode;
}) => {
const [open, setOpen] = React.useState(false);
const handleKeyEvents = (event: React.KeyboardEvent<HTMLDivElement>) => {
if (onKeyUp) onKeyUp(event);
if (onKeyDown) onKeyDown(event);
if (event.key === "Enter" || event.key === " ") {
setOpen((prevOpen) => !prevOpen);
}
};
return (
<TooltipPrimitive.Trigger asChild>
<div
tabIndex={0}
role="button"
onClick={(e) => {
setOpen((prevOpen) => !prevOpen);
if (onClick) onClick(e);
}}
onFocus={(e) => {
setTimeout(() => setOpen(true), 0);
if (onFocus) onFocus(e);
}}
onBlur={(e) => {
setOpen(false);
if (onBlur) onBlur(e);
}}
onKeyUp={handleKeyEvents}
onKeyDown={handleKeyEvents}
>
{children}
</div>
</TooltipPrimitive.Trigger>
);
};
const TooltipContent = React.forwardRef<
React.ElementRef<typeof TooltipPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
>(({ className, sideOffset = 4, ...props }, ref) => (
<TooltipPrimitive.Content
ref={ref}
sideOffset={sideOffset}
className={cn(
"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",
className,
)}
{...props}
/>
));
TooltipContent.displayName = TooltipPrimitive.Content.displayName;
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }; |
@benoitgrelard I feel like the stance you're arguing from on this is a bit strained and silly. Of course the original tooltip was not considering touch devices—it was invented in the 90s. UI design has evolved a lot since then, as have input modalities. While I think it's reasonable for someone to have a tooltip on a button intending to be clicked, that's not the most common use case for them today. Rather than pretending you'd have to boil the ocean (serve every single use case ever), just add the expected behavior to show the tooltip on touch-start and hide it when the user clicks outside as the default. It (still) won't work when someone has an interactive button, but that's fine—at least it'll work in the majority of use cases that have produced a dozen clumsy workarounds (and likely sent plenty of potential Radix UI users searching for another library). Pragmatism > Perfectionism |
# [SRBT-349] Fix: Tooltip Not Appearing for "Add Section Title" **Changes** - Refactored the SectionTitleIcon to be wrapped in a `div` instead of an `svg`. I also refactored the Tooltip Trigger for section titles to be a button. Apparently, Tooltips can only to appear on [buttons](radix-ui/primitives#955 (comment)), or elements that require a click / pointer-down interaction – from what I've gathered on the documentation beyond this specific GitHub issue. # Screenshots <img width="487" alt="Screenshot 2024-12-03 at 8 57 21 AM" src="https://github.com/user-attachments/assets/a1a38d3f-075c-46b7-9064-a0b581efcf5a"> --------- Co-authored-by: Audrey Ostrom <[email protected]>
Bug report
The Tooltip component isn't working on iOS Safari.
Current Behavior
Tapping on a tooltip component doesn't show the content
Expected behavior
Content shows when tapping a Tooltip component
Reproducible example
https://www.radix-ui.com/docs/primitives/components/tooltip
Suggested solution
Content should show on tap events
Your environment
Below is my env, but it's also not working on whatever your website env is.
The text was updated successfully, but these errors were encountered: