@react-aria/interactions 3.10.0 → 3.12.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, useLayoutEffect as $bx7SL$useLayoutEffect, 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, isVirtualClick as $bx7SL$isVirtualClick, focusWithoutScrolling as $bx7SL$focusWithoutScrolling, isVirtualPointerEvent as $bx7SL$isVirtualPointerEvent, 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
 
@@ -57,106 +57,6 @@ function $14c0b72509d70225$export$b0d6fa1ab32e3295(target) {
57
57
 
58
58
 
59
59
 
60
-
61
- function $8a9cb279dc87e130$export$60278871457622de(event) {
62
- // JAWS/NVDA with Firefox.
63
- if (event.mozInputSource === 0 && event.isTrusted) return true;
64
- return event.detail === 0 && !event.pointerType;
65
- }
66
- class $8a9cb279dc87e130$export$905e7fc544a71f36 {
67
- isDefaultPrevented() {
68
- return this.nativeEvent.defaultPrevented;
69
- }
70
- preventDefault() {
71
- this.defaultPrevented = true;
72
- this.nativeEvent.preventDefault();
73
- }
74
- stopPropagation() {
75
- this.nativeEvent.stopPropagation();
76
- this.isPropagationStopped = ()=>true
77
- ;
78
- }
79
- isPropagationStopped() {
80
- return false;
81
- }
82
- persist() {
83
- }
84
- constructor(type, nativeEvent){
85
- this.nativeEvent = nativeEvent;
86
- this.target = nativeEvent.target;
87
- this.currentTarget = nativeEvent.currentTarget;
88
- this.relatedTarget = nativeEvent.relatedTarget;
89
- this.bubbles = nativeEvent.bubbles;
90
- this.cancelable = nativeEvent.cancelable;
91
- this.defaultPrevented = nativeEvent.defaultPrevented;
92
- this.eventPhase = nativeEvent.eventPhase;
93
- this.isTrusted = nativeEvent.isTrusted;
94
- this.timeStamp = nativeEvent.timeStamp;
95
- this.type = type;
96
- }
97
- }
98
- function $8a9cb279dc87e130$export$715c682d09d639cc(onBlur) {
99
- let stateRef = $bx7SL$useRef({
100
- isFocused: false,
101
- onBlur: onBlur,
102
- observer: null
103
- });
104
- stateRef.current.onBlur = onBlur;
105
- // Clean up MutationObserver on unmount. See below.
106
- // eslint-disable-next-line arrow-body-style
107
- $bx7SL$useLayoutEffect(()=>{
108
- const state = stateRef.current;
109
- return ()=>{
110
- if (state.observer) {
111
- state.observer.disconnect();
112
- state.observer = null;
113
- }
114
- };
115
- }, []);
116
- // This function is called during a React onFocus event.
117
- return $bx7SL$useCallback((e1)=>{
118
- // React does not fire onBlur when an element is disabled. https://github.com/facebook/react/issues/9142
119
- // Most browsers fire a native focusout event in this case, except for Firefox. In that case, we use a
120
- // MutationObserver to watch for the disabled attribute, and dispatch these events ourselves.
121
- // For browsers that do, focusout fires before the MutationObserver, so onBlur should not fire twice.
122
- if (e1.target instanceof HTMLButtonElement || e1.target instanceof HTMLInputElement || e1.target instanceof HTMLTextAreaElement || e1.target instanceof HTMLSelectElement) {
123
- stateRef.current.isFocused = true;
124
- let target = e1.target;
125
- let onBlurHandler = (e)=>{
126
- var // For backward compatibility, dispatch a (fake) React synthetic event.
127
- _current, ref;
128
- stateRef.current.isFocused = false;
129
- if (target.disabled) (ref = (_current = stateRef.current).onBlur) === null || ref === void 0 ? void 0 : ref.call(_current, new $8a9cb279dc87e130$export$905e7fc544a71f36('blur', e));
130
- // We no longer need the MutationObserver once the target is blurred.
131
- if (stateRef.current.observer) {
132
- stateRef.current.observer.disconnect();
133
- stateRef.current.observer = null;
134
- }
135
- };
136
- target.addEventListener('focusout', onBlurHandler, {
137
- once: true
138
- });
139
- stateRef.current.observer = new MutationObserver(()=>{
140
- if (stateRef.current.isFocused && target.disabled) {
141
- stateRef.current.observer.disconnect();
142
- target.dispatchEvent(new FocusEvent('blur'));
143
- target.dispatchEvent(new FocusEvent('focusout', {
144
- bubbles: true
145
- }));
146
- }
147
- });
148
- stateRef.current.observer.observe(target, {
149
- attributes: true,
150
- attributeFilter: [
151
- 'disabled'
152
- ]
153
- });
154
- }
155
- }, []);
156
- }
157
-
158
-
159
-
160
60
  const $ae1eeba8b9eafd08$export$5165eccb35aaadb5 = $bx7SL$react.createContext(null);
161
61
  $ae1eeba8b9eafd08$export$5165eccb35aaadb5.displayName = 'PressResponderContext';
162
62
 
@@ -268,8 +168,8 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
268
168
  };
269
169
  let pressProps = {
270
170
  onKeyDown (e) {
271
- if ($f6c31cce2adf654f$var$isValidKeyboardEvent(e.nativeEvent) && e.currentTarget.contains(e.target)) {
272
- if ($f6c31cce2adf654f$var$shouldPreventDefaultKeyboard(e.target)) e.preventDefault();
171
+ if ($f6c31cce2adf654f$var$isValidKeyboardEvent(e.nativeEvent, e.currentTarget) && e.currentTarget.contains(e.target)) {
172
+ if ($f6c31cce2adf654f$var$shouldPreventDefaultKeyboard(e.target, e.key)) e.preventDefault();
273
173
  e.stopPropagation();
274
174
  // If the event is repeating, it may have started on a different element
275
175
  // after which focus moved to the current element. Ignore these events and
@@ -282,10 +182,13 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
282
182
  // instead of the same element where the key down event occurred.
283
183
  addGlobalListener(document, 'keyup', onKeyUp, false);
284
184
  }
285
- }
185
+ } else if (e.key === 'Enter' && $f6c31cce2adf654f$var$isHTMLAnchorLink(e.currentTarget)) // If the target is a link, we won't have handled this above because we want the default
186
+ // browser behavior to open the link when pressing Enter. But we still need to prevent
187
+ // default so that elements above do not also handle it (e.g. table row).
188
+ e.stopPropagation();
286
189
  },
287
190
  onKeyUp (e) {
288
- if ($f6c31cce2adf654f$var$isValidKeyboardEvent(e.nativeEvent) && !e.repeat && e.currentTarget.contains(e.target)) triggerPressUp($f6c31cce2adf654f$var$createEvent(state.target, e), 'keyboard');
191
+ if ($f6c31cce2adf654f$var$isValidKeyboardEvent(e.nativeEvent, e.currentTarget) && !e.repeat && e.currentTarget.contains(e.target)) triggerPressUp($f6c31cce2adf654f$var$createEvent(state.target, e), 'keyboard');
289
192
  },
290
193
  onClick (e) {
291
194
  if (e && !e.currentTarget.contains(e.target)) return;
@@ -294,7 +197,7 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
294
197
  if (isDisabled1) e.preventDefault();
295
198
  // If triggered from a screen reader or by using element.click(),
296
199
  // trigger as if it were a keyboard click.
297
- if (!state.ignoreClickAfterPress && !state.ignoreEmulatedMouseEvents && (state.pointerType === 'virtual' || $8a9cb279dc87e130$export$60278871457622de(e.nativeEvent))) {
200
+ if (!state.ignoreClickAfterPress && !state.ignoreEmulatedMouseEvents && (state.pointerType === 'virtual' || $bx7SL$isVirtualClick(e.nativeEvent))) {
298
201
  // Ensure the element receives focus (VoiceOver on iOS does not do this)
299
202
  if (!isDisabled1 && !preventFocusOnPress) $bx7SL$focusWithoutScrolling(e.currentTarget);
300
203
  triggerPressStart(e, 'virtual');
@@ -307,8 +210,8 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
307
210
  }
308
211
  };
309
212
  let onKeyUp = (e)=>{
310
- if (state.isPressed && $f6c31cce2adf654f$var$isValidKeyboardEvent(e)) {
311
- if ($f6c31cce2adf654f$var$shouldPreventDefaultKeyboard(e.target)) e.preventDefault();
213
+ if (state.isPressed && $f6c31cce2adf654f$var$isValidKeyboardEvent(e, state.target)) {
214
+ if ($f6c31cce2adf654f$var$shouldPreventDefaultKeyboard(e.target, e.key)) e.preventDefault();
312
215
  e.stopPropagation();
313
216
  state.isPressed = false;
314
217
  let target = e.target;
@@ -316,7 +219,7 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
316
219
  removeAllGlobalListeners();
317
220
  // If the target is a link, trigger the click method to open the URL,
318
221
  // but defer triggering pressEnd until onClick event handler.
319
- if (state.target instanceof HTMLElement && (state.target.contains(target) && $f6c31cce2adf654f$var$isHTMLAnchorLink(state.target) || state.target.getAttribute('role') === 'link')) state.target.click();
222
+ if (state.target instanceof HTMLElement && state.target.contains(target) && ($f6c31cce2adf654f$var$isHTMLAnchorLink(state.target) || state.target.getAttribute('role') === 'link')) state.target.click();
320
223
  }
321
224
  };
322
225
  if (typeof PointerEvent !== 'undefined') {
@@ -327,7 +230,7 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
327
230
  // Ignore and let the onClick handler take care of it instead.
328
231
  // https://bugs.webkit.org/show_bug.cgi?id=222627
329
232
  // https://bugs.webkit.org/show_bug.cgi?id=223202
330
- if ($f6c31cce2adf654f$var$isVirtualPointerEvent(e.nativeEvent)) {
233
+ if ($bx7SL$isVirtualPointerEvent(e.nativeEvent)) {
331
234
  state.pointerType = 'virtual';
332
235
  return;
333
236
  }
@@ -415,7 +318,7 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
415
318
  state.isPressed = true;
416
319
  state.isOverTarget = true;
417
320
  state.target = e.currentTarget;
418
- state.pointerType = $8a9cb279dc87e130$export$60278871457622de(e.nativeEvent) ? 'virtual' : 'mouse';
321
+ state.pointerType = $bx7SL$isVirtualClick(e.nativeEvent) ? 'virtual' : 'mouse';
419
322
  if (!isDisabled1 && !preventFocusOnPress) $bx7SL$focusWithoutScrolling(e.currentTarget);
420
323
  triggerPressStart(e, state.pointerType);
421
324
  addGlobalListener(document, 'mouseup', onMouseUp, false);
@@ -548,14 +451,13 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
548
451
  function $f6c31cce2adf654f$var$isHTMLAnchorLink(target) {
549
452
  return target.tagName === 'A' && target.hasAttribute('href');
550
453
  }
551
- function $f6c31cce2adf654f$var$isValidKeyboardEvent(event) {
552
- const { key: key , code: code , target: target } = event;
553
- const element = target;
554
- const { tagName: tagName , isContentEditable: isContentEditable } = element;
454
+ function $f6c31cce2adf654f$var$isValidKeyboardEvent(event, currentTarget) {
455
+ const { key: key , code: code } = event;
456
+ const element = currentTarget;
555
457
  const role = element.getAttribute('role');
556
458
  // Accessibility for keyboards. Space and Enter only.
557
459
  // "Spacebar" is for IE 11
558
- return (key === 'Enter' || key === ' ' || key === 'Spacebar' || code === 'Space') && tagName !== 'INPUT' && tagName !== 'TEXTAREA' && isContentEditable !== true && (!$f6c31cce2adf654f$var$isHTMLAnchorLink(element) || role === 'button' && key !== 'Enter') && // An element with role='link' should only trigger with Enter key
460
+ return (key === 'Enter' || key === ' ' || key === 'Spacebar' || code === 'Space') && !(element instanceof HTMLInputElement && !$f6c31cce2adf654f$var$isValidInputKey(element, key) || element instanceof HTMLTextAreaElement || element.isContentEditable) && (!$f6c31cce2adf654f$var$isHTMLAnchorLink(element) || role === 'button' && key !== 'Enter') && // An element with role='link' should only trigger with Enter key
559
461
  !(role === 'link' && key !== 'Enter');
560
462
  }
561
463
  function $f6c31cce2adf654f$var$getTouchFromEvent(event) {
@@ -606,17 +508,25 @@ function $f6c31cce2adf654f$var$shouldPreventDefault(target) {
606
508
  // We cannot prevent default if the target is a draggable element.
607
509
  return !(target instanceof HTMLElement) || !target.draggable;
608
510
  }
609
- function $f6c31cce2adf654f$var$shouldPreventDefaultKeyboard(target) {
610
- return !((target.tagName === 'INPUT' || target.tagName === 'BUTTON') && target.type === 'submit');
511
+ function $f6c31cce2adf654f$var$shouldPreventDefaultKeyboard(target, key) {
512
+ if (target instanceof HTMLInputElement) return !$f6c31cce2adf654f$var$isValidInputKey(target, key);
513
+ if (target instanceof HTMLButtonElement) return target.type !== 'submit';
514
+ return true;
611
515
  }
612
- function $f6c31cce2adf654f$var$isVirtualPointerEvent(event) {
613
- // If the pointer size is zero, then we assume it's from a screen reader.
614
- // Android TalkBack double tap will sometimes return a event with width and height of 1
615
- // and pointerType === 'mouse' so we need to check for a specific combination of event attributes.
616
- // Cannot use "event.pressure === 0" as the sole check due to Safari pointer events always returning pressure === 0
617
- // instead of .5, see https://bugs.webkit.org/show_bug.cgi?id=206216. event.pointerType === 'mouse' is to distingush
618
- // Talkback double tap from Windows Firefox touch screen press
619
- return event.width === 0 && event.height === 0 || event.width === 1 && event.height === 1 && event.pressure === 0 && event.detail === 0 && event.pointerType === 'mouse';
516
+ const $f6c31cce2adf654f$var$nonTextInputTypes = new Set([
517
+ 'checkbox',
518
+ 'radio',
519
+ 'range',
520
+ 'color',
521
+ 'file',
522
+ 'image',
523
+ 'button',
524
+ 'submit',
525
+ 'reset'
526
+ ]);
527
+ function $f6c31cce2adf654f$var$isValidInputKey(target, key) {
528
+ // Only space should toggle checkboxes and radios, not enter.
529
+ return target.type === 'checkbox' || target.type === 'radio' ? key === ' ' : $f6c31cce2adf654f$var$nonTextInputTypes.has(target.type);
620
530
  }
621
531
 
622
532
 
@@ -664,6 +574,100 @@ const $f1ab8c75478c6f73$export$3351871ee4b288b8 = /*#__PURE__*/ $bx7SL$react.for
664
574
 
665
575
 
666
576
 
577
+
578
+ class $8a9cb279dc87e130$export$905e7fc544a71f36 {
579
+ isDefaultPrevented() {
580
+ return this.nativeEvent.defaultPrevented;
581
+ }
582
+ preventDefault() {
583
+ this.defaultPrevented = true;
584
+ this.nativeEvent.preventDefault();
585
+ }
586
+ stopPropagation() {
587
+ this.nativeEvent.stopPropagation();
588
+ this.isPropagationStopped = ()=>true
589
+ ;
590
+ }
591
+ isPropagationStopped() {
592
+ return false;
593
+ }
594
+ persist() {
595
+ }
596
+ constructor(type, nativeEvent){
597
+ this.nativeEvent = nativeEvent;
598
+ this.target = nativeEvent.target;
599
+ this.currentTarget = nativeEvent.currentTarget;
600
+ this.relatedTarget = nativeEvent.relatedTarget;
601
+ this.bubbles = nativeEvent.bubbles;
602
+ this.cancelable = nativeEvent.cancelable;
603
+ this.defaultPrevented = nativeEvent.defaultPrevented;
604
+ this.eventPhase = nativeEvent.eventPhase;
605
+ this.isTrusted = nativeEvent.isTrusted;
606
+ this.timeStamp = nativeEvent.timeStamp;
607
+ this.type = type;
608
+ }
609
+ }
610
+ function $8a9cb279dc87e130$export$715c682d09d639cc(onBlur) {
611
+ let stateRef = $bx7SL$useRef({
612
+ isFocused: false,
613
+ onBlur: onBlur,
614
+ observer: null
615
+ });
616
+ stateRef.current.onBlur = onBlur;
617
+ // Clean up MutationObserver on unmount. See below.
618
+ // eslint-disable-next-line arrow-body-style
619
+ $bx7SL$useLayoutEffect(()=>{
620
+ const state = stateRef.current;
621
+ return ()=>{
622
+ if (state.observer) {
623
+ state.observer.disconnect();
624
+ state.observer = null;
625
+ }
626
+ };
627
+ }, []);
628
+ // This function is called during a React onFocus event.
629
+ return $bx7SL$useCallback((e1)=>{
630
+ // React does not fire onBlur when an element is disabled. https://github.com/facebook/react/issues/9142
631
+ // Most browsers fire a native focusout event in this case, except for Firefox. In that case, we use a
632
+ // MutationObserver to watch for the disabled attribute, and dispatch these events ourselves.
633
+ // For browsers that do, focusout fires before the MutationObserver, so onBlur should not fire twice.
634
+ if (e1.target instanceof HTMLButtonElement || e1.target instanceof HTMLInputElement || e1.target instanceof HTMLTextAreaElement || e1.target instanceof HTMLSelectElement) {
635
+ stateRef.current.isFocused = true;
636
+ let target = e1.target;
637
+ let onBlurHandler = (e)=>{
638
+ var // For backward compatibility, dispatch a (fake) React synthetic event.
639
+ _current, ref;
640
+ stateRef.current.isFocused = false;
641
+ if (target.disabled) (ref = (_current = stateRef.current).onBlur) === null || ref === void 0 ? void 0 : ref.call(_current, new $8a9cb279dc87e130$export$905e7fc544a71f36('blur', e));
642
+ // We no longer need the MutationObserver once the target is blurred.
643
+ if (stateRef.current.observer) {
644
+ stateRef.current.observer.disconnect();
645
+ stateRef.current.observer = null;
646
+ }
647
+ };
648
+ target.addEventListener('focusout', onBlurHandler, {
649
+ once: true
650
+ });
651
+ stateRef.current.observer = new MutationObserver(()=>{
652
+ if (stateRef.current.isFocused && target.disabled) {
653
+ stateRef.current.observer.disconnect();
654
+ target.dispatchEvent(new FocusEvent('blur'));
655
+ target.dispatchEvent(new FocusEvent('focusout', {
656
+ bubbles: true
657
+ }));
658
+ }
659
+ });
660
+ stateRef.current.observer.observe(target, {
661
+ attributes: true,
662
+ attributeFilter: [
663
+ 'disabled'
664
+ ]
665
+ });
666
+ }
667
+ }, []);
668
+ }
669
+
670
+
667
671
  function $a1ea59d68270f0dd$export$f8168d8dd8fd66e6(props) {
668
672
  let { isDisabled: isDisabled , onFocus: onFocusProp , onBlur: onBlurProp , onFocusChange: onFocusChange } = props;
669
673
  const onBlur = $bx7SL$useCallback((e)=>{
@@ -699,7 +703,6 @@ function $a1ea59d68270f0dd$export$f8168d8dd8fd66e6(props) {
699
703
 
700
704
 
701
705
 
702
-
703
706
  let $507fabe10e71c6fb$var$currentModality = null;
704
707
  let $507fabe10e71c6fb$var$changeHandlers = new Set();
705
708
  let $507fabe10e71c6fb$var$hasSetupGlobalListeners = false;
@@ -734,7 +737,7 @@ function $507fabe10e71c6fb$var$handlePointerEvent(e) {
734
737
  }
735
738
  }
736
739
  function $507fabe10e71c6fb$var$handleClickEvent(e) {
737
- if ($8a9cb279dc87e130$export$60278871457622de(e)) {
740
+ if ($bx7SL$isVirtualClick(e)) {
738
741
  $507fabe10e71c6fb$var$hasEventBeforeFocus = true;
739
742
  $507fabe10e71c6fb$var$currentModality = 'virtual';
740
743
  }