@react-aria/interactions 3.8.2 → 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 CHANGED
@@ -83,11 +83,104 @@ function $f7e14e656343df57$export$b0d6fa1ab32e3295(target) {
83
83
 
84
84
 
85
85
 
86
+
87
+
86
88
  function $625cf83917e112ad$export$60278871457622de(event) {
87
89
  // JAWS/NVDA with Firefox.
88
90
  if (event.mozInputSource === 0 && event.isTrusted) return true;
89
91
  return event.detail === 0 && !event.pointerType;
90
92
  }
93
+ class $625cf83917e112ad$export$905e7fc544a71f36 {
94
+ isDefaultPrevented() {
95
+ return this.nativeEvent.defaultPrevented;
96
+ }
97
+ preventDefault() {
98
+ this.defaultPrevented = true;
99
+ this.nativeEvent.preventDefault();
100
+ }
101
+ stopPropagation() {
102
+ this.nativeEvent.stopPropagation();
103
+ this.isPropagationStopped = ()=>true
104
+ ;
105
+ }
106
+ isPropagationStopped() {
107
+ return false;
108
+ }
109
+ persist() {
110
+ }
111
+ constructor(type, nativeEvent){
112
+ this.nativeEvent = nativeEvent;
113
+ this.target = nativeEvent.target;
114
+ this.currentTarget = nativeEvent.currentTarget;
115
+ this.relatedTarget = nativeEvent.relatedTarget;
116
+ this.bubbles = nativeEvent.bubbles;
117
+ this.cancelable = nativeEvent.cancelable;
118
+ this.defaultPrevented = nativeEvent.defaultPrevented;
119
+ this.eventPhase = nativeEvent.eventPhase;
120
+ this.isTrusted = nativeEvent.isTrusted;
121
+ this.timeStamp = nativeEvent.timeStamp;
122
+ this.type = type;
123
+ }
124
+ }
125
+ function $625cf83917e112ad$export$715c682d09d639cc(onBlur) {
126
+ let stateRef = $goTMa$react.useRef({
127
+ isFocused: false,
128
+ onBlur: onBlur,
129
+ observer: null
130
+ });
131
+ stateRef.current.onBlur = onBlur;
132
+ // Clean up MutationObserver on unmount. See below.
133
+ // eslint-disable-next-line arrow-body-style
134
+ $goTMa$reactariautils.useLayoutEffect(()=>{
135
+ const state = stateRef.current;
136
+ return ()=>{
137
+ if (state.observer) {
138
+ state.observer.disconnect();
139
+ state.observer = null;
140
+ }
141
+ };
142
+ }, []);
143
+ // This function is called during a React onFocus event.
144
+ return $goTMa$react.useCallback((e1)=>{
145
+ // React does not fire onBlur when an element is disabled. https://github.com/facebook/react/issues/9142
146
+ // Most browsers fire a native focusout event in this case, except for Firefox. In that case, we use a
147
+ // MutationObserver to watch for the disabled attribute, and dispatch these events ourselves.
148
+ // For browsers that do, focusout fires before the MutationObserver, so onBlur should not fire twice.
149
+ if (e1.target instanceof HTMLButtonElement || e1.target instanceof HTMLInputElement || e1.target instanceof HTMLTextAreaElement || e1.target instanceof HTMLSelectElement) {
150
+ stateRef.current.isFocused = true;
151
+ let target = e1.target;
152
+ let onBlurHandler = (e)=>{
153
+ var // For backward compatibility, dispatch a (fake) React synthetic event.
154
+ _current, ref;
155
+ stateRef.current.isFocused = false;
156
+ if (target.disabled) (ref = (_current = stateRef.current).onBlur) === null || ref === void 0 ? void 0 : ref.call(_current, new $625cf83917e112ad$export$905e7fc544a71f36('blur', e));
157
+ // We no longer need the MutationObserver once the target is blurred.
158
+ if (stateRef.current.observer) {
159
+ stateRef.current.observer.disconnect();
160
+ stateRef.current.observer = null;
161
+ }
162
+ };
163
+ target.addEventListener('focusout', onBlurHandler, {
164
+ once: true
165
+ });
166
+ stateRef.current.observer = new MutationObserver(()=>{
167
+ if (stateRef.current.isFocused && target.disabled) {
168
+ stateRef.current.observer.disconnect();
169
+ target.dispatchEvent(new FocusEvent('blur'));
170
+ target.dispatchEvent(new FocusEvent('focusout', {
171
+ bubbles: true
172
+ }));
173
+ }
174
+ });
175
+ stateRef.current.observer.observe(target, {
176
+ attributes: true,
177
+ attributeFilter: [
178
+ 'disabled'
179
+ ]
180
+ });
181
+ }
182
+ }, []);
183
+ }
91
184
 
92
185
 
93
186
 
@@ -547,8 +640,9 @@ function $0294ea432cd92340$var$isVirtualPointerEvent(event) {
547
640
  // Android TalkBack double tap will sometimes return a event with width and height of 1
548
641
  // and pointerType === 'mouse' so we need to check for a specific combination of event attributes.
549
642
  // Cannot use "event.pressure === 0" as the sole check due to Safari pointer events always returning pressure === 0
550
- // instead of .5, see https://bugs.webkit.org/show_bug.cgi?id=206216
551
- return event.width === 0 && event.height === 0 || event.width === 1 && event.height === 1 && event.pressure === 0 && event.detail === 0;
643
+ // instead of .5, see https://bugs.webkit.org/show_bug.cgi?id=206216. event.pointerType === 'mouse' is to distingush
644
+ // Talkback double tap from Windows Firefox touch screen press
645
+ return event.width === 0 && event.height === 0 || event.width === 1 && event.height === 1 && event.pressure === 0 && event.detail === 0 && event.pointerType === 'mouse';
552
646
  }
553
647
 
554
648
 
@@ -600,28 +694,36 @@ const $3596bae48579386f$export$3351871ee4b288b8 = /*#__PURE__*/ ($parcel$interop
600
694
  var $5cb73d0ce355b0dc$exports = {};
601
695
 
602
696
  $parcel$export($5cb73d0ce355b0dc$exports, "useFocus", () => $5cb73d0ce355b0dc$export$f8168d8dd8fd66e6);
697
+
698
+
603
699
  function $5cb73d0ce355b0dc$export$f8168d8dd8fd66e6(props) {
604
- if (props.isDisabled) return {
605
- focusProps: {
606
- }
607
- };
608
- let onFocus, onBlur;
609
- if (props.onFocus || props.onFocusChange) onFocus = (e)=>{
700
+ let { isDisabled: isDisabled , onFocus: onFocusProp , onBlur: onBlurProp , onFocusChange: onFocusChange } = props;
701
+ const onBlur = $goTMa$react.useCallback((e)=>{
610
702
  if (e.target === e.currentTarget) {
611
- if (props.onFocus) props.onFocus(e);
612
- if (props.onFocusChange) props.onFocusChange(true);
703
+ if (onBlurProp) onBlurProp(e);
704
+ if (onFocusChange) onFocusChange(false);
705
+ return true;
613
706
  }
614
- };
615
- if (props.onBlur || props.onFocusChange) onBlur = (e)=>{
707
+ }, [
708
+ onBlurProp,
709
+ onFocusChange
710
+ ]);
711
+ const onSyntheticFocus = $625cf83917e112ad$export$715c682d09d639cc(onBlur);
712
+ const onFocus = $goTMa$react.useCallback((e)=>{
616
713
  if (e.target === e.currentTarget) {
617
- if (props.onBlur) props.onBlur(e);
618
- if (props.onFocusChange) props.onFocusChange(false);
714
+ if (onFocusProp) onFocusProp(e);
715
+ if (onFocusChange) onFocusChange(true);
716
+ onSyntheticFocus(e);
619
717
  }
620
- };
718
+ }, [
719
+ onFocusChange,
720
+ onFocusProp,
721
+ onSyntheticFocus
722
+ ]);
621
723
  return {
622
724
  focusProps: {
623
- onFocus: onFocus,
624
- onBlur: onBlur
725
+ onFocus: !isDisabled && (onFocusProp || onFocusChange || onBlurProp) ? onFocus : undefined,
726
+ onBlur: !isDisabled && (onBlurProp || onFocusChange) ? onBlur : null
625
727
  }
626
728
  };
627
729
  }
@@ -796,29 +898,43 @@ var $d16842bbd0359d1b$exports = {};
796
898
 
797
899
  $parcel$export($d16842bbd0359d1b$exports, "useFocusWithin", () => $d16842bbd0359d1b$export$420e68273165f4ec);
798
900
 
901
+
799
902
  function $d16842bbd0359d1b$export$420e68273165f4ec(props) {
903
+ let { isDisabled: isDisabled , onBlurWithin: onBlurWithin , onFocusWithin: onFocusWithin , onFocusWithinChange: onFocusWithinChange } = props;
800
904
  let state = $goTMa$react.useRef({
801
905
  isFocusWithin: false
802
- }).current;
803
- if (props.isDisabled) return {
804
- focusWithinProps: {
805
- }
806
- };
807
- let onFocus = (e)=>{
808
- if (!state.isFocusWithin) {
809
- if (props.onFocusWithin) props.onFocusWithin(e);
810
- if (props.onFocusWithinChange) props.onFocusWithinChange(true);
811
- state.isFocusWithin = true;
812
- }
813
- };
814
- let onBlur = (e)=>{
906
+ });
907
+ let onBlur = $goTMa$react.useCallback((e)=>{
815
908
  // We don't want to trigger onBlurWithin and then immediately onFocusWithin again
816
909
  // when moving focus inside the element. Only trigger if the currentTarget doesn't
817
910
  // include the relatedTarget (where focus is moving).
818
- if (state.isFocusWithin && !e.currentTarget.contains(e.relatedTarget)) {
819
- if (props.onBlurWithin) props.onBlurWithin(e);
820
- if (props.onFocusWithinChange) props.onFocusWithinChange(false);
821
- state.isFocusWithin = false;
911
+ if (state.current.isFocusWithin && !e.currentTarget.contains(e.relatedTarget)) {
912
+ state.current.isFocusWithin = false;
913
+ if (onBlurWithin) onBlurWithin(e);
914
+ if (onFocusWithinChange) onFocusWithinChange(false);
915
+ }
916
+ }, [
917
+ onBlurWithin,
918
+ onFocusWithinChange,
919
+ state
920
+ ]);
921
+ let onSyntheticFocus = $625cf83917e112ad$export$715c682d09d639cc(onBlur);
922
+ let onFocus = $goTMa$react.useCallback((e)=>{
923
+ if (!state.current.isFocusWithin) {
924
+ if (onFocusWithin) onFocusWithin(e);
925
+ if (onFocusWithinChange) onFocusWithinChange(true);
926
+ state.current.isFocusWithin = true;
927
+ onSyntheticFocus(e);
928
+ }
929
+ }, [
930
+ onFocusWithin,
931
+ onFocusWithinChange,
932
+ onSyntheticFocus
933
+ ]);
934
+ if (isDisabled) return {
935
+ focusWithinProps: {
936
+ onFocus: null,
937
+ onBlur: null
822
938
  }
823
939
  };
824
940
  return {