@react-aria/interactions 3.10.0 → 3.11.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
@@ -268,8 +268,8 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
268
268
  };
269
269
  let pressProps = {
270
270
  onKeyDown (e) {
271
- if ($f6c31cce2adf654f$var$isValidKeyboardEvent(e.nativeEvent) && e.currentTarget.contains(e.target)) {
272
- if ($f6c31cce2adf654f$var$shouldPreventDefaultKeyboard(e.target)) e.preventDefault();
271
+ if ($f6c31cce2adf654f$var$isValidKeyboardEvent(e.nativeEvent, e.currentTarget) && e.currentTarget.contains(e.target)) {
272
+ if ($f6c31cce2adf654f$var$shouldPreventDefaultKeyboard(e.target, e.key)) e.preventDefault();
273
273
  e.stopPropagation();
274
274
  // If the event is repeating, it may have started on a different element
275
275
  // after which focus moved to the current element. Ignore these events and
@@ -282,10 +282,13 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
282
282
  // instead of the same element where the key down event occurred.
283
283
  addGlobalListener(document, 'keyup', onKeyUp, false);
284
284
  }
285
- }
285
+ } 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
286
+ // browser behavior to open the link when pressing Enter. But we still need to prevent
287
+ // default so that elements above do not also handle it (e.g. table row).
288
+ e.stopPropagation();
286
289
  },
287
290
  onKeyUp (e) {
288
- if ($f6c31cce2adf654f$var$isValidKeyboardEvent(e.nativeEvent) && !e.repeat && e.currentTarget.contains(e.target)) triggerPressUp($f6c31cce2adf654f$var$createEvent(state.target, e), 'keyboard');
291
+ if ($f6c31cce2adf654f$var$isValidKeyboardEvent(e.nativeEvent, e.currentTarget) && !e.repeat && e.currentTarget.contains(e.target)) triggerPressUp($f6c31cce2adf654f$var$createEvent(state.target, e), 'keyboard');
289
292
  },
290
293
  onClick (e) {
291
294
  if (e && !e.currentTarget.contains(e.target)) return;
@@ -307,8 +310,8 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
307
310
  }
308
311
  };
309
312
  let onKeyUp = (e)=>{
310
- if (state.isPressed && $f6c31cce2adf654f$var$isValidKeyboardEvent(e)) {
311
- if ($f6c31cce2adf654f$var$shouldPreventDefaultKeyboard(e.target)) e.preventDefault();
313
+ if (state.isPressed && $f6c31cce2adf654f$var$isValidKeyboardEvent(e, state.target)) {
314
+ if ($f6c31cce2adf654f$var$shouldPreventDefaultKeyboard(e.target, e.key)) e.preventDefault();
312
315
  e.stopPropagation();
313
316
  state.isPressed = false;
314
317
  let target = e.target;
@@ -316,7 +319,7 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
316
319
  removeAllGlobalListeners();
317
320
  // If the target is a link, trigger the click method to open the URL,
318
321
  // 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();
322
+ if (state.target instanceof HTMLElement && state.target.contains(target) && ($f6c31cce2adf654f$var$isHTMLAnchorLink(state.target) || state.target.getAttribute('role') === 'link')) state.target.click();
320
323
  }
321
324
  };
322
325
  if (typeof PointerEvent !== 'undefined') {
@@ -548,14 +551,13 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
548
551
  function $f6c31cce2adf654f$var$isHTMLAnchorLink(target) {
549
552
  return target.tagName === 'A' && target.hasAttribute('href');
550
553
  }
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;
554
+ function $f6c31cce2adf654f$var$isValidKeyboardEvent(event, currentTarget) {
555
+ const { key: key , code: code } = event;
556
+ const element = currentTarget;
555
557
  const role = element.getAttribute('role');
556
558
  // Accessibility for keyboards. Space and Enter only.
557
559
  // "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
560
+ 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
561
  !(role === 'link' && key !== 'Enter');
560
562
  }
561
563
  function $f6c31cce2adf654f$var$getTouchFromEvent(event) {
@@ -606,8 +608,25 @@ function $f6c31cce2adf654f$var$shouldPreventDefault(target) {
606
608
  // We cannot prevent default if the target is a draggable element.
607
609
  return !(target instanceof HTMLElement) || !target.draggable;
608
610
  }
609
- function $f6c31cce2adf654f$var$shouldPreventDefaultKeyboard(target) {
610
- return !((target.tagName === 'INPUT' || target.tagName === 'BUTTON') && target.type === 'submit');
611
+ function $f6c31cce2adf654f$var$shouldPreventDefaultKeyboard(target, key) {
612
+ if (target instanceof HTMLInputElement) return !$f6c31cce2adf654f$var$isValidInputKey(target, key);
613
+ if (target instanceof HTMLButtonElement) return target.type !== 'submit';
614
+ return true;
615
+ }
616
+ const $f6c31cce2adf654f$var$nonTextInputTypes = new Set([
617
+ 'checkbox',
618
+ 'radio',
619
+ 'range',
620
+ 'color',
621
+ 'file',
622
+ 'image',
623
+ 'button',
624
+ 'submit',
625
+ 'reset'
626
+ ]);
627
+ function $f6c31cce2adf654f$var$isValidInputKey(target, key) {
628
+ // Only space should toggle checkboxes and radios, not enter.
629
+ return target.type === 'checkbox' || target.type === 'radio' ? key === ' ' : $f6c31cce2adf654f$var$nonTextInputTypes.has(target.type);
611
630
  }
612
631
  function $f6c31cce2adf654f$var$isVirtualPointerEvent(event) {
613
632
  // If the pointer size is zero, then we assume it's from a screen reader.