Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/@react-aria/interactions/src/usePress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,13 @@ export function usePress(props: PressHookProps): PressResult {
// This enables onPointerLeave and onPointerEnter to fire.
let target = getEventTarget(e.nativeEvent);
if ('releasePointerCapture' in target) {
target.releasePointerCapture(e.pointerId);
if ('hasPointerCapture' in target) {
if (target.hasPointerCapture(e.pointerId)) {
target.releasePointerCapture(e.pointerId);
}
} else {
(target as Element).releasePointerCapture(e.pointerId);
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/@react-aria/interactions/test/usePress.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,9 @@ describe('usePress', function () {

let el = res.getByText('test');
el.releasePointerCapture = jest.fn();
el.hasPointerCapture = jest.fn().mockReturnValue(true);
fireEvent(el, pointerEvent('pointerdown', {pointerId: 1, pointerType: 'mouse', clientX: 0, clientY: 0}));
expect(el.hasPointerCapture).toHaveBeenCalled();
expect(el.releasePointerCapture).toHaveBeenCalled();
// react listens for pointerout and pointerover instead of pointerleave and pointerenter...
fireEvent(el, pointerEvent('pointerout', {pointerId: 1, pointerType: 'mouse', clientX: 100, clientY: 100}));
Expand Down Expand Up @@ -4011,7 +4013,9 @@ describe('usePress', function () {

const el = shadowRoot.getElementById('testElement');
el.releasePointerCapture = jest.fn();
el.hasPointerCapture = jest.fn().mockReturnValue(true);
fireEvent(el, pointerEvent('pointerdown', {pointerId: 1, pointerType: 'mouse', clientX: 0, clientY: 0}));
expect(el.hasPointerCapture).toHaveBeenCalled();
expect(el.releasePointerCapture).toHaveBeenCalled();
// react listens for pointerout and pointerover instead of pointerleave and pointerenter...
fireEvent(el, pointerEvent('pointerout', {pointerId: 1, pointerType: 'mouse', clientX: 100, clientY: 100}));
Expand Down