Skip to content

Commit 04462ef

Browse files
authored
fix: Delay onPressUp to native onClick event (#8368)
1 parent 26f9102 commit 04462ef

File tree

3 files changed

+8
-15
lines changed

3 files changed

+8
-15
lines changed

packages/@react-aria/interactions/src/usePress.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,9 @@ export function usePress(props: PressHookProps): PressResult {
385385
shouldStopPropagation = stopPressStart && stopPressUp && stopPressEnd;
386386
} else if (state.isPressed && state.pointerType !== 'keyboard') {
387387
let pointerType = state.pointerType || (e.nativeEvent as PointerEvent).pointerType as PointerType || 'virtual';
388-
shouldStopPropagation = triggerPressEnd(createEvent(e.currentTarget, e), pointerType, true);
388+
let stopPressUp = triggerPressUp(createEvent(e.currentTarget, e), pointerType);
389+
let stopPressEnd = triggerPressEnd(createEvent(e.currentTarget, e), pointerType, true);
390+
shouldStopPropagation = stopPressUp && stopPressEnd;
389391
state.isOverTarget = false;
390392
triggerClick(e);
391393
cancel(e);
@@ -507,8 +509,8 @@ export function usePress(props: PressHookProps): PressResult {
507509
return;
508510
}
509511

510-
// Only handle left clicks
511-
if (e.button === 0) {
512+
// Only handle left clicks. If isPressed is true, delay until onClick.
513+
if (e.button === 0 && !state.isPressed) {
512514
triggerPressUp(e, state.pointerType || e.pointerType);
513515
}
514516
};
@@ -651,7 +653,7 @@ export function usePress(props: PressHookProps): PressResult {
651653
return;
652654
}
653655

654-
if (!state.ignoreEmulatedMouseEvents && e.button === 0) {
656+
if (!state.ignoreEmulatedMouseEvents && e.button === 0 && !state.isPressed) {
655657
triggerPressUp(e, state.pointerType || 'mouse');
656658
}
657659
};

packages/@react-aria/interactions/test/usePress.test.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -387,17 +387,6 @@ describe('usePress', function () {
387387
type: 'presschange',
388388
pressed: true
389389
},
390-
{
391-
type: 'pressup',
392-
target: el.parentElement,
393-
pointerType: 'mouse',
394-
ctrlKey: false,
395-
metaKey: false,
396-
shiftKey: false,
397-
altKey: false,
398-
x: 0,
399-
y: 0
400-
},
401390
{
402391
type: 'pressend',
403392
target: el.parentElement,

packages/@react-spectrum/calendar/test/RangeCalendar.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,7 @@ describe('RangeCalendar', () => {
923923

924924
// mouse up should
925925
fireEvent.mouseUp(getByText('10'), {detail: 1});
926+
fireEvent.click(getByText('10'), {detail: 1});
926927
selectedDates = getAllByLabelText('selected', {exact: false});
927928
expect(selectedDates[0].textContent).toBe('10');
928929
expect(selectedDates[selectedDates.length - 1].textContent).toBe('10');
@@ -967,6 +968,7 @@ describe('RangeCalendar', () => {
967968

968969
// mouse up should
969970
fireEvent.mouseUp(getByText('20'), {detail: 1});
971+
fireEvent.click(getByText('20'), {detail: 1});
970972
selectedDates = getAllByLabelText('selected', {exact: false});
971973
expect(selectedDates[0].textContent).toBe('20');
972974
expect(selectedDates[selectedDates.length - 1].textContent).toBe('20');

0 commit comments

Comments
 (0)