Skip to content

Commit e341033

Browse files
style: temporary fix for tooltip not working on mobile
1 parent fbaad02 commit e341033

File tree

2 files changed

+59
-10
lines changed

2 files changed

+59
-10
lines changed

src/components/Homepage/RankingSelector.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { Link } from "@tanstack/react-router"
2-
import { useMemo } from "react"
2+
import { useContext, useMemo } from "react"
33
import { phaseGroupLabel } from "@/utils/phase"
44
import { numberToRoman } from "@/utils/strings/numbers"
55
import type { PhaseLink } from "@/utils/types/data/phase"
66
import type { School } from "@/utils/types/data/school"
77
import { cn } from "@/utils/ui"
88
import { Tooltip, TooltipContent, TooltipTrigger } from "../ui/tooltip"
9+
import { Button } from "../ui/button"
10+
import MobileContext from "@/contexts/MobileContext"
911

1012
type Props = {
1113
phases: PhaseLink[]
@@ -97,6 +99,7 @@ function groupPhases(phases: PhaseLink[], lang: Language): PhaseGroup[] {
9799
}
98100

99101
export function RankingSelector({ phases, school, year }: Props) {
102+
const { isMobile } = useContext(MobileContext)
100103
const columnsData = useMemo(() => {
101104
return LANGUAGES.map((config) => ({
102105
config,
@@ -120,19 +123,19 @@ export function RankingSelector({ phases, school, year }: Props) {
120123
</div>
121124

122125
{/* Summary */}
123-
<div className="flex gap-1 text-slate-400 text-xs">
126+
<div className="flex gap-4 text-slate-400 text-xs max-sm:flex-col sm:gap-1">
124127
<p className="text-slate-400">
125128
{phases.length} graduatorie disponibili in totale.{" "}
126129
</p>
127-
<Tooltip delayDuration={100}>
128-
<TooltipTrigger className="underline">
130+
<Tooltip delayDuration={100} useTouch={true}>
131+
<TooltipTrigger className="select-none rounded-xl border-dashed underline max-sm:border max-sm:py-3 dark:border-slate-600">
129132
Perché non trovo una graduatoria?
130133
</TooltipTrigger>
131134
<TooltipContent
132-
side="bottom"
133-
className="bg-slate-300 dark:bg-slate-800 dark:text-slate-300"
135+
side={isMobile ? "top" : "bottom"}
136+
className="select-none bg-slate-300 dark:bg-slate-800 dark:text-slate-300"
134137
>
135-
<p className="max-w-120">
138+
<p className="max-w-[80vw] sm:max-w-120">
136139
Il Politecnico ha cambiato negli anni le modalità di pubblicazione
137140
delle graduatorie, oltre a eliminare molto rapidamente i file
138141
grezzi dai server pubblici, rendendo malfunzionante il nostro

src/components/ui/tooltip.tsx

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,58 @@ import * as TooltipPrimitive from "@radix-ui/react-tooltip"
33

44
import { cn } from "@/utils/ui.ts"
55

6-
const TooltipProvider = TooltipPrimitive.Provider
7-
8-
const Tooltip = TooltipPrimitive.Root
6+
const TooltipProvider = React.forwardRef<
7+
HTMLDivElement,
8+
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Provider>
9+
>(({
10+
delayDuration = 0,
11+
...props
12+
}, _ref) => {
13+
return (
14+
<TooltipPrimitive.Provider
15+
data-slot="tooltip-provider"
16+
delayDuration={delayDuration}
17+
{...props}
18+
/>
19+
);
20+
})
921

1022
const TooltipTrigger = TooltipPrimitive.Trigger
1123

24+
const Tooltip = React.forwardRef<
25+
HTMLDivElement,
26+
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Root> & {
27+
useTouch?: boolean;
28+
useTap?: boolean;
29+
}
30+
>(({ useTouch = false, useTap = false, children, ...props }, _ref) => {
31+
const [open, setOpen] = React.useState(false);
32+
33+
const handleTouch = (event: React.TouchEvent | React.MouseEvent) => {
34+
event.persist();
35+
setOpen(true);
36+
};
37+
38+
return (
39+
<TooltipPrimitive.Root
40+
open={open}
41+
onOpenChange={setOpen}
42+
{...props}
43+
>
44+
{React.Children.map(children, (child) => {
45+
if (React.isValidElement(child) && useTouch) {
46+
return React.cloneElement(child as React.ReactElement<any>, {
47+
onTouchStart: handleTouch,
48+
onMouseDown: handleTouch,
49+
});
50+
}
51+
return child;
52+
})}
53+
</TooltipPrimitive.Root>
54+
);
55+
});
56+
Tooltip.displayName = TooltipPrimitive.Root.displayName;
57+
1258
const TooltipContent = React.forwardRef<
1359
React.ElementRef<typeof TooltipPrimitive.Content>,
1460
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>

0 commit comments

Comments
 (0)