From d7d39b12b2ed4badde277a52db776b63ffb0ae59 Mon Sep 17 00:00:00 2001 From: gmpaliwal07 Date: Sat, 3 May 2025 11:51:00 +0530 Subject: [PATCH] fix: prevent progress bar pause on mobile tap (fixes #1217) --- src/hooks/useToast.ts | 5 +++-- src/utils/isMobile.ts | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 src/utils/isMobile.ts diff --git a/src/hooks/useToast.ts b/src/hooks/useToast.ts index 85c5d1a4..8a4c1ff5 100644 --- a/src/hooks/useToast.ts +++ b/src/hooks/useToast.ts @@ -3,7 +3,7 @@ import { DOMAttributes, useEffect, useRef, useState } from 'react'; import { ToastProps } from '../types'; import { Default, Direction } from '../utils'; import { registerToggle } from '../core/store'; - +import isMobile from '../utils/isMobile' interface Draggable { start: number; delta: number; @@ -84,6 +84,7 @@ export function useToast(props: ToastProps) { if ( e.nativeEvent.type !== 'touchend' && props.pauseOnHover && + !isMobile() && e.clientX >= left && e.clientX <= right && e.clientY >= top && @@ -157,7 +158,7 @@ export function useToast(props: ToastProps) { onPointerUp: onDragTransitionEnd }; - if (autoClose && pauseOnHover) { + if (autoClose && pauseOnHover && !isMobile()) { eventHandlers.onMouseEnter = pauseToast; // progress control is delegated to the container diff --git a/src/utils/isMobile.ts b/src/utils/isMobile.ts new file mode 100644 index 00000000..e7ebbae7 --- /dev/null +++ b/src/utils/isMobile.ts @@ -0,0 +1,6 @@ +const isMobile = (): boolean => { + return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || + ('ontouchstart' in window || navigator.maxTouchPoints > 0);} + + + export default isMobile; \ No newline at end of file