@react-aria/interactions 3.0.0-nightly.1533 → 3.0.0-nightly.1536

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
@@ -128,61 +128,58 @@ function $625cf83917e112ad$export$715c682d09d639cc(onBlur) {
128
128
  onBlur: onBlur,
129
129
  observer: null
130
130
  });
131
- let state1 = stateRef.current;
132
- state1.onBlur = onBlur;
131
+ stateRef.current.onBlur = onBlur;
133
132
  // Clean up MutationObserver on unmount. See below.
134
133
  // eslint-disable-next-line arrow-body-style
135
134
  $goTMa$reactariautils.useLayoutEffect(()=>{
135
+ const state = stateRef.current;
136
136
  return ()=>{
137
- if (state1.observer) {
138
- state1.observer.disconnect();
139
- state1.observer = null;
137
+ if (state.observer) {
138
+ state.observer.disconnect();
139
+ state.observer = null;
140
140
  }
141
141
  };
142
- }, [
143
- state1
144
- ]);
142
+ }, []);
145
143
  // This function is called during a React onFocus event.
146
- return (e1)=>{
144
+ return $goTMa$react.useCallback((e1)=>{
147
145
  // React does not fire onBlur when an element is disabled. https://github.com/facebook/react/issues/9142
148
146
  // Most browsers fire a native focusout event in this case, except for Firefox. In that case, we use a
149
147
  // MutationObserver to watch for the disabled attribute, and dispatch these events ourselves.
150
148
  // For browsers that do, focusout fires before the MutationObserver, so onBlur should not fire twice.
151
149
  if (e1.target instanceof HTMLButtonElement || e1.target instanceof HTMLInputElement || e1.target instanceof HTMLTextAreaElement || e1.target instanceof HTMLSelectElement) {
152
- state1.isFocused = true;
150
+ stateRef.current.isFocused = true;
153
151
  let target = e1.target;
154
152
  let onBlurHandler = (e)=>{
155
153
  var // For backward compatibility, dispatch a (fake) React synthetic event.
156
- ref;
157
- let state = stateRef.current;
158
- state.isFocused = false;
159
- if (target.disabled) (ref = state.onBlur) === null || ref === void 0 ? void 0 : ref.call(state, new $625cf83917e112ad$export$905e7fc544a71f36('blur', e));
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));
160
157
  // We no longer need the MutationObserver once the target is blurred.
161
- if (state.observer) {
162
- state.observer.disconnect();
163
- state.observer = null;
158
+ if (stateRef.current.observer) {
159
+ stateRef.current.observer.disconnect();
160
+ stateRef.current.observer = null;
164
161
  }
165
162
  };
166
163
  target.addEventListener('focusout', onBlurHandler, {
167
164
  once: true
168
165
  });
169
- state1.observer = new MutationObserver(()=>{
170
- if (state1.isFocused && target.disabled) {
171
- state1.observer.disconnect();
166
+ stateRef.current.observer = new MutationObserver(()=>{
167
+ if (stateRef.current.isFocused && target.disabled) {
168
+ stateRef.current.observer.disconnect();
172
169
  target.dispatchEvent(new FocusEvent('blur'));
173
170
  target.dispatchEvent(new FocusEvent('focusout', {
174
171
  bubbles: true
175
172
  }));
176
173
  }
177
174
  });
178
- state1.observer.observe(target, {
175
+ stateRef.current.observer.observe(target, {
179
176
  attributes: true,
180
177
  attributeFilter: [
181
178
  'disabled'
182
179
  ]
183
180
  });
184
181
  }
185
- };
182
+ }, []);
186
183
  }
187
184
 
188
185
 
@@ -697,29 +694,34 @@ var $5cb73d0ce355b0dc$exports = {};
697
694
 
698
695
  $parcel$export($5cb73d0ce355b0dc$exports, "useFocus", () => $5cb73d0ce355b0dc$export$f8168d8dd8fd66e6);
699
696
 
700
- function $5cb73d0ce355b0dc$export$f8168d8dd8fd66e6(props) {
701
- let onBlur;
702
- if (!props.isDisabled && (props.onBlur || props.onFocusChange)) onBlur = (e)=>{
697
+
698
+ function $5cb73d0ce355b0dc$export$f8168d8dd8fd66e6({ isDisabled: isDisabled , onFocus: onFocusProp , onBlur: onBlurProp , onFocusChange: onFocusChange }) {
699
+ const onBlur = $goTMa$react.useCallback((e)=>{
703
700
  if (e.target === e.currentTarget) {
704
- if (props.onBlur) props.onBlur(e);
705
- if (props.onFocusChange) props.onFocusChange(false);
701
+ if (onBlurProp) onBlurProp(e);
702
+ if (onFocusChange) onFocusChange(false);
706
703
  return true;
707
704
  }
708
- };
709
- else onBlur = null;
710
- let onSyntheticFocus = $625cf83917e112ad$export$715c682d09d639cc(onBlur);
711
- let onFocus;
712
- if (!props.isDisabled && (props.onFocus || props.onFocusChange || props.onBlur)) onFocus = (e)=>{
705
+ }, [
706
+ onBlurProp,
707
+ onFocusChange
708
+ ]);
709
+ const onSyntheticFocus = $625cf83917e112ad$export$715c682d09d639cc(onBlur);
710
+ const onFocus = $goTMa$react.useCallback((e)=>{
713
711
  if (e.target === e.currentTarget) {
714
- if (props.onFocus) props.onFocus(e);
715
- if (props.onFocusChange) props.onFocusChange(true);
712
+ if (onFocusProp) onFocusProp(e);
713
+ if (onFocusChange) onFocusChange(true);
716
714
  onSyntheticFocus(e);
717
715
  }
718
- };
716
+ }, [
717
+ onFocusChange,
718
+ onFocusProp,
719
+ onSyntheticFocus
720
+ ]);
719
721
  return {
720
722
  focusProps: {
721
- onFocus: onFocus,
722
- onBlur: onBlur
723
+ onFocus: !isDisabled && (onFocusProp || onFocusChange || onBlurProp) ? onFocus : undefined,
724
+ onBlur: !isDisabled && (onBlurProp || onFocusChange) ? onBlur : null
723
725
  }
724
726
  };
725
727
  }
@@ -895,28 +897,42 @@ var $d16842bbd0359d1b$exports = {};
895
897
  $parcel$export($d16842bbd0359d1b$exports, "useFocusWithin", () => $d16842bbd0359d1b$export$420e68273165f4ec);
896
898
 
897
899
 
898
- function $d16842bbd0359d1b$export$420e68273165f4ec(props) {
900
+ function $d16842bbd0359d1b$export$420e68273165f4ec({ isDisabled: isDisabled , onBlurWithin: onBlurWithin , onFocusWithin: onFocusWithin , onFocusWithinChange: onFocusWithinChange }) {
899
901
  let state = $goTMa$react.useRef({
900
902
  isFocusWithin: false
901
- }).current;
902
- let onBlur = props.isDisabled ? null : (e)=>{
903
+ });
904
+ let onBlur = $goTMa$react.useCallback((e)=>{
903
905
  // We don't want to trigger onBlurWithin and then immediately onFocusWithin again
904
906
  // when moving focus inside the element. Only trigger if the currentTarget doesn't
905
907
  // include the relatedTarget (where focus is moving).
906
- if (state.isFocusWithin && !e.currentTarget.contains(e.relatedTarget)) {
907
- state.isFocusWithin = false;
908
- if (props.onBlurWithin) props.onBlurWithin(e);
909
- if (props.onFocusWithinChange) props.onFocusWithinChange(false);
908
+ if (state.current.isFocusWithin && !e.currentTarget.contains(e.relatedTarget)) {
909
+ state.current.isFocusWithin = false;
910
+ if (onBlurWithin) onBlurWithin(e);
911
+ if (onFocusWithinChange) onFocusWithinChange(false);
910
912
  }
911
- };
913
+ }, [
914
+ onBlurWithin,
915
+ onFocusWithinChange,
916
+ state
917
+ ]);
912
918
  let onSyntheticFocus = $625cf83917e112ad$export$715c682d09d639cc(onBlur);
913
- let onFocus = props.isDisabled ? null : (e)=>{
914
- if (!state.isFocusWithin) {
915
- if (props.onFocusWithin) props.onFocusWithin(e);
916
- if (props.onFocusWithinChange) props.onFocusWithinChange(true);
917
- state.isFocusWithin = true;
919
+ let onFocus = $goTMa$react.useCallback((e)=>{
920
+ if (!state.current.isFocusWithin) {
921
+ if (onFocusWithin) onFocusWithin(e);
922
+ if (onFocusWithinChange) onFocusWithinChange(true);
923
+ state.current.isFocusWithin = true;
918
924
  onSyntheticFocus(e);
919
925
  }
926
+ }, [
927
+ onFocusWithin,
928
+ onFocusWithinChange,
929
+ onSyntheticFocus
930
+ ]);
931
+ if (isDisabled) return {
932
+ focusWithinProps: {
933
+ onFocus: null,
934
+ onBlur: null
935
+ }
920
936
  };
921
937
  return {
922
938
  focusWithinProps: {