Skip to content

Commit 8375ace

Browse files
committed
fix: touch bug in onDragTransitionEnd, closes #1217
1 parent c0d8186 commit 8375ace

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

src/components/Toast.cy.tsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,48 @@ describe('Toast', () => {
174174
progressBar.isRunning();
175175
});
176176

177+
it('pauses progress bar on mouse pointerup released over the toast', () => {
178+
cy.mount(
179+
<Toast {...REQUIRED_PROPS} autoClose={5000} pauseOnHover>
180+
hello
181+
</Toast>
182+
);
183+
184+
cy.resolveEntranceAnimation();
185+
progressBar.isRunning();
186+
187+
cy.findByRole('alert').then($el => {
188+
const rect = $el[0].getBoundingClientRect();
189+
cy.wrap($el).trigger('pointerup', {
190+
pointerType: 'mouse',
191+
clientX: rect.left + rect.width / 2,
192+
clientY: rect.top + rect.height / 2
193+
});
194+
});
195+
progressBar.isPaused();
196+
});
197+
198+
it('does not pause progress bar on touch pointerup (hover has no meaning for touch)', () => {
199+
cy.mount(
200+
<Toast {...REQUIRED_PROPS} autoClose={5000} pauseOnHover>
201+
hello
202+
</Toast>
203+
);
204+
205+
cy.resolveEntranceAnimation();
206+
progressBar.isRunning();
207+
208+
cy.findByRole('alert').then($el => {
209+
const rect = $el[0].getBoundingClientRect();
210+
cy.wrap($el).trigger('pointerup', {
211+
pointerType: 'touch',
212+
clientX: rect.left + rect.width / 2,
213+
clientY: rect.top + rect.height / 2
214+
});
215+
});
216+
progressBar.isRunning();
217+
});
218+
177219
describe('controller progress bar', () => {
178220
it('set the correct progress value bar disregarding autoClose value', () => {
179221
cy.mount(

src/hooks/useToast.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ export function useToast(props: ToastProps) {
8181
function onDragTransitionEnd(e: React.PointerEvent<HTMLElement>) {
8282
const { top, bottom, left, right } = toastRef.current!.getBoundingClientRect();
8383

84+
// Touch/pen releases don't "hover" — only re-pause on a mouse release over the toast.
8485
if (
85-
e.nativeEvent.type !== 'touchend' &&
86+
e.pointerType === 'mouse' &&
8687
props.pauseOnHover &&
8788
e.clientX >= left &&
8889
e.clientX <= right &&

0 commit comments

Comments
 (0)