Skip to content

Commit

Permalink
Fix hover scrubber error in Firefox (#5243)
Browse files Browse the repository at this point in the history
  • Loading branch information
WithoutPants authored Sep 11, 2024
1 parent 5407596 commit b897de3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions ui/v2.5/src/components/Shared/HoverScrubber.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React, { useMemo } from "react";
import cx from "classnames";

// #5231: TouchEvent is not defined on all browsers
const touchEventDefined = window.TouchEvent !== undefined;

interface IHoverScrubber {
totalSprites: number;
activeIndex: number | undefined;
Expand All @@ -24,7 +27,7 @@ export const HoverScrubber: React.FC<IHoverScrubber> = ({
let x = 0;
if (e.nativeEvent instanceof MouseEvent) {
x = e.nativeEvent.offsetX;
} else if (e.nativeEvent instanceof TouchEvent) {
} else if (touchEventDefined && e.nativeEvent instanceof TouchEvent) {
x =
e.nativeEvent.touches[0].clientX -
e.currentTarget.getBoundingClientRect().x;
Expand All @@ -47,7 +50,8 @@ export const HoverScrubber: React.FC<IHoverScrubber> = ({

if (
(e instanceof MouseEvent && relatedTarget !== e.target) ||
(e instanceof TouchEvent &&
(touchEventDefined &&
e instanceof TouchEvent &&
document.elementFromPoint(e.touches[0].clientX, e.touches[0].clientY))
)
return;
Expand All @@ -70,7 +74,8 @@ export const HoverScrubber: React.FC<IHoverScrubber> = ({

if (
(e instanceof MouseEvent && relatedTarget !== e.target) ||
(e instanceof TouchEvent &&
(touchEventDefined &&
e instanceof TouchEvent &&
document.elementFromPoint(e.touches[0].clientX, e.touches[0].clientY))
)
return;
Expand Down

0 comments on commit b897de3

Please sign in to comment.