@react-aria/interactions 3.19.0 → 3.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/import.mjs +110 -71
- package/dist/main.js +110 -69
- package/dist/main.js.map +1 -1
- package/dist/module.js +110 -71
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +6 -6
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/DOMPropsContext.ts +1 -1
- package/src/DOMPropsResponder.tsx +5 -3
- package/src/PressResponder.tsx +7 -5
- package/src/Pressable.tsx +4 -5
- package/src/context.ts +1 -1
- package/src/createEventHandler.ts +2 -2
- package/src/textSelection.ts +10 -6
- package/src/useFocusVisible.ts +22 -6
- package/src/useFocusWithin.ts +3 -2
- package/src/useInteractOutside.ts +21 -18
- package/src/useLongPress.ts +3 -3
- package/src/useMove.ts +4 -4
- package/src/usePress.ts +50 -40
- package/src/useScrollWheel.ts +1 -1
- package/src/utils.ts +4 -4
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DOMAttributes, PressEvents, FocusableElement, FocusEvents, HoverEvents, KeyboardEvents, MoveEvents, ScrollEvents, LongPressEvent } from "@react-types/shared";
|
|
2
|
-
import React, { RefObject, ReactElement, ReactNode, FocusEvent
|
|
2
|
+
import React, { RefObject, ReactElement, ReactNode, FocusEvent } from "react";
|
|
3
3
|
export interface PressProps extends PressEvents {
|
|
4
4
|
/** Whether the target is in a controlled press state (e.g. an overlay it triggers is open). */
|
|
5
5
|
isPressed?: boolean;
|
|
@@ -36,7 +36,7 @@ export function usePress(props: PressHookProps): PressResult;
|
|
|
36
36
|
interface PressableProps extends PressProps {
|
|
37
37
|
children: ReactElement<DOMAttributes, string>;
|
|
38
38
|
}
|
|
39
|
-
export const Pressable: React.ForwardRefExoticComponent<PressableProps & React.RefAttributes<
|
|
39
|
+
export const Pressable: React.ForwardRefExoticComponent<PressableProps & React.RefAttributes<HTMLElement>>;
|
|
40
40
|
interface PressResponderProps extends PressProps {
|
|
41
41
|
children: ReactNode;
|
|
42
42
|
}
|
|
@@ -73,12 +73,12 @@ export interface FocusVisibleResult {
|
|
|
73
73
|
* If true, keyboard focus is visible.
|
|
74
74
|
*/
|
|
75
75
|
export function isFocusVisible(): boolean;
|
|
76
|
-
export function getInteractionModality(): Modality;
|
|
76
|
+
export function getInteractionModality(): Modality | null;
|
|
77
77
|
export function setInteractionModality(modality: Modality): void;
|
|
78
78
|
/**
|
|
79
79
|
* Keeps state of the current modality.
|
|
80
80
|
*/
|
|
81
|
-
export function useInteractionModality(): Modality;
|
|
81
|
+
export function useInteractionModality(): Modality | null;
|
|
82
82
|
/**
|
|
83
83
|
* Manages focus visible state for the page, and subscribes individual components for updates.
|
|
84
84
|
*/
|
|
@@ -123,8 +123,8 @@ export interface HoverResult {
|
|
|
123
123
|
export function useHover(props: HoverProps): HoverResult;
|
|
124
124
|
export interface InteractOutsideProps {
|
|
125
125
|
ref: RefObject<Element>;
|
|
126
|
-
onInteractOutside?: (e:
|
|
127
|
-
onInteractOutsideStart?: (e:
|
|
126
|
+
onInteractOutside?: (e: PointerEvent) => void;
|
|
127
|
+
onInteractOutsideStart?: (e: PointerEvent) => void;
|
|
128
128
|
/** Whether the interact outside events should be disabled. */
|
|
129
129
|
isDisabled?: boolean;
|
|
130
130
|
}
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;AEuBA,2BAA4B,SAAQ,WAAW;IAC7C,+FAA+F;IAC/F,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,mDAAmD;IACnD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,4DAA4D;IAC5D,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;;;OAKG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC,yEAAyE;IACzE,yBAAyB,CAAC,EAAE,OAAO,CAAA;CACpC;AAED,+BAAgC,SAAQ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AAK,EAAE,gBAAgB,EAAE,GAAG,EAAE,UAAU,WAAW,CAAC,GAAG,IAAI,CAkBzF;ACvBD;IACE,oDAAoD;IACpD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,mEAAmE;IACnE,gBAAgB,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc,KAAK,IAAI,CAAC;IAC/C;;;OAGG;IACH,cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc,KAAK,IAAI,CAAC;IAC7C;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc,KAAK,IAAI,CAAC;IAC1C;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,wBAAwB,CAAC,EAAE,MAAM,CAAA;CAClC;AAED;IACE,6CAA6C;IAC7C,cAAc,EAAE,aAAa,CAAA;CAC9B;AAID;;;GAGG;AACH,6BAA6B,KAAK,EAAE,cAAc,GAAG,eAAe,CAyEnE;ACzFD,YAAY,EAAC,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAC,MAAM,qBAAqB,CAAC","sources":["packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/textSelection.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/context.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/usePress.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/Pressable.tsx","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/PressResponder.tsx","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/utils.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useFocus.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useFocusVisible.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useFocusWithin.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useHover.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useInteractOutside.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/createEventHandler.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useKeyboard.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useMove.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useScrollWheel.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useLongPress.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/index.ts","packages/@react-aria/interactions/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport {Pressable} from './Pressable';\nexport {PressResponder, ClearPressResponder} from './PressResponder';\nexport {useFocus} from './useFocus';\nexport {\n isFocusVisible,\n getInteractionModality,\n setInteractionModality,\n useInteractionModality,\n useFocusVisible,\n useFocusVisibleListener\n} from './useFocusVisible';\nexport {useFocusWithin} from './useFocusWithin';\nexport {useHover} from './useHover';\nexport {useInteractOutside} from './useInteractOutside';\nexport {useKeyboard} from './useKeyboard';\nexport {useMove} from './useMove';\nexport {usePress} from './usePress';\nexport {useScrollWheel} from './useScrollWheel';\nexport {useLongPress} from './useLongPress';\n\nexport type {FocusProps, FocusResult} from './useFocus';\nexport type {FocusVisibleHandler, FocusVisibleProps, FocusVisibleResult, Modality} from './useFocusVisible';\nexport type {FocusWithinProps, FocusWithinResult} from './useFocusWithin';\nexport type {HoverProps, HoverResult} from './useHover';\nexport type {InteractOutsideProps} from './useInteractOutside';\nexport type {KeyboardProps, KeyboardResult} from './useKeyboard';\nexport type {PressProps, PressHookProps, PressResult} from './usePress';\nexport type {PressEvent, PressEvents, MoveStartEvent, MoveMoveEvent, MoveEndEvent, MoveEvents, HoverEvent, HoverEvents, FocusEvents, KeyboardEvents} from '@react-types/shared';\nexport type {MoveResult} from './useMove';\nexport type {LongPressProps, LongPressResult} from './useLongPress';\nexport type {ScrollWheelProps} from './useScrollWheel';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/interactions",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.20.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-aria/ssr": "^3.
|
|
26
|
-
"@react-aria/utils": "^3.
|
|
27
|
-
"@react-types/shared": "^3.
|
|
25
|
+
"@react-aria/ssr": "^3.9.0",
|
|
26
|
+
"@react-aria/utils": "^3.22.0",
|
|
27
|
+
"@react-types/shared": "^3.22.0",
|
|
28
28
|
"@swc/helpers": "^0.5.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "9ce2f674eab2cc8912800d3162dcf00a1ce94274"
|
|
37
37
|
}
|
package/src/DOMPropsContext.ts
CHANGED
|
@@ -23,7 +23,7 @@ interface IDOMPropsResponderContext extends DOMAttributes {
|
|
|
23
23
|
ref?: MutableRefObject<Element>
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export const DOMPropsResponderContext = React.createContext<IDOMPropsResponderContext>(null);
|
|
26
|
+
export const DOMPropsResponderContext = React.createContext<IDOMPropsResponderContext | null>(null);
|
|
27
27
|
|
|
28
28
|
export function useDOMPropsResponderContext(props: DOMPropsResponderProps): DOMPropsResponderProps {
|
|
29
29
|
// Consume context from <DOMPropsResponder> and merge with props.
|
|
@@ -12,17 +12,19 @@
|
|
|
12
12
|
|
|
13
13
|
import {DOMPropsResponderContext} from './DOMPropsContext';
|
|
14
14
|
import {HoverProps} from './useHover';
|
|
15
|
-
import React, {
|
|
15
|
+
import React, {ForwardedRef, ReactNode, useEffect, useRef} from 'react';
|
|
16
|
+
import {useObjectRef} from '@react-aria/utils';
|
|
16
17
|
|
|
17
18
|
interface DOMPropsResponderProps extends HoverProps {
|
|
18
19
|
children: ReactNode
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
export const DOMPropsResponder = React.forwardRef(({children, ...props}: DOMPropsResponderProps, ref:
|
|
22
|
+
export const DOMPropsResponder = React.forwardRef(({children, ...props}: DOMPropsResponderProps, ref: ForwardedRef<Element>) => {
|
|
22
23
|
let isRegistered = useRef(false);
|
|
24
|
+
let objRef = useObjectRef(ref);
|
|
23
25
|
let context = {
|
|
24
26
|
...props,
|
|
25
|
-
ref,
|
|
27
|
+
ref: objRef,
|
|
26
28
|
register() {
|
|
27
29
|
isRegistered.current = true;
|
|
28
30
|
}
|
package/src/PressResponder.tsx
CHANGED
|
@@ -11,21 +11,22 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import {FocusableElement} from '@react-types/shared';
|
|
14
|
-
import {mergeProps, useSyncRef} from '@react-aria/utils';
|
|
14
|
+
import {mergeProps, useObjectRef, useSyncRef} from '@react-aria/utils';
|
|
15
15
|
import {PressProps} from './usePress';
|
|
16
16
|
import {PressResponderContext} from './context';
|
|
17
|
-
import React, {
|
|
17
|
+
import React, {ForwardedRef, ReactNode, useContext, useEffect, useMemo, useRef} from 'react';
|
|
18
18
|
|
|
19
19
|
interface PressResponderProps extends PressProps {
|
|
20
20
|
children: ReactNode
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
export const PressResponder = React.forwardRef(({children, ...props}: PressResponderProps, ref:
|
|
23
|
+
export const PressResponder = React.forwardRef(({children, ...props}: PressResponderProps, ref: ForwardedRef<FocusableElement>) => {
|
|
24
24
|
let isRegistered = useRef(false);
|
|
25
25
|
let prevContext = useContext(PressResponderContext);
|
|
26
|
+
ref = useObjectRef(ref || prevContext?.ref);
|
|
26
27
|
let context = mergeProps(prevContext || {}, {
|
|
27
28
|
...props,
|
|
28
|
-
ref
|
|
29
|
+
ref,
|
|
29
30
|
register() {
|
|
30
31
|
isRegistered.current = true;
|
|
31
32
|
if (prevContext) {
|
|
@@ -54,8 +55,9 @@ export const PressResponder = React.forwardRef(({children, ...props}: PressRespo
|
|
|
54
55
|
});
|
|
55
56
|
|
|
56
57
|
export function ClearPressResponder({children}: {children: ReactNode}) {
|
|
58
|
+
let context = useMemo(() => ({register: () => {}}), []);
|
|
57
59
|
return (
|
|
58
|
-
<PressResponderContext.Provider value={
|
|
60
|
+
<PressResponderContext.Provider value={context}>
|
|
59
61
|
{children}
|
|
60
62
|
</PressResponderContext.Provider>
|
|
61
63
|
);
|
package/src/Pressable.tsx
CHANGED
|
@@ -11,17 +11,16 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import {DOMAttributes} from '@react-types/shared';
|
|
14
|
-
import {mergeProps} from '@react-aria/utils';
|
|
14
|
+
import {mergeProps, useObjectRef} from '@react-aria/utils';
|
|
15
15
|
import {PressProps, usePress} from './usePress';
|
|
16
|
-
import React, {
|
|
16
|
+
import React, {ForwardedRef, ReactElement} from 'react';
|
|
17
17
|
|
|
18
18
|
interface PressableProps extends PressProps {
|
|
19
19
|
children: ReactElement<DOMAttributes, string>
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export const Pressable = React.forwardRef(({children, ...props}: PressableProps, ref:
|
|
23
|
-
|
|
24
|
-
ref = ref ?? newRef;
|
|
22
|
+
export const Pressable = React.forwardRef(({children, ...props}: PressableProps, ref: ForwardedRef<HTMLElement>) => {
|
|
23
|
+
ref = useObjectRef(ref);
|
|
25
24
|
let {pressProps} = usePress({...props, ref});
|
|
26
25
|
let child = React.Children.only(children);
|
|
27
26
|
return React.cloneElement(
|
package/src/context.ts
CHANGED
|
@@ -19,5 +19,5 @@ interface IPressResponderContext extends PressProps {
|
|
|
19
19
|
ref?: MutableRefObject<FocusableElement>
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export const PressResponderContext = React.createContext<IPressResponderContext>(
|
|
22
|
+
export const PressResponderContext = React.createContext<IPressResponderContext>({register: () => {}});
|
|
23
23
|
PressResponderContext.displayName = 'PressResponderContext';
|
|
@@ -16,9 +16,9 @@ import {SyntheticEvent} from 'react';
|
|
|
16
16
|
/**
|
|
17
17
|
* This function wraps a React event handler to make stopPropagation the default, and support continuePropagation instead.
|
|
18
18
|
*/
|
|
19
|
-
export function createEventHandler<T extends SyntheticEvent>(handler
|
|
19
|
+
export function createEventHandler<T extends SyntheticEvent>(handler?: (e: BaseEvent<T>) => void): ((e: T) => void) | undefined {
|
|
20
20
|
if (!handler) {
|
|
21
|
-
return;
|
|
21
|
+
return undefined;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
let shouldStopPropagation = true;
|
package/src/textSelection.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {isIOS, runAfterTransition} from '@react-aria/utils';
|
|
13
|
+
import {getOwnerDocument, isIOS, runAfterTransition} from '@react-aria/utils';
|
|
14
14
|
|
|
15
15
|
// Safari on iOS starts selecting text on long press. The only way to avoid this, it seems,
|
|
16
16
|
// is to add user-select: none to the entire page. Adding it to the pressable element prevents
|
|
@@ -36,8 +36,10 @@ let modifiedElementMap = new WeakMap<Element, string>();
|
|
|
36
36
|
export function disableTextSelection(target?: Element) {
|
|
37
37
|
if (isIOS()) {
|
|
38
38
|
if (state === 'default') {
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
// eslint-disable-next-line no-restricted-globals
|
|
40
|
+
const documentObject = getOwnerDocument(target);
|
|
41
|
+
savedUserSelect = documentObject.documentElement.style.webkitUserSelect;
|
|
42
|
+
documentObject.documentElement.style.webkitUserSelect = 'none';
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
state = 'disabled';
|
|
@@ -67,8 +69,10 @@ export function restoreTextSelection(target?: Element) {
|
|
|
67
69
|
runAfterTransition(() => {
|
|
68
70
|
// Avoid race conditions
|
|
69
71
|
if (state === 'restoring') {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
// eslint-disable-next-line no-restricted-globals
|
|
73
|
+
const documentObject = getOwnerDocument(target);
|
|
74
|
+
if (documentObject.documentElement.style.webkitUserSelect === 'none') {
|
|
75
|
+
documentObject.documentElement.style.webkitUserSelect = savedUserSelect || '';
|
|
72
76
|
}
|
|
73
77
|
|
|
74
78
|
savedUserSelect = '';
|
|
@@ -82,7 +86,7 @@ export function restoreTextSelection(target?: Element) {
|
|
|
82
86
|
if (target && modifiedElementMap.has(target)) {
|
|
83
87
|
let targetOldUserSelect = modifiedElementMap.get(target);
|
|
84
88
|
|
|
85
|
-
if (target.style.userSelect === 'none') {
|
|
89
|
+
if (target.style.userSelect === 'none' && targetOldUserSelect) {
|
|
86
90
|
target.style.userSelect = targetOldUserSelect;
|
|
87
91
|
}
|
|
88
92
|
|
package/src/useFocusVisible.ts
CHANGED
|
@@ -20,7 +20,7 @@ import {useEffect, useState} from 'react';
|
|
|
20
20
|
import {useIsSSR} from '@react-aria/ssr';
|
|
21
21
|
|
|
22
22
|
export type Modality = 'keyboard' | 'pointer' | 'virtual';
|
|
23
|
-
type HandlerEvent = PointerEvent | MouseEvent | KeyboardEvent | FocusEvent;
|
|
23
|
+
type HandlerEvent = PointerEvent | MouseEvent | KeyboardEvent | FocusEvent | null;
|
|
24
24
|
type Handler = (modality: Modality, e: HandlerEvent) => void;
|
|
25
25
|
export type FocusVisibleHandler = (isFocusVisible: boolean) => void;
|
|
26
26
|
export interface FocusVisibleProps {
|
|
@@ -35,7 +35,7 @@ export interface FocusVisibleResult {
|
|
|
35
35
|
isFocusVisible: boolean
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
let currentModality = null;
|
|
38
|
+
let currentModality: null | Modality = null;
|
|
39
39
|
let changeHandlers = new Set<Handler>();
|
|
40
40
|
let hasSetupGlobalListeners = false;
|
|
41
41
|
let hasEventBeforeFocus = false;
|
|
@@ -126,7 +126,7 @@ function setupGlobalFocusEvents() {
|
|
|
126
126
|
let focus = HTMLElement.prototype.focus;
|
|
127
127
|
HTMLElement.prototype.focus = function () {
|
|
128
128
|
hasEventBeforeFocus = true;
|
|
129
|
-
focus.apply(this, arguments);
|
|
129
|
+
focus.apply(this, arguments as unknown as [options?: FocusOptions | undefined]);
|
|
130
130
|
};
|
|
131
131
|
|
|
132
132
|
document.addEventListener('keydown', handleKeyboardEvent, true);
|
|
@@ -166,7 +166,7 @@ export function isFocusVisible(): boolean {
|
|
|
166
166
|
return currentModality !== 'pointer';
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
export function getInteractionModality(): Modality {
|
|
169
|
+
export function getInteractionModality(): Modality | null {
|
|
170
170
|
return currentModality;
|
|
171
171
|
}
|
|
172
172
|
|
|
@@ -178,7 +178,7 @@ export function setInteractionModality(modality: Modality) {
|
|
|
178
178
|
/**
|
|
179
179
|
* Keeps state of the current modality.
|
|
180
180
|
*/
|
|
181
|
-
export function useInteractionModality(): Modality {
|
|
181
|
+
export function useInteractionModality(): Modality | null {
|
|
182
182
|
setupGlobalFocusEvents();
|
|
183
183
|
|
|
184
184
|
let [modality, setModality] = useState(currentModality);
|
|
@@ -196,11 +196,27 @@ export function useInteractionModality(): Modality {
|
|
|
196
196
|
return useIsSSR() ? null : modality;
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
+
const nonTextInputTypes = new Set([
|
|
200
|
+
'checkbox',
|
|
201
|
+
'radio',
|
|
202
|
+
'range',
|
|
203
|
+
'color',
|
|
204
|
+
'file',
|
|
205
|
+
'image',
|
|
206
|
+
'button',
|
|
207
|
+
'submit',
|
|
208
|
+
'reset'
|
|
209
|
+
]);
|
|
210
|
+
|
|
199
211
|
/**
|
|
200
212
|
* If this is attached to text input component, return if the event is a focus event (Tab/Escape keys pressed) so that
|
|
201
213
|
* focus visible style can be properly set.
|
|
202
214
|
*/
|
|
203
215
|
function isKeyboardFocusEvent(isTextInput: boolean, modality: Modality, e: HandlerEvent) {
|
|
216
|
+
isTextInput = isTextInput ||
|
|
217
|
+
(e?.target instanceof HTMLInputElement && !nonTextInputTypes.has(e?.target?.type)) ||
|
|
218
|
+
e?.target instanceof HTMLTextAreaElement ||
|
|
219
|
+
(e?.target instanceof HTMLElement && e?.target.isContentEditable);
|
|
204
220
|
return !(isTextInput && modality === 'keyboard' && e instanceof KeyboardEvent && !FOCUS_VISIBLE_INPUT_KEYS[e.key]);
|
|
205
221
|
}
|
|
206
222
|
|
|
@@ -225,7 +241,7 @@ export function useFocusVisibleListener(fn: FocusVisibleHandler, deps: ReadonlyA
|
|
|
225
241
|
|
|
226
242
|
useEffect(() => {
|
|
227
243
|
let handler = (modality: Modality, e: HandlerEvent) => {
|
|
228
|
-
if (!isKeyboardFocusEvent(opts?.isTextInput, modality, e)) {
|
|
244
|
+
if (!isKeyboardFocusEvent(!!(opts?.isTextInput), modality, e)) {
|
|
229
245
|
return;
|
|
230
246
|
}
|
|
231
247
|
fn(isFocusVisible());
|
package/src/useFocusWithin.ts
CHANGED
|
@@ -87,8 +87,9 @@ export function useFocusWithin(props: FocusWithinProps): FocusWithinResult {
|
|
|
87
87
|
if (isDisabled) {
|
|
88
88
|
return {
|
|
89
89
|
focusWithinProps: {
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
// These should not have been null, that would conflict in mergeProps
|
|
91
|
+
onFocus: undefined,
|
|
92
|
+
onBlur: undefined
|
|
92
93
|
}
|
|
93
94
|
};
|
|
94
95
|
}
|
|
@@ -15,13 +15,13 @@
|
|
|
15
15
|
// NOTICE file in the root directory of this source tree.
|
|
16
16
|
// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
|
|
17
17
|
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
18
|
+
import {getOwnerDocument, useEffectEvent} from '@react-aria/utils';
|
|
19
|
+
import {RefObject, useEffect, useRef} from 'react';
|
|
20
20
|
|
|
21
21
|
export interface InteractOutsideProps {
|
|
22
22
|
ref: RefObject<Element>,
|
|
23
|
-
onInteractOutside?: (e:
|
|
24
|
-
onInteractOutsideStart?: (e:
|
|
23
|
+
onInteractOutside?: (e: PointerEvent) => void,
|
|
24
|
+
onInteractOutsideStart?: (e: PointerEvent) => void,
|
|
25
25
|
/** Whether the interact outside events should be disabled. */
|
|
26
26
|
isDisabled?: boolean
|
|
27
27
|
}
|
|
@@ -37,7 +37,7 @@ export function useInteractOutside(props: InteractOutsideProps) {
|
|
|
37
37
|
ignoreEmulatedMouseEvents: false
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
-
let onPointerDown = useEffectEvent((e
|
|
40
|
+
let onPointerDown = useEffectEvent((e) => {
|
|
41
41
|
if (onInteractOutside && isValidEvent(e, ref)) {
|
|
42
42
|
if (onInteractOutsideStart) {
|
|
43
43
|
onInteractOutsideStart(e);
|
|
@@ -46,7 +46,7 @@ export function useInteractOutside(props: InteractOutsideProps) {
|
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
48
|
|
|
49
|
-
let triggerInteractOutside = useEffectEvent((e:
|
|
49
|
+
let triggerInteractOutside = useEffectEvent((e: PointerEvent) => {
|
|
50
50
|
if (onInteractOutside) {
|
|
51
51
|
onInteractOutside(e);
|
|
52
52
|
}
|
|
@@ -58,6 +58,9 @@ export function useInteractOutside(props: InteractOutsideProps) {
|
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
const element = ref.current;
|
|
62
|
+
const documentObject = getOwnerDocument(element);
|
|
63
|
+
|
|
61
64
|
// Use pointer events if available. Otherwise, fall back to mouse and touch events.
|
|
62
65
|
if (typeof PointerEvent !== 'undefined') {
|
|
63
66
|
let onPointerUp = (e) => {
|
|
@@ -68,12 +71,12 @@ export function useInteractOutside(props: InteractOutsideProps) {
|
|
|
68
71
|
};
|
|
69
72
|
|
|
70
73
|
// changing these to capture phase fixed combobox
|
|
71
|
-
|
|
72
|
-
|
|
74
|
+
documentObject.addEventListener('pointerdown', onPointerDown, true);
|
|
75
|
+
documentObject.addEventListener('pointerup', onPointerUp, true);
|
|
73
76
|
|
|
74
77
|
return () => {
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
documentObject.removeEventListener('pointerdown', onPointerDown, true);
|
|
79
|
+
documentObject.removeEventListener('pointerup', onPointerUp, true);
|
|
77
80
|
};
|
|
78
81
|
} else {
|
|
79
82
|
let onMouseUp = (e) => {
|
|
@@ -93,16 +96,16 @@ export function useInteractOutside(props: InteractOutsideProps) {
|
|
|
93
96
|
state.isPointerDown = false;
|
|
94
97
|
};
|
|
95
98
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
documentObject.addEventListener('mousedown', onPointerDown, true);
|
|
100
|
+
documentObject.addEventListener('mouseup', onMouseUp, true);
|
|
101
|
+
documentObject.addEventListener('touchstart', onPointerDown, true);
|
|
102
|
+
documentObject.addEventListener('touchend', onTouchEnd, true);
|
|
100
103
|
|
|
101
104
|
return () => {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
105
|
+
documentObject.removeEventListener('mousedown', onPointerDown, true);
|
|
106
|
+
documentObject.removeEventListener('mouseup', onMouseUp, true);
|
|
107
|
+
documentObject.removeEventListener('touchstart', onPointerDown, true);
|
|
108
|
+
documentObject.removeEventListener('touchend', onTouchEnd, true);
|
|
106
109
|
};
|
|
107
110
|
}
|
|
108
111
|
}, [ref, isDisabled, onPointerDown, triggerInteractOutside]);
|
package/src/useLongPress.ts
CHANGED
|
@@ -63,7 +63,7 @@ export function useLongPress(props: LongPressProps): LongPressResult {
|
|
|
63
63
|
accessibilityDescription
|
|
64
64
|
} = props;
|
|
65
65
|
|
|
66
|
-
const timeRef = useRef(
|
|
66
|
+
const timeRef = useRef<ReturnType<typeof setTimeout> | undefined>();
|
|
67
67
|
let {addGlobalListener, removeGlobalListener} = useGlobalListeners();
|
|
68
68
|
|
|
69
69
|
let {pressProps} = usePress({
|
|
@@ -87,7 +87,7 @@ export function useLongPress(props: LongPressProps): LongPressResult {
|
|
|
87
87
|
type: 'longpress'
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
|
-
timeRef.current =
|
|
90
|
+
timeRef.current = undefined;
|
|
91
91
|
}, threshold);
|
|
92
92
|
|
|
93
93
|
// Prevent context menu, which may be opened on long press on touch devices
|
|
@@ -121,7 +121,7 @@ export function useLongPress(props: LongPressProps): LongPressResult {
|
|
|
121
121
|
}
|
|
122
122
|
});
|
|
123
123
|
|
|
124
|
-
let descriptionProps = useDescription(onLongPress && !isDisabled ? accessibilityDescription :
|
|
124
|
+
let descriptionProps = useDescription(onLongPress && !isDisabled ? accessibilityDescription : undefined);
|
|
125
125
|
|
|
126
126
|
return {
|
|
127
127
|
longPressProps: mergeProps(pressProps, descriptionProps)
|
package/src/useMove.ts
CHANGED
|
@@ -59,7 +59,7 @@ export function useMove(props: MoveEvents): MoveResult {
|
|
|
59
59
|
altKey: originalEvent.altKey
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
|
-
onMove({
|
|
62
|
+
onMove?.({
|
|
63
63
|
type: 'move',
|
|
64
64
|
pointerType,
|
|
65
65
|
deltaX: deltaX,
|
|
@@ -96,7 +96,7 @@ export function useMove(props: MoveEvents): MoveResult {
|
|
|
96
96
|
if (typeof PointerEvent === 'undefined') {
|
|
97
97
|
let onMouseMove = (e: MouseEvent) => {
|
|
98
98
|
if (e.button === 0) {
|
|
99
|
-
move(e, 'mouse', e.pageX - state.current.lastPosition
|
|
99
|
+
move(e, 'mouse', e.pageX - (state.current.lastPosition?.pageX ?? 0), e.pageY - (state.current.lastPosition?.pageY ?? 0));
|
|
100
100
|
state.current.lastPosition = {pageX: e.pageX, pageY: e.pageY};
|
|
101
101
|
}
|
|
102
102
|
};
|
|
@@ -122,7 +122,7 @@ export function useMove(props: MoveEvents): MoveResult {
|
|
|
122
122
|
let touch = [...e.changedTouches].findIndex(({identifier}) => identifier === state.current.id);
|
|
123
123
|
if (touch >= 0) {
|
|
124
124
|
let {pageX, pageY} = e.changedTouches[touch];
|
|
125
|
-
move(e, 'touch', pageX - state.current.lastPosition
|
|
125
|
+
move(e, 'touch', pageX - (state.current.lastPosition?.pageX ?? 0), pageY - (state.current.lastPosition?.pageY ?? 0));
|
|
126
126
|
state.current.lastPosition = {pageX, pageY};
|
|
127
127
|
}
|
|
128
128
|
};
|
|
@@ -159,7 +159,7 @@ export function useMove(props: MoveEvents): MoveResult {
|
|
|
159
159
|
// Problems with PointerEvent#movementX/movementY:
|
|
160
160
|
// 1. it is always 0 on macOS Safari.
|
|
161
161
|
// 2. On Chrome Android, it's scaled by devicePixelRatio, but not on Chrome macOS
|
|
162
|
-
move(e, pointerType, e.pageX - state.current.lastPosition
|
|
162
|
+
move(e, pointerType, e.pageX - (state.current.lastPosition?.pageX ?? 0), e.pageY - (state.current.lastPosition?.pageY ?? 0));
|
|
163
163
|
state.current.lastPosition = {pageX: e.pageX, pageY: e.pageY};
|
|
164
164
|
}
|
|
165
165
|
};
|