|
17 | 17 |
|
18 | 18 | import {disableTextSelection, restoreTextSelection} from './textSelection';
|
19 | 19 | import {DOMAttributes, FocusableElement, PressEvent as IPressEvent, PointerType, PressEvents} from '@react-types/shared';
|
20 |
| -import {focusWithoutScrolling, isMac, isVirtualClick, isVirtualPointerEvent, mergeProps, openLink, useEffectEvent, useGlobalListeners, useSyncRef} from '@react-aria/utils'; |
| 20 | +import {focusWithoutScrolling, getOwnerDocument, getOwnerWindow, isMac, isVirtualClick, isVirtualPointerEvent, mergeProps, openLink, useEffectEvent, useGlobalListeners, useSyncRef} from '@react-aria/utils'; |
21 | 21 | import {PressResponderContext} from './context';
|
22 | 22 | import {RefObject, useContext, useEffect, useMemo, useRef, useState} from 'react';
|
23 | 23 |
|
@@ -271,7 +271,7 @@ export function usePress(props: PressHookProps): PressResult {
|
271 | 271 |
|
272 | 272 | // Focus may move before the key up event, so register the event on the document
|
273 | 273 | // instead of the same element where the key down event occurred.
|
274 |
| - addGlobalListener(document, 'keyup', onKeyUp, false); |
| 274 | + addGlobalListener(getOwnerDocument(e.currentTarget), 'keyup', onKeyUp, false); |
275 | 275 | }
|
276 | 276 |
|
277 | 277 | if (shouldStopPropagation) {
|
@@ -410,9 +410,9 @@ export function usePress(props: PressHookProps): PressResult {
|
410 | 410 |
|
411 | 411 | shouldStopPropagation = triggerPressStart(e, state.pointerType);
|
412 | 412 |
|
413 |
| - addGlobalListener(document, 'pointermove', onPointerMove, false); |
414 |
| - addGlobalListener(document, 'pointerup', onPointerUp, false); |
415 |
| - addGlobalListener(document, 'pointercancel', onPointerCancel, false); |
| 413 | + addGlobalListener(getOwnerDocument(e.currentTarget), 'pointermove', onPointerMove, false); |
| 414 | + addGlobalListener(getOwnerDocument(e.currentTarget), 'pointerup', onPointerUp, false); |
| 415 | + addGlobalListener(getOwnerDocument(e.currentTarget), 'pointercancel', onPointerCancel, false); |
416 | 416 | }
|
417 | 417 |
|
418 | 418 | if (shouldStopPropagation) {
|
@@ -534,7 +534,7 @@ export function usePress(props: PressHookProps): PressResult {
|
534 | 534 | e.stopPropagation();
|
535 | 535 | }
|
536 | 536 |
|
537 |
| - addGlobalListener(document, 'mouseup', onMouseUp, false); |
| 537 | + addGlobalListener(getOwnerDocument(e.currentTarget), 'mouseup', onMouseUp, false); |
538 | 538 | };
|
539 | 539 |
|
540 | 540 | pressProps.onMouseEnter = (e) => {
|
@@ -634,7 +634,7 @@ export function usePress(props: PressHookProps): PressResult {
|
634 | 634 | e.stopPropagation();
|
635 | 635 | }
|
636 | 636 |
|
637 |
| - addGlobalListener(window, 'scroll', onScroll, true); |
| 637 | + addGlobalListener(getOwnerWindow(e.currentTarget), 'scroll', onScroll, true); |
638 | 638 | };
|
639 | 639 |
|
640 | 640 | pressProps.onTouchMove = (e) => {
|
@@ -773,8 +773,8 @@ function isValidKeyboardEvent(event: KeyboardEvent, currentTarget: Element): boo
|
773 | 773 | // "Spacebar" is for IE 11
|
774 | 774 | return (
|
775 | 775 | (key === 'Enter' || key === ' ' || key === 'Spacebar' || code === 'Space') &&
|
776 |
| - !((element instanceof HTMLInputElement && !isValidInputKey(element, key)) || |
777 |
| - element instanceof HTMLTextAreaElement || |
| 776 | + !((element instanceof getOwnerWindow(element).HTMLInputElement && !isValidInputKey(element, key)) || |
| 777 | + element instanceof getOwnerWindow(element).HTMLTextAreaElement || |
778 | 778 | element.isContentEditable) &&
|
779 | 779 | // Links should only trigger with Enter key
|
780 | 780 | !((role === 'link' || (!role && isHTMLAnchorLink(element))) && key !== 'Enter')
|
|
0 commit comments