@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/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,104 @@ 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
+ stateRef.current.onBlur = onBlur;
113
+ // Clean up MutationObserver on unmount. See below.
114
+ // eslint-disable-next-line arrow-body-style
115
+ $bx7SL$useLayoutEffect(()=>{
116
+ const state = stateRef.current;
117
+ return ()=>{
118
+ if (state.observer) {
119
+ state.observer.disconnect();
120
+ state.observer = null;
121
+ }
122
+ };
123
+ }, []);
124
+ // This function is called during a React onFocus event.
125
+ return $bx7SL$useCallback((e1)=>{
126
+ // React does not fire onBlur when an element is disabled. https://github.com/facebook/react/issues/9142
127
+ // Most browsers fire a native focusout event in this case, except for Firefox. In that case, we use a
128
+ // MutationObserver to watch for the disabled attribute, and dispatch these events ourselves.
129
+ // For browsers that do, focusout fires before the MutationObserver, so onBlur should not fire twice.
130
+ if (e1.target instanceof HTMLButtonElement || e1.target instanceof HTMLInputElement || e1.target instanceof HTMLTextAreaElement || e1.target instanceof HTMLSelectElement) {
131
+ stateRef.current.isFocused = true;
132
+ let target = e1.target;
133
+ let onBlurHandler = (e)=>{
134
+ var // For backward compatibility, dispatch a (fake) React synthetic event.
135
+ _current, ref;
136
+ stateRef.current.isFocused = false;
137
+ if (target.disabled) (ref = (_current = stateRef.current).onBlur) === null || ref === void 0 ? void 0 : ref.call(_current, new $8a9cb279dc87e130$export$905e7fc544a71f36('blur', e));
138
+ // We no longer need the MutationObserver once the target is blurred.
139
+ if (stateRef.current.observer) {
140
+ stateRef.current.observer.disconnect();
141
+ stateRef.current.observer = null;
142
+ }
143
+ };
144
+ target.addEventListener('focusout', onBlurHandler, {
145
+ once: true
146
+ });
147
+ stateRef.current.observer = new MutationObserver(()=>{
148
+ if (stateRef.current.isFocused && target.disabled) {
149
+ stateRef.current.observer.disconnect();
150
+ target.dispatchEvent(new FocusEvent('blur'));
151
+ target.dispatchEvent(new FocusEvent('focusout', {
152
+ bubbles: true
153
+ }));
154
+ }
155
+ });
156
+ stateRef.current.observer.observe(target, {
157
+ attributes: true,
158
+ attributeFilter: [
159
+ 'disabled'
160
+ ]
161
+ });
162
+ }
163
+ }, []);
164
+ }
72
165
 
73
166
 
74
167
 
@@ -528,8 +621,9 @@ function $f6c31cce2adf654f$var$isVirtualPointerEvent(event) {
528
621
  // Android TalkBack double tap will sometimes return a event with width and height of 1
529
622
  // and pointerType === 'mouse' so we need to check for a specific combination of event attributes.
530
623
  // Cannot use "event.pressure === 0" as the sole check due to Safari pointer events always returning pressure === 0
531
- // instead of .5, see https://bugs.webkit.org/show_bug.cgi?id=206216
532
- return event.width === 0 && event.height === 0 || event.width === 1 && event.height === 1 && event.pressure === 0 && event.detail === 0;
624
+ // instead of .5, see https://bugs.webkit.org/show_bug.cgi?id=206216. event.pointerType === 'mouse' is to distingush
625
+ // Talkback double tap from Windows Firefox touch screen press
626
+ return event.width === 0 && event.height === 0 || event.width === 1 && event.height === 1 && event.pressure === 0 && event.detail === 0 && event.pointerType === 'mouse';
533
627
  }
534
628
 
535
629
 
@@ -581,28 +675,36 @@ const $f1ab8c75478c6f73$export$3351871ee4b288b8 = /*#__PURE__*/ $bx7SL$react.for
581
675
  var $a1ea59d68270f0dd$exports = {};
582
676
 
583
677
  $parcel$export($a1ea59d68270f0dd$exports, "useFocus", () => $a1ea59d68270f0dd$export$f8168d8dd8fd66e6);
678
+
679
+
584
680
  function $a1ea59d68270f0dd$export$f8168d8dd8fd66e6(props) {
585
- if (props.isDisabled) return {
586
- focusProps: {
587
- }
588
- };
589
- let onFocus, onBlur;
590
- if (props.onFocus || props.onFocusChange) onFocus = (e)=>{
681
+ let { isDisabled: isDisabled , onFocus: onFocusProp , onBlur: onBlurProp , onFocusChange: onFocusChange } = props;
682
+ const onBlur = $bx7SL$useCallback((e)=>{
591
683
  if (e.target === e.currentTarget) {
592
- if (props.onFocus) props.onFocus(e);
593
- if (props.onFocusChange) props.onFocusChange(true);
684
+ if (onBlurProp) onBlurProp(e);
685
+ if (onFocusChange) onFocusChange(false);
686
+ return true;
594
687
  }
595
- };
596
- if (props.onBlur || props.onFocusChange) onBlur = (e)=>{
688
+ }, [
689
+ onBlurProp,
690
+ onFocusChange
691
+ ]);
692
+ const onSyntheticFocus = $8a9cb279dc87e130$export$715c682d09d639cc(onBlur);
693
+ const onFocus = $bx7SL$useCallback((e)=>{
597
694
  if (e.target === e.currentTarget) {
598
- if (props.onBlur) props.onBlur(e);
599
- if (props.onFocusChange) props.onFocusChange(false);
695
+ if (onFocusProp) onFocusProp(e);
696
+ if (onFocusChange) onFocusChange(true);
697
+ onSyntheticFocus(e);
600
698
  }
601
- };
699
+ }, [
700
+ onFocusChange,
701
+ onFocusProp,
702
+ onSyntheticFocus
703
+ ]);
602
704
  return {
603
705
  focusProps: {
604
- onFocus: onFocus,
605
- onBlur: onBlur
706
+ onFocus: !isDisabled && (onFocusProp || onFocusChange || onBlurProp) ? onFocus : undefined,
707
+ onBlur: !isDisabled && (onBlurProp || onFocusChange) ? onBlur : null
606
708
  }
607
709
  };
608
710
  }
@@ -777,29 +879,43 @@ var $9ab94262bd0047c7$exports = {};
777
879
 
778
880
  $parcel$export($9ab94262bd0047c7$exports, "useFocusWithin", () => $9ab94262bd0047c7$export$420e68273165f4ec);
779
881
 
882
+
780
883
  function $9ab94262bd0047c7$export$420e68273165f4ec(props) {
884
+ let { isDisabled: isDisabled , onBlurWithin: onBlurWithin , onFocusWithin: onFocusWithin , onFocusWithinChange: onFocusWithinChange } = props;
781
885
  let state = $bx7SL$useRef({
782
886
  isFocusWithin: false
783
- }).current;
784
- if (props.isDisabled) return {
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)=>{
887
+ });
888
+ let onBlur = $bx7SL$useCallback((e)=>{
796
889
  // We don't want to trigger onBlurWithin and then immediately onFocusWithin again
797
890
  // when moving focus inside the element. Only trigger if the currentTarget doesn't
798
891
  // include the relatedTarget (where focus is moving).
799
- if (state.isFocusWithin && !e.currentTarget.contains(e.relatedTarget)) {
800
- if (props.onBlurWithin) props.onBlurWithin(e);
801
- if (props.onFocusWithinChange) props.onFocusWithinChange(false);
802
- state.isFocusWithin = false;
892
+ if (state.current.isFocusWithin && !e.currentTarget.contains(e.relatedTarget)) {
893
+ state.current.isFocusWithin = false;
894
+ if (onBlurWithin) onBlurWithin(e);
895
+ if (onFocusWithinChange) onFocusWithinChange(false);
896
+ }
897
+ }, [
898
+ onBlurWithin,
899
+ onFocusWithinChange,
900
+ state
901
+ ]);
902
+ let onSyntheticFocus = $8a9cb279dc87e130$export$715c682d09d639cc(onBlur);
903
+ let onFocus = $bx7SL$useCallback((e)=>{
904
+ if (!state.current.isFocusWithin) {
905
+ if (onFocusWithin) onFocusWithin(e);
906
+ if (onFocusWithinChange) onFocusWithinChange(true);
907
+ state.current.isFocusWithin = true;
908
+ onSyntheticFocus(e);
909
+ }
910
+ }, [
911
+ onFocusWithin,
912
+ onFocusWithinChange,
913
+ onSyntheticFocus
914
+ ]);
915
+ if (isDisabled) return {
916
+ focusWithinProps: {
917
+ onFocus: null,
918
+ onBlur: null
803
919
  }
804
920
  };
805
921
  return {