@react-aria/interactions 3.8.2 → 3.8.3
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 +120 -23
- package/dist/main.js.map +1 -1
- package/dist/module.js +121 -24
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/useFocus.ts +21 -15
- package/src/useFocusWithin.ts +20 -21
- package/src/utils.ts +117 -0
package/dist/module.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {mergeProps as $bx7SL$mergeProps, useSyncRef as $bx7SL$useSyncRef, useGlobalListeners as $bx7SL$useGlobalListeners, focusWithoutScrolling as $bx7SL$focusWithoutScrolling, isIOS as $bx7SL$isIOS, runAfterTransition as $bx7SL$runAfterTransition, isMac as $bx7SL$isMac, useEvent as $bx7SL$useEvent, useDescription as $bx7SL$useDescription} from "@react-aria/utils";
|
|
1
|
+
import {mergeProps as $bx7SL$mergeProps, useSyncRef as $bx7SL$useSyncRef, useGlobalListeners as $bx7SL$useGlobalListeners, focusWithoutScrolling as $bx7SL$focusWithoutScrolling, isIOS as $bx7SL$isIOS, runAfterTransition as $bx7SL$runAfterTransition, useLayoutEffect as $bx7SL$useLayoutEffect, isMac as $bx7SL$isMac, useEvent as $bx7SL$useEvent, useDescription as $bx7SL$useDescription} from "@react-aria/utils";
|
|
2
2
|
import $bx7SL$react, {useRef as $bx7SL$useRef, useContext as $bx7SL$useContext, useState as $bx7SL$useState, useMemo as $bx7SL$useMemo, useEffect as $bx7SL$useEffect, useCallback as $bx7SL$useCallback} from "react";
|
|
3
3
|
|
|
4
4
|
function $parcel$export(e, n, v, s) {
|
|
@@ -64,11 +64,107 @@ function $14c0b72509d70225$export$b0d6fa1ab32e3295(target) {
|
|
|
64
64
|
|
|
65
65
|
|
|
66
66
|
|
|
67
|
+
|
|
68
|
+
|
|
67
69
|
function $8a9cb279dc87e130$export$60278871457622de(event) {
|
|
68
70
|
// JAWS/NVDA with Firefox.
|
|
69
71
|
if (event.mozInputSource === 0 && event.isTrusted) return true;
|
|
70
72
|
return event.detail === 0 && !event.pointerType;
|
|
71
73
|
}
|
|
74
|
+
class $8a9cb279dc87e130$export$905e7fc544a71f36 {
|
|
75
|
+
isDefaultPrevented() {
|
|
76
|
+
return this.nativeEvent.defaultPrevented;
|
|
77
|
+
}
|
|
78
|
+
preventDefault() {
|
|
79
|
+
this.defaultPrevented = true;
|
|
80
|
+
this.nativeEvent.preventDefault();
|
|
81
|
+
}
|
|
82
|
+
stopPropagation() {
|
|
83
|
+
this.nativeEvent.stopPropagation();
|
|
84
|
+
this.isPropagationStopped = ()=>true
|
|
85
|
+
;
|
|
86
|
+
}
|
|
87
|
+
isPropagationStopped() {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
persist() {
|
|
91
|
+
}
|
|
92
|
+
constructor(type, nativeEvent){
|
|
93
|
+
this.nativeEvent = nativeEvent;
|
|
94
|
+
this.target = nativeEvent.target;
|
|
95
|
+
this.currentTarget = nativeEvent.currentTarget;
|
|
96
|
+
this.relatedTarget = nativeEvent.relatedTarget;
|
|
97
|
+
this.bubbles = nativeEvent.bubbles;
|
|
98
|
+
this.cancelable = nativeEvent.cancelable;
|
|
99
|
+
this.defaultPrevented = nativeEvent.defaultPrevented;
|
|
100
|
+
this.eventPhase = nativeEvent.eventPhase;
|
|
101
|
+
this.isTrusted = nativeEvent.isTrusted;
|
|
102
|
+
this.timeStamp = nativeEvent.timeStamp;
|
|
103
|
+
this.type = type;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function $8a9cb279dc87e130$export$715c682d09d639cc(onBlur) {
|
|
107
|
+
let stateRef = $bx7SL$useRef({
|
|
108
|
+
isFocused: false,
|
|
109
|
+
onBlur: onBlur,
|
|
110
|
+
observer: null
|
|
111
|
+
});
|
|
112
|
+
let state1 = stateRef.current;
|
|
113
|
+
state1.onBlur = onBlur;
|
|
114
|
+
// Clean up MutationObserver on unmount. See below.
|
|
115
|
+
// eslint-disable-next-line arrow-body-style
|
|
116
|
+
$bx7SL$useLayoutEffect(()=>{
|
|
117
|
+
return ()=>{
|
|
118
|
+
if (state1.observer) {
|
|
119
|
+
state1.observer.disconnect();
|
|
120
|
+
state1.observer = null;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}, [
|
|
124
|
+
state1
|
|
125
|
+
]);
|
|
126
|
+
// This function is called during a React onFocus event.
|
|
127
|
+
return (e1)=>{
|
|
128
|
+
// React does not fire onBlur when an element is disabled. https://github.com/facebook/react/issues/9142
|
|
129
|
+
// Most browsers fire a native focusout event in this case, except for Firefox. In that case, we use a
|
|
130
|
+
// MutationObserver to watch for the disabled attribute, and dispatch these events ourselves.
|
|
131
|
+
// For browsers that do, focusout fires before the MutationObserver, so onBlur should not fire twice.
|
|
132
|
+
if (e1.target instanceof HTMLButtonElement || e1.target instanceof HTMLInputElement || e1.target instanceof HTMLTextAreaElement || e1.target instanceof HTMLSelectElement) {
|
|
133
|
+
state1.isFocused = true;
|
|
134
|
+
let target = e1.target;
|
|
135
|
+
let onBlurHandler = (e)=>{
|
|
136
|
+
var // For backward compatibility, dispatch a (fake) React synthetic event.
|
|
137
|
+
ref;
|
|
138
|
+
let state = stateRef.current;
|
|
139
|
+
state.isFocused = false;
|
|
140
|
+
if (target.disabled) (ref = state.onBlur) === null || ref === void 0 ? void 0 : ref.call(state, new $8a9cb279dc87e130$export$905e7fc544a71f36('blur', e));
|
|
141
|
+
// We no longer need the MutationObserver once the target is blurred.
|
|
142
|
+
if (state.observer) {
|
|
143
|
+
state.observer.disconnect();
|
|
144
|
+
state.observer = null;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
target.addEventListener('focusout', onBlurHandler, {
|
|
148
|
+
once: true
|
|
149
|
+
});
|
|
150
|
+
state1.observer = new MutationObserver(()=>{
|
|
151
|
+
if (state1.isFocused && target.disabled) {
|
|
152
|
+
state1.observer.disconnect();
|
|
153
|
+
target.dispatchEvent(new FocusEvent('blur'));
|
|
154
|
+
target.dispatchEvent(new FocusEvent('focusout', {
|
|
155
|
+
bubbles: true
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
state1.observer.observe(target, {
|
|
160
|
+
attributes: true,
|
|
161
|
+
attributeFilter: [
|
|
162
|
+
'disabled'
|
|
163
|
+
]
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
}
|
|
72
168
|
|
|
73
169
|
|
|
74
170
|
|
|
@@ -581,22 +677,24 @@ const $f1ab8c75478c6f73$export$3351871ee4b288b8 = /*#__PURE__*/ $bx7SL$react.for
|
|
|
581
677
|
var $a1ea59d68270f0dd$exports = {};
|
|
582
678
|
|
|
583
679
|
$parcel$export($a1ea59d68270f0dd$exports, "useFocus", () => $a1ea59d68270f0dd$export$f8168d8dd8fd66e6);
|
|
680
|
+
|
|
584
681
|
function $a1ea59d68270f0dd$export$f8168d8dd8fd66e6(props) {
|
|
585
|
-
|
|
586
|
-
|
|
682
|
+
let onBlur;
|
|
683
|
+
if (!props.isDisabled && (props.onBlur || props.onFocusChange)) onBlur = (e)=>{
|
|
684
|
+
if (e.target === e.currentTarget) {
|
|
685
|
+
if (props.onBlur) props.onBlur(e);
|
|
686
|
+
if (props.onFocusChange) props.onFocusChange(false);
|
|
687
|
+
return true;
|
|
587
688
|
}
|
|
588
689
|
};
|
|
589
|
-
|
|
590
|
-
|
|
690
|
+
else onBlur = null;
|
|
691
|
+
let onSyntheticFocus = $8a9cb279dc87e130$export$715c682d09d639cc(onBlur);
|
|
692
|
+
let onFocus;
|
|
693
|
+
if (!props.isDisabled && (props.onFocus || props.onFocusChange || props.onBlur)) onFocus = (e)=>{
|
|
591
694
|
if (e.target === e.currentTarget) {
|
|
592
695
|
if (props.onFocus) props.onFocus(e);
|
|
593
696
|
if (props.onFocusChange) props.onFocusChange(true);
|
|
594
|
-
|
|
595
|
-
};
|
|
596
|
-
if (props.onBlur || props.onFocusChange) onBlur = (e)=>{
|
|
597
|
-
if (e.target === e.currentTarget) {
|
|
598
|
-
if (props.onBlur) props.onBlur(e);
|
|
599
|
-
if (props.onFocusChange) props.onFocusChange(false);
|
|
697
|
+
onSyntheticFocus(e);
|
|
600
698
|
}
|
|
601
699
|
};
|
|
602
700
|
return {
|
|
@@ -777,29 +875,28 @@ var $9ab94262bd0047c7$exports = {};
|
|
|
777
875
|
|
|
778
876
|
$parcel$export($9ab94262bd0047c7$exports, "useFocusWithin", () => $9ab94262bd0047c7$export$420e68273165f4ec);
|
|
779
877
|
|
|
878
|
+
|
|
780
879
|
function $9ab94262bd0047c7$export$420e68273165f4ec(props) {
|
|
781
880
|
let state = $bx7SL$useRef({
|
|
782
881
|
isFocusWithin: false
|
|
783
882
|
}).current;
|
|
784
|
-
|
|
785
|
-
focusWithinProps: {
|
|
786
|
-
}
|
|
787
|
-
};
|
|
788
|
-
let onFocus = (e)=>{
|
|
789
|
-
if (!state.isFocusWithin) {
|
|
790
|
-
if (props.onFocusWithin) props.onFocusWithin(e);
|
|
791
|
-
if (props.onFocusWithinChange) props.onFocusWithinChange(true);
|
|
792
|
-
state.isFocusWithin = true;
|
|
793
|
-
}
|
|
794
|
-
};
|
|
795
|
-
let onBlur = (e)=>{
|
|
883
|
+
let onBlur = props.isDisabled ? null : (e)=>{
|
|
796
884
|
// We don't want to trigger onBlurWithin and then immediately onFocusWithin again
|
|
797
885
|
// when moving focus inside the element. Only trigger if the currentTarget doesn't
|
|
798
886
|
// include the relatedTarget (where focus is moving).
|
|
799
887
|
if (state.isFocusWithin && !e.currentTarget.contains(e.relatedTarget)) {
|
|
888
|
+
state.isFocusWithin = false;
|
|
800
889
|
if (props.onBlurWithin) props.onBlurWithin(e);
|
|
801
890
|
if (props.onFocusWithinChange) props.onFocusWithinChange(false);
|
|
802
|
-
|
|
891
|
+
}
|
|
892
|
+
};
|
|
893
|
+
let onSyntheticFocus = $8a9cb279dc87e130$export$715c682d09d639cc(onBlur);
|
|
894
|
+
let onFocus = props.isDisabled ? null : (e)=>{
|
|
895
|
+
if (!state.isFocusWithin) {
|
|
896
|
+
if (props.onFocusWithin) props.onFocusWithin(e);
|
|
897
|
+
if (props.onFocusWithinChange) props.onFocusWithinChange(true);
|
|
898
|
+
state.isFocusWithin = true;
|
|
899
|
+
onSyntheticFocus(e);
|
|
803
900
|
}
|
|
804
901
|
};
|
|
805
902
|
return {
|