@react-aria/interactions 3.8.4 → 3.9.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/main.js +69 -50
- package/dist/main.js.map +1 -1
- package/dist/module.js +69 -50
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/useFocus.ts +32 -32
- package/src/useFocusWithin.ts +33 -18
- package/src/usePress.ts +4 -2
- package/src/utils.ts +16 -17
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;AGwBA,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,UAAU;IAChD,mCAAmC;IACnC,GAAG,CAAC,EAAE,UAAU,WAAW,CAAC,CAAA;CAC7B;AAsBD;IACE,+CAA+C;IAC/C,SAAS,EAAE,OAAO,CAAC;IACnB,6CAA6C;IAC7C,UAAU,EAAE,eAAe,WAAW,CAAC,CAAA;CACxC;AAeD;;;;GAIG;AACH,yBAAyB,KAAK,EAAE,cAAc,GAAG,WAAW,CA0jB3D;ACtoBD,wBAAyB,SAAQ,UAAU;IACzC,QAAQ,EAAE,aAAa,eAAe,WAAW,CAAC,EAAE,MAAM,CAAC,CAAA;CAC5D;AAED,OAAO,MAAM,6FAUX,CAAC;ACbH,6BAA8B,SAAQ,UAAU;IAC9C,QAAQ,EAAE,SAAS,CAAA;CACpB;AAED,OAAO,MAAM,uGA8BX,CAAC;AC9BH,oBAAqB,SAAQ,WAAW;IACtC,mDAA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AED;IACE,6CAA6C;IAC7C,cAAc,EAAE,eAAe,WAAW,CAAC,CAAA;CAC5C;AAID;;;GAGG;AACH,6BAA6B,KAAK,EAAE,cAAc,GAAG,eAAe,CAwEnE","sources":["packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/textSelection.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/utils.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/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 * from './Pressable';\nexport * from './PressResponder';\nexport * from './useFocus';\nexport * from './useFocusVisible';\nexport * from './useFocusWithin';\nexport * from './useHover';\nexport * from './useInteractOutside';\nexport * from './useKeyboard';\nexport * from './useMove';\nexport * from './usePress';\nexport * from './useScrollWheel';\nexport * from './useLongPress';\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.9.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/runtime": "^7.6.2",
|
|
21
|
-
"@react-aria/utils": "^3.
|
|
22
|
-
"@react-types/shared": "^3.
|
|
21
|
+
"@react-aria/utils": "^3.13.0",
|
|
22
|
+
"@react-types/shared": "^3.13.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"react": "^16.8.0 || ^17.0.0-rc.1"
|
|
25
|
+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "8f921ec5094e7c2b3c301bcb6133372e35a2052b"
|
|
31
31
|
}
|
package/src/useFocus.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
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 {FocusEvent, HTMLAttributes} from 'react';
|
|
18
|
+
import {FocusEvent, HTMLAttributes, useCallback} from 'react';
|
|
19
19
|
import {FocusEvents} from '@react-types/shared';
|
|
20
20
|
import {useSyntheticBlurEvent} from './utils';
|
|
21
21
|
|
|
@@ -34,48 +34,48 @@ interface FocusResult {
|
|
|
34
34
|
* Focus events on child elements will be ignored.
|
|
35
35
|
*/
|
|
36
36
|
export function useFocus(props: FocusProps): FocusResult {
|
|
37
|
-
let
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
37
|
+
let {
|
|
38
|
+
isDisabled,
|
|
39
|
+
onFocus: onFocusProp,
|
|
40
|
+
onBlur: onBlurProp,
|
|
41
|
+
onFocusChange
|
|
42
|
+
} = props;
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
const onBlur: FocusProps['onBlur'] = useCallback((e: FocusEvent) => {
|
|
45
|
+
if (e.target === e.currentTarget) {
|
|
46
|
+
if (onBlurProp) {
|
|
47
|
+
onBlurProp(e);
|
|
48
|
+
}
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
if (onFocusChange) {
|
|
51
|
+
onFocusChange(false);
|
|
50
52
|
}
|
|
51
|
-
};
|
|
52
|
-
} else {
|
|
53
|
-
onBlur = null;
|
|
54
|
-
}
|
|
55
53
|
|
|
56
|
-
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
}, [onBlurProp, onFocusChange]);
|
|
57
|
+
|
|
57
58
|
|
|
58
|
-
|
|
59
|
-
if (!props.isDisabled && (props.onFocus || props.onFocusChange || props.onBlur)) {
|
|
60
|
-
onFocus = (e: FocusEvent) => {
|
|
61
|
-
if (e.target === e.currentTarget) {
|
|
62
|
-
if (props.onFocus) {
|
|
63
|
-
props.onFocus(e);
|
|
64
|
-
}
|
|
59
|
+
const onSyntheticFocus = useSyntheticBlurEvent(onBlur);
|
|
65
60
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
61
|
+
const onFocus: FocusProps['onFocus'] = useCallback((e: FocusEvent) => {
|
|
62
|
+
if (e.target === e.currentTarget) {
|
|
63
|
+
if (onFocusProp) {
|
|
64
|
+
onFocusProp(e);
|
|
65
|
+
}
|
|
69
66
|
|
|
70
|
-
|
|
67
|
+
if (onFocusChange) {
|
|
68
|
+
onFocusChange(true);
|
|
71
69
|
}
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
|
|
71
|
+
onSyntheticFocus(e);
|
|
72
|
+
}
|
|
73
|
+
}, [onFocusChange, onFocusProp, onSyntheticFocus]);
|
|
74
74
|
|
|
75
75
|
return {
|
|
76
76
|
focusProps: {
|
|
77
|
-
onFocus,
|
|
78
|
-
onBlur
|
|
77
|
+
onFocus: (!isDisabled && (onFocusProp || onFocusChange || onBlurProp)) ? onFocus : undefined,
|
|
78
|
+
onBlur: (!isDisabled && (onBlurProp || onFocusChange)) ? onBlur : null
|
|
79
79
|
}
|
|
80
80
|
};
|
|
81
81
|
}
|
package/src/useFocusWithin.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
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 {FocusEvent, HTMLAttributes, useRef} from 'react';
|
|
18
|
+
import {FocusEvent, HTMLAttributes, useCallback, useRef} from 'react';
|
|
19
19
|
import {useSyntheticBlurEvent} from './utils';
|
|
20
20
|
|
|
21
21
|
interface FocusWithinProps {
|
|
@@ -38,42 +38,57 @@ interface FocusWithinResult {
|
|
|
38
38
|
* Handles focus events for the target and its descendants.
|
|
39
39
|
*/
|
|
40
40
|
export function useFocusWithin(props: FocusWithinProps): FocusWithinResult {
|
|
41
|
+
let {
|
|
42
|
+
isDisabled,
|
|
43
|
+
onBlurWithin,
|
|
44
|
+
onFocusWithin,
|
|
45
|
+
onFocusWithinChange
|
|
46
|
+
} = props;
|
|
41
47
|
let state = useRef({
|
|
42
48
|
isFocusWithin: false
|
|
43
|
-
})
|
|
49
|
+
});
|
|
44
50
|
|
|
45
|
-
let onBlur =
|
|
51
|
+
let onBlur = useCallback((e: FocusEvent) => {
|
|
46
52
|
// We don't want to trigger onBlurWithin and then immediately onFocusWithin again
|
|
47
53
|
// when moving focus inside the element. Only trigger if the currentTarget doesn't
|
|
48
54
|
// include the relatedTarget (where focus is moving).
|
|
49
|
-
if (state.isFocusWithin && !(e.currentTarget as Element).contains(e.relatedTarget as Element)) {
|
|
50
|
-
state.isFocusWithin = false;
|
|
55
|
+
if (state.current.isFocusWithin && !(e.currentTarget as Element).contains(e.relatedTarget as Element)) {
|
|
56
|
+
state.current.isFocusWithin = false;
|
|
51
57
|
|
|
52
|
-
if (
|
|
53
|
-
|
|
58
|
+
if (onBlurWithin) {
|
|
59
|
+
onBlurWithin(e);
|
|
54
60
|
}
|
|
55
61
|
|
|
56
|
-
if (
|
|
57
|
-
|
|
62
|
+
if (onFocusWithinChange) {
|
|
63
|
+
onFocusWithinChange(false);
|
|
58
64
|
}
|
|
59
65
|
}
|
|
60
|
-
};
|
|
66
|
+
}, [onBlurWithin, onFocusWithinChange, state]);
|
|
61
67
|
|
|
62
68
|
let onSyntheticFocus = useSyntheticBlurEvent(onBlur);
|
|
63
|
-
let onFocus =
|
|
64
|
-
if (!state.isFocusWithin) {
|
|
65
|
-
if (
|
|
66
|
-
|
|
69
|
+
let onFocus = useCallback((e: FocusEvent) => {
|
|
70
|
+
if (!state.current.isFocusWithin) {
|
|
71
|
+
if (onFocusWithin) {
|
|
72
|
+
onFocusWithin(e);
|
|
67
73
|
}
|
|
68
74
|
|
|
69
|
-
if (
|
|
70
|
-
|
|
75
|
+
if (onFocusWithinChange) {
|
|
76
|
+
onFocusWithinChange(true);
|
|
71
77
|
}
|
|
72
78
|
|
|
73
|
-
state.isFocusWithin = true;
|
|
79
|
+
state.current.isFocusWithin = true;
|
|
74
80
|
onSyntheticFocus(e);
|
|
75
81
|
}
|
|
76
|
-
};
|
|
82
|
+
}, [onFocusWithin, onFocusWithinChange, onSyntheticFocus]);
|
|
83
|
+
|
|
84
|
+
if (isDisabled) {
|
|
85
|
+
return {
|
|
86
|
+
focusWithinProps: {
|
|
87
|
+
onFocus: null,
|
|
88
|
+
onBlur: null
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
77
92
|
|
|
78
93
|
return {
|
|
79
94
|
focusWithinProps: {
|
package/src/usePress.ts
CHANGED
|
@@ -778,13 +778,15 @@ function isVirtualPointerEvent(event: PointerEvent) {
|
|
|
778
778
|
// Android TalkBack double tap will sometimes return a event with width and height of 1
|
|
779
779
|
// and pointerType === 'mouse' so we need to check for a specific combination of event attributes.
|
|
780
780
|
// Cannot use "event.pressure === 0" as the sole check due to Safari pointer events always returning pressure === 0
|
|
781
|
-
// instead of .5, see https://bugs.webkit.org/show_bug.cgi?id=206216
|
|
781
|
+
// instead of .5, see https://bugs.webkit.org/show_bug.cgi?id=206216. event.pointerType === 'mouse' is to distingush
|
|
782
|
+
// Talkback double tap from Windows Firefox touch screen press
|
|
782
783
|
return (
|
|
783
784
|
(event.width === 0 && event.height === 0) ||
|
|
784
785
|
(event.width === 1 &&
|
|
785
786
|
event.height === 1 &&
|
|
786
787
|
event.pressure === 0 &&
|
|
787
|
-
event.detail === 0
|
|
788
|
+
event.detail === 0 &&
|
|
789
|
+
event.pointerType === 'mouse'
|
|
788
790
|
)
|
|
789
791
|
);
|
|
790
792
|
}
|
package/src/utils.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {FocusEvent as ReactFocusEvent, useRef} from 'react';
|
|
13
|
+
import {FocusEvent as ReactFocusEvent, useCallback, useRef} from 'react';
|
|
14
14
|
import {useLayoutEffect} from '@react-aria/utils';
|
|
15
15
|
|
|
16
16
|
// Original licensing for the following method can be found in the
|
|
@@ -87,22 +87,22 @@ export function useSyntheticBlurEvent(onBlur: (e: ReactFocusEvent) => void) {
|
|
|
87
87
|
onBlur,
|
|
88
88
|
observer: null as MutationObserver
|
|
89
89
|
});
|
|
90
|
-
|
|
91
|
-
state.onBlur = onBlur;
|
|
90
|
+
stateRef.current.onBlur = onBlur;
|
|
92
91
|
|
|
93
92
|
// Clean up MutationObserver on unmount. See below.
|
|
94
93
|
// eslint-disable-next-line arrow-body-style
|
|
95
94
|
useLayoutEffect(() => {
|
|
95
|
+
const state = stateRef.current;
|
|
96
96
|
return () => {
|
|
97
97
|
if (state.observer) {
|
|
98
98
|
state.observer.disconnect();
|
|
99
99
|
state.observer = null;
|
|
100
100
|
}
|
|
101
101
|
};
|
|
102
|
-
}, [
|
|
102
|
+
}, []);
|
|
103
103
|
|
|
104
104
|
// This function is called during a React onFocus event.
|
|
105
|
-
return (e: ReactFocusEvent) => {
|
|
105
|
+
return useCallback((e: ReactFocusEvent) => {
|
|
106
106
|
// React does not fire onBlur when an element is disabled. https://github.com/facebook/react/issues/9142
|
|
107
107
|
// Most browsers fire a native focusout event in this case, except for Firefox. In that case, we use a
|
|
108
108
|
// MutationObserver to watch for the disabled attribute, and dispatch these events ourselves.
|
|
@@ -113,36 +113,35 @@ export function useSyntheticBlurEvent(onBlur: (e: ReactFocusEvent) => void) {
|
|
|
113
113
|
e.target instanceof HTMLTextAreaElement ||
|
|
114
114
|
e.target instanceof HTMLSelectElement
|
|
115
115
|
) {
|
|
116
|
-
|
|
116
|
+
stateRef.current.isFocused = true;
|
|
117
117
|
|
|
118
118
|
let target = e.target;
|
|
119
119
|
let onBlurHandler = (e: FocusEvent) => {
|
|
120
|
-
|
|
121
|
-
state.isFocused = false;
|
|
120
|
+
stateRef.current.isFocused = false;
|
|
122
121
|
|
|
123
122
|
if (target.disabled) {
|
|
124
123
|
// For backward compatibility, dispatch a (fake) React synthetic event.
|
|
125
|
-
|
|
124
|
+
stateRef.current.onBlur?.(new SyntheticFocusEvent('blur', e));
|
|
126
125
|
}
|
|
127
126
|
|
|
128
127
|
// We no longer need the MutationObserver once the target is blurred.
|
|
129
|
-
if (
|
|
130
|
-
|
|
131
|
-
|
|
128
|
+
if (stateRef.current.observer) {
|
|
129
|
+
stateRef.current.observer.disconnect();
|
|
130
|
+
stateRef.current.observer = null;
|
|
132
131
|
}
|
|
133
132
|
};
|
|
134
133
|
|
|
135
134
|
target.addEventListener('focusout', onBlurHandler, {once: true});
|
|
136
135
|
|
|
137
|
-
|
|
138
|
-
if (
|
|
139
|
-
|
|
136
|
+
stateRef.current.observer = new MutationObserver(() => {
|
|
137
|
+
if (stateRef.current.isFocused && target.disabled) {
|
|
138
|
+
stateRef.current.observer.disconnect();
|
|
140
139
|
target.dispatchEvent(new FocusEvent('blur'));
|
|
141
140
|
target.dispatchEvent(new FocusEvent('focusout', {bubbles: true}));
|
|
142
141
|
}
|
|
143
142
|
});
|
|
144
143
|
|
|
145
|
-
|
|
144
|
+
stateRef.current.observer.observe(target, {attributes: true, attributeFilter: ['disabled']});
|
|
146
145
|
}
|
|
147
|
-
};
|
|
146
|
+
}, []);
|
|
148
147
|
}
|