Skip to content

Commit 7a61d20

Browse files
committed
Fix tag click to copy
1 parent ef1a102 commit 7a61d20

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/components/result/GenericResultViewTag.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ReactNode, useCallback, useMemo } from "react"
1+
import { MouseEvent, ReactNode, useCallback, useMemo } from "react"
22
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"
33
import { Badge } from "@/components/ui/badge"
44
import { SearchResult } from "@elastic/search-ui"
@@ -21,19 +21,28 @@ export function GenericResultViewTag({ field, result, icon, label, valueMapper }
2121
else return value
2222
}, [field, result, valueMapper])
2323

24-
const [_, copy] = useCopyToClipboard()
24+
const [, copy] = useCopyToClipboard()
25+
26+
const copyTagValue = useCallback(
27+
(e: MouseEvent<HTMLDivElement>) => {
28+
if ("innerText" in e.target && typeof e.target.innerText === "string") {
29+
copy(e.target.innerText).then()
30+
} else console.warn("Failed to copy innerText of", e.target)
31+
},
32+
[copy]
33+
)
2534

2635
const base = useCallback(
2736
(value: string) => {
2837
return (
29-
<Badge variant="secondary" className="rfs-truncate" onClick={() => copy(value)}>
38+
<Badge variant="secondary" className="rfs-truncate" onClick={copyTagValue}>
3039
<span className="rfs-flex rfs-truncate">
3140
{icon} {value}
3241
</span>
3342
</Badge>
3443
)
3544
},
36-
[copy, icon]
45+
[copyTagValue, icon]
3746
)
3847

3948
if (!label) return base(value)

0 commit comments

Comments
 (0)