@testing-library/user-event 14.5.2 → 14.6.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.
Files changed (136) hide show
  1. package/dist/cjs/clipboard/copy.js +1 -7
  2. package/dist/cjs/clipboard/cut.js +1 -7
  3. package/dist/cjs/clipboard/paste.js +2 -8
  4. package/dist/cjs/convenience/hover.js +0 -5
  5. package/dist/cjs/document/UI.js +3 -3
  6. package/dist/cjs/document/copySelection.js +0 -6
  7. package/dist/cjs/document/getValueOrTextContent.js +0 -6
  8. package/dist/cjs/document/interceptor.js +5 -11
  9. package/dist/cjs/document/patchFocus.js +104 -0
  10. package/dist/cjs/document/prepareDocument.js +1 -7
  11. package/dist/cjs/document/trackValue.js +2 -8
  12. package/dist/cjs/event/behavior/click.js +1 -7
  13. package/dist/cjs/event/behavior/cut.js +0 -5
  14. package/dist/cjs/event/behavior/keydown.js +3 -8
  15. package/dist/cjs/event/behavior/keypress.js +2 -7
  16. package/dist/cjs/event/behavior/keyup.js +1 -6
  17. package/dist/cjs/event/behavior/paste.js +1 -6
  18. package/dist/cjs/event/createEvent.js +34 -27
  19. package/dist/cjs/event/dispatchEvent.js +1 -1
  20. package/dist/cjs/event/eventMap.js +32 -0
  21. package/dist/cjs/event/focus.js +5 -9
  22. package/dist/cjs/event/index.js +0 -6
  23. package/dist/cjs/event/input.js +2 -7
  24. package/dist/cjs/event/radio.js +0 -6
  25. package/dist/cjs/event/selection/getInputRange.js +1 -1
  26. package/dist/cjs/event/selection/getTargetTypeAndSelection.js +2 -8
  27. package/dist/cjs/event/selection/modifySelection.js +1 -7
  28. package/dist/cjs/event/selection/modifySelectionPerMouse.js +2 -8
  29. package/dist/cjs/event/selection/moveSelection.js +1 -7
  30. package/dist/cjs/event/selection/resolveCaretPosition.js +4 -10
  31. package/dist/cjs/event/selection/selectAll.js +3 -9
  32. package/dist/cjs/event/selection/setSelection.js +1 -7
  33. package/dist/cjs/event/selection/setSelectionPerMouse.js +7 -13
  34. package/dist/cjs/event/selection/setSelectionRange.js +1 -7
  35. package/dist/cjs/event/selection/updateSelectionOnFocus.js +6 -8
  36. package/dist/cjs/index.js +1 -4
  37. package/dist/cjs/keyboard/index.js +0 -6
  38. package/dist/cjs/keyboard/parseKeyDef.js +3 -8
  39. package/dist/cjs/options.js +5 -3
  40. package/dist/cjs/pointer/index.js +6 -11
  41. package/dist/cjs/pointer/parseKeyDef.js +0 -5
  42. package/dist/cjs/setup/setup.js +7 -7
  43. package/dist/cjs/system/keyboard.js +47 -25
  44. package/dist/cjs/system/pointer/index.js +18 -20
  45. package/dist/cjs/system/pointer/mouse.js +8 -14
  46. package/dist/cjs/system/pointer/pointer.js +4 -9
  47. package/dist/cjs/system/pointer/shared.js +2 -2
  48. package/dist/cjs/utility/clear.js +0 -5
  49. package/dist/cjs/utility/selectOptions.js +1 -6
  50. package/dist/cjs/utility/type.js +1 -7
  51. package/dist/cjs/utility/upload.js +4 -10
  52. package/dist/cjs/utils/click/isClickableInput.js +3 -3
  53. package/dist/cjs/utils/dataTransfer/Clipboard.js +5 -6
  54. package/dist/cjs/utils/dataTransfer/DataTransfer.js +6 -10
  55. package/dist/cjs/utils/edit/isEditable.js +3 -3
  56. package/dist/cjs/utils/edit/maxLength.js +4 -4
  57. package/dist/cjs/utils/edit/setFiles.js +2 -2
  58. package/dist/cjs/utils/focus/cursor.js +1 -1
  59. package/dist/cjs/utils/focus/getActiveElement.js +2 -2
  60. package/dist/cjs/utils/index.js +1 -4
  61. package/dist/cjs/utils/keyDef/readNextDescriptor.js +6 -6
  62. package/dist/cjs/utils/misc/getWindow.js +1 -1
  63. package/dist/cjs/utils/misc/isDisabled.js +1 -1
  64. package/dist/cjs/utils/misc/isVisible.js +1 -1
  65. package/dist/cjs/utils/misc/level.js +4 -3
  66. package/dist/cjs/utils/pointer/cssPointerEvents.js +11 -11
  67. package/dist/esm/clipboard/copy.js +1 -7
  68. package/dist/esm/clipboard/cut.js +1 -7
  69. package/dist/esm/clipboard/paste.js +2 -8
  70. package/dist/esm/convenience/hover.js +0 -5
  71. package/dist/esm/document/UI.js +3 -3
  72. package/dist/esm/document/copySelection.js +0 -6
  73. package/dist/esm/document/getValueOrTextContent.js +0 -6
  74. package/dist/esm/document/interceptor.js +5 -11
  75. package/dist/esm/document/patchFocus.js +101 -0
  76. package/dist/esm/document/prepareDocument.js +1 -7
  77. package/dist/esm/document/trackValue.js +2 -8
  78. package/dist/esm/event/behavior/click.js +1 -7
  79. package/dist/esm/event/behavior/cut.js +0 -5
  80. package/dist/esm/event/behavior/keydown.js +3 -8
  81. package/dist/esm/event/behavior/keypress.js +2 -7
  82. package/dist/esm/event/behavior/keyup.js +1 -6
  83. package/dist/esm/event/behavior/paste.js +1 -6
  84. package/dist/esm/event/createEvent.js +34 -27
  85. package/dist/esm/event/dispatchEvent.js +1 -1
  86. package/dist/esm/event/eventMap.js +32 -0
  87. package/dist/esm/event/focus.js +5 -9
  88. package/dist/esm/event/index.js +0 -6
  89. package/dist/esm/event/input.js +2 -7
  90. package/dist/esm/event/radio.js +0 -6
  91. package/dist/esm/event/selection/getInputRange.js +1 -1
  92. package/dist/esm/event/selection/getTargetTypeAndSelection.js +2 -8
  93. package/dist/esm/event/selection/modifySelection.js +1 -7
  94. package/dist/esm/event/selection/modifySelectionPerMouse.js +2 -8
  95. package/dist/esm/event/selection/moveSelection.js +1 -7
  96. package/dist/esm/event/selection/resolveCaretPosition.js +4 -10
  97. package/dist/esm/event/selection/selectAll.js +3 -9
  98. package/dist/esm/event/selection/setSelection.js +1 -7
  99. package/dist/esm/event/selection/setSelectionPerMouse.js +7 -13
  100. package/dist/esm/event/selection/setSelectionRange.js +1 -7
  101. package/dist/esm/event/selection/updateSelectionOnFocus.js +6 -8
  102. package/dist/esm/keyboard/index.js +0 -6
  103. package/dist/esm/keyboard/parseKeyDef.js +3 -8
  104. package/dist/esm/options.js +3 -3
  105. package/dist/esm/pointer/index.js +6 -11
  106. package/dist/esm/pointer/parseKeyDef.js +0 -5
  107. package/dist/esm/setup/setup.js +7 -7
  108. package/dist/esm/system/keyboard.js +46 -25
  109. package/dist/esm/system/pointer/index.js +18 -20
  110. package/dist/esm/system/pointer/mouse.js +8 -14
  111. package/dist/esm/system/pointer/pointer.js +4 -9
  112. package/dist/esm/system/pointer/shared.js +2 -2
  113. package/dist/esm/utility/clear.js +0 -5
  114. package/dist/esm/utility/selectOptions.js +1 -6
  115. package/dist/esm/utility/type.js +1 -7
  116. package/dist/esm/utility/upload.js +4 -10
  117. package/dist/esm/utils/click/isClickableInput.js +3 -3
  118. package/dist/esm/utils/dataTransfer/Clipboard.js +5 -6
  119. package/dist/esm/utils/dataTransfer/DataTransfer.js +6 -10
  120. package/dist/esm/utils/edit/isEditable.js +3 -3
  121. package/dist/esm/utils/edit/maxLength.js +4 -4
  122. package/dist/esm/utils/edit/setFiles.js +2 -2
  123. package/dist/esm/utils/focus/cursor.js +1 -1
  124. package/dist/esm/utils/focus/getActiveElement.js +2 -2
  125. package/dist/esm/utils/keyDef/readNextDescriptor.js +6 -6
  126. package/dist/esm/utils/misc/getWindow.js +1 -1
  127. package/dist/esm/utils/misc/isDisabled.js +1 -1
  128. package/dist/esm/utils/misc/isVisible.js +1 -1
  129. package/dist/esm/utils/misc/level.js +3 -3
  130. package/dist/esm/utils/pointer/cssPointerEvents.js +11 -11
  131. package/dist/types/document/patchFocus.d.ts +9 -0
  132. package/dist/types/event/eventMap.d.ts +32 -0
  133. package/dist/types/event/types.d.ts +1 -1
  134. package/dist/types/system/keyboard.d.ts +1 -4
  135. package/dist/types/utils/dataTransfer/DataTransfer.d.ts +1 -1
  136. package/package.json +3 -3
@@ -14,7 +14,7 @@ function restoreProperty(obj, prop, descriptor) {
14
14
  }
15
15
  function setFiles(el, files) {
16
16
  var _el_fakeFiles;
17
- (_el_fakeFiles = el[fakeFiles]) === null || _el_fakeFiles === void 0 ? void 0 : _el_fakeFiles.restore();
17
+ (_el_fakeFiles = el[fakeFiles]) === null || _el_fakeFiles === undefined ? undefined : _el_fakeFiles.restore();
18
18
  const typeDescr = Object.getOwnPropertyDescriptor(el, 'type');
19
19
  const valueDescr = Object.getOwnPropertyDescriptor(el, 'value');
20
20
  const filesDescr = Object.getOwnPropertyDescriptor(el, 'files');
@@ -39,7 +39,7 @@ function setFiles(el, files) {
39
39
  restore();
40
40
  } else {
41
41
  var _valueDescr_set;
42
- valueDescr === null || valueDescr === void 0 ? void 0 : (_valueDescr_set = valueDescr.set) === null || _valueDescr_set === void 0 ? void 0 : _valueDescr_set.call(el, v);
42
+ valueDescr === null || valueDescr === undefined ? undefined : (_valueDescr_set = valueDescr.set) === null || _valueDescr_set === undefined ? undefined : _valueDescr_set.call(el, v);
43
43
  }
44
44
  }
45
45
  },
@@ -109,7 +109,7 @@ function walkNodes(node, direction, callback) {
109
109
  if (callback(node)) {
110
110
  return node;
111
111
  }
112
- } else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable.isContentEditable(node.parentNode) && node.parentNode !== ((_node_ownerDocument = node.ownerDocument) === null || _node_ownerDocument === void 0 ? void 0 : _node_ownerDocument.body))) {
112
+ } else if (node.parentNode && (!isElement(node.parentNode) || !isContentEditable.isContentEditable(node.parentNode) && node.parentNode !== ((_node_ownerDocument = node.ownerDocument) === null || _node_ownerDocument === undefined ? undefined : _node_ownerDocument.body))) {
113
113
  node = node.parentNode;
114
114
  } else {
115
115
  break;
@@ -4,7 +4,7 @@ var isDisabled = require('../misc/isDisabled.js');
4
4
 
5
5
  function getActiveElement(document) {
6
6
  const activeElement = document.activeElement;
7
- if (activeElement === null || activeElement === void 0 ? void 0 : activeElement.shadowRoot) {
7
+ if (activeElement === null || activeElement === undefined ? undefined : activeElement.shadowRoot) {
8
8
  return getActiveElement(activeElement.shadowRoot);
9
9
  } else {
10
10
  // Browser does not yield disabled elements as document.activeElement - jsdom does
@@ -16,7 +16,7 @@ function getActiveElement(document) {
16
16
  }
17
17
  function getActiveElementOrBody(document) {
18
18
  var _getActiveElement;
19
- return (_getActiveElement = getActiveElement(document)) !== null && _getActiveElement !== void 0 ? _getActiveElement : /* istanbul ignore next */ document.body;
19
+ return (_getActiveElement = getActiveElement(document)) !== null && _getActiveElement !== undefined ? _getActiveElement : /* istanbul ignore next */ document.body;
20
20
  }
21
21
 
22
22
  exports.getActiveElement = getActiveElement;
@@ -70,10 +70,7 @@ exports.isDescendantOrSelf = isDescendantOrSelf.isDescendantOrSelf;
70
70
  exports.isElementType = isElementType.isElementType;
71
71
  exports.isVisible = isVisible.isVisible;
72
72
  exports.isDisabled = isDisabled.isDisabled;
73
- Object.defineProperty(exports, "ApiLevel", {
74
- enumerable: true,
75
- get: function () { return level.ApiLevel; }
76
- });
73
+ exports.ApiLevel = level.ApiLevel;
77
74
  exports.getLevelRef = level.getLevelRef;
78
75
  exports.setLevelRef = level.setLevelRef;
79
76
  exports.wait = wait.wait;
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var bracketDict;
4
- (function(bracketDict) {
3
+ var bracketDict = /*#__PURE__*/ function(bracketDict) {
5
4
  bracketDict["{"] = "}";
6
5
  bracketDict["["] = "]";
7
- })(bracketDict || (bracketDict = {}));
6
+ return bracketDict;
7
+ }(bracketDict || {});
8
8
  /**
9
9
  * Read the next key definition from user input
10
10
  *
@@ -44,11 +44,11 @@ function readTag(text, pos, startBracket, context) {
44
44
  pos += releasePreviousModifier.length;
45
45
  const escapedDescriptor = startBracket === '{' && text[pos] === '\\';
46
46
  pos += Number(escapedDescriptor);
47
- const descriptor = escapedDescriptor ? text[pos] : (_text_slice_match = text.slice(pos).match(startBracket === '{' ? /^\w+|^[^}>/]/ : /^\w+/)) === null || _text_slice_match === void 0 ? void 0 : _text_slice_match[0];
47
+ const descriptor = escapedDescriptor ? text[pos] : (_text_slice_match = text.slice(pos).match(startBracket === '{' ? /^\w+|^[^}>/]/ : /^\w+/)) === null || _text_slice_match === undefined ? undefined : _text_slice_match[0];
48
48
  assertDescriptor(descriptor, text, pos, context);
49
49
  pos += descriptor.length;
50
50
  var _text_slice_match_;
51
- const repeatModifier = (_text_slice_match_ = (_text_slice_match1 = text.slice(pos).match(/^>\d+/)) === null || _text_slice_match1 === void 0 ? void 0 : _text_slice_match1[0]) !== null && _text_slice_match_ !== void 0 ? _text_slice_match_ : '';
51
+ const repeatModifier = (_text_slice_match_ = (_text_slice_match1 = text.slice(pos).match(/^>\d+/)) === null || _text_slice_match1 === undefined ? undefined : _text_slice_match1[0]) !== null && _text_slice_match_ !== undefined ? _text_slice_match_ : '';
52
52
  pos += repeatModifier.length;
53
53
  const releaseSelfModifier = text[pos] === '/' || !repeatModifier && text[pos] === '>' ? text[pos] : '';
54
54
  pos += releaseSelfModifier.length;
@@ -84,7 +84,7 @@ function hasReleaseSelf(releaseSelfModifier, repeatModifier) {
84
84
  }
85
85
  }
86
86
  function getErrorMessage(expected, found, text, context) {
87
- return `Expected ${expected} but found "${found !== null && found !== void 0 ? found : ''}" in "${text}"
87
+ return `Expected ${expected} but found "${found !== null && found !== undefined ? found : ''}" in "${text}"
88
88
  See ${context === 'pointer' ? `https://testing-library.com/docs/user-event/pointer#pressing-a-button-or-touching-the-screen` : `https://testing-library.com/docs/user-event/keyboard`}
89
89
  for more information about how userEvent parses your input.`;
90
90
  }
@@ -4,7 +4,7 @@ function getWindow(node) {
4
4
  var _node_ownerDocument;
5
5
  if (isDocument(node) && node.defaultView) {
6
6
  return node.defaultView;
7
- } else if ((_node_ownerDocument = node.ownerDocument) === null || _node_ownerDocument === void 0 ? void 0 : _node_ownerDocument.defaultView) {
7
+ } else if ((_node_ownerDocument = node.ownerDocument) === null || _node_ownerDocument === undefined ? undefined : _node_ownerDocument.defaultView) {
8
8
  return node.ownerDocument.defaultView;
9
9
  }
10
10
  throw new Error(`Could not determine window of node. Node was ${describe(node)}`);
@@ -18,7 +18,7 @@ function isDisabled(element) {
18
18
  }
19
19
  } else if (isElementType.isElementType(el, 'fieldset')) {
20
20
  var _el_querySelector;
21
- if (el.hasAttribute('disabled') && !((_el_querySelector = el.querySelector(':scope > legend')) === null || _el_querySelector === void 0 ? void 0 : _el_querySelector.contains(element))) {
21
+ if (el.hasAttribute('disabled') && !((_el_querySelector = el.querySelector(':scope > legend')) === null || _el_querySelector === undefined ? undefined : _el_querySelector.contains(element))) {
22
22
  return true;
23
23
  }
24
24
  } else if (el.tagName.includes('-')) {
@@ -4,7 +4,7 @@ var getWindow = require('./getWindow.js');
4
4
 
5
5
  function isVisible(element) {
6
6
  const window = getWindow.getWindow(element);
7
- for(let el = element; el === null || el === void 0 ? void 0 : el.ownerDocument; el = el.parentElement){
7
+ for(let el = element; el === null || el === undefined ? undefined : el.ownerDocument; el = el.parentElement){
8
8
  const { display, visibility } = window.getComputedStyle(el);
9
9
  if (display === 'none') {
10
10
  return false;
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- exports.ApiLevel = void 0;
4
- (function(ApiLevel) {
3
+ var ApiLevel = /*#__PURE__*/ function(ApiLevel) {
5
4
  ApiLevel[ApiLevel["Trigger"] = 2] = "Trigger";
6
5
  ApiLevel[ApiLevel["Call"] = 1] = "Call";
7
- })(exports.ApiLevel || (exports.ApiLevel = {}));
6
+ return ApiLevel;
7
+ }({});
8
8
  function setLevelRef(instance, level) {
9
9
  instance.levelRefs[level] = {};
10
10
  }
@@ -12,5 +12,6 @@ function getLevelRef(instance, level) {
12
12
  return instance.levelRefs[level];
13
13
  }
14
14
 
15
+ exports.ApiLevel = ApiLevel;
15
16
  exports.getLevelRef = getLevelRef;
16
17
  exports.setLevelRef = setLevelRef;
@@ -7,11 +7,11 @@ var level = require('../misc/level.js');
7
7
 
8
8
  function hasPointerEvents(instance, element) {
9
9
  var _checkPointerEvents;
10
- return ((_checkPointerEvents = checkPointerEvents(instance, element)) === null || _checkPointerEvents === void 0 ? void 0 : _checkPointerEvents.pointerEvents) !== 'none';
10
+ return ((_checkPointerEvents = checkPointerEvents(instance, element)) === null || _checkPointerEvents === undefined ? undefined : _checkPointerEvents.pointerEvents) !== 'none';
11
11
  }
12
12
  function closestPointerEventsDeclaration(element) {
13
13
  const window = getWindow.getWindow(element);
14
- for(let el = element, tree = []; el === null || el === void 0 ? void 0 : el.ownerDocument; el = el.parentElement){
14
+ for(let el = element, tree = []; el === null || el === undefined ? undefined : el.ownerDocument; el = el.parentElement){
15
15
  tree.push(el);
16
16
  const pointerEvents = window.getComputedStyle(el).pointerEvents;
17
17
  if (pointerEvents && ![
@@ -31,7 +31,7 @@ function checkPointerEvents(instance, element) {
31
31
  const lastCheck = element[PointerEventsCheck];
32
32
  const needsCheck = instance.config.pointerEventsCheck !== options.PointerEventsCheckLevel.Never && (!lastCheck || hasBitFlag(instance.config.pointerEventsCheck, options.PointerEventsCheckLevel.EachApiCall) && lastCheck[level.ApiLevel.Call] !== level.getLevelRef(instance, level.ApiLevel.Call) || hasBitFlag(instance.config.pointerEventsCheck, options.PointerEventsCheckLevel.EachTrigger) && lastCheck[level.ApiLevel.Trigger] !== level.getLevelRef(instance, level.ApiLevel.Trigger));
33
33
  if (!needsCheck) {
34
- return lastCheck === null || lastCheck === void 0 ? void 0 : lastCheck.result;
34
+ return lastCheck === null || lastCheck === undefined ? undefined : lastCheck.result;
35
35
  }
36
36
  const declaration = closestPointerEventsDeclaration(element);
37
37
  element[PointerEventsCheck] = {
@@ -43,7 +43,7 @@ function checkPointerEvents(instance, element) {
43
43
  }
44
44
  function assertPointerEvents(instance, element) {
45
45
  const declaration = checkPointerEvents(instance, element);
46
- if ((declaration === null || declaration === void 0 ? void 0 : declaration.pointerEvents) === 'none') {
46
+ if ((declaration === null || declaration === undefined ? undefined : declaration.pointerEvents) === 'none') {
47
47
  throw new Error([
48
48
  `Unable to perform pointer interaction as the element ${declaration.tree.length > 1 ? 'inherits' : 'has'} \`pointer-events: none\`:`,
49
49
  '',
@@ -69,7 +69,7 @@ function getLabelDescr(element) {
69
69
  label = element.getAttribute('aria-label');
70
70
  } else if (element.hasAttribute('aria-labelledby')) {
71
71
  var _element_ownerDocument_getElementById_textContent, _element_ownerDocument_getElementById;
72
- label = (_element_ownerDocument_getElementById = element.ownerDocument.getElementById(element.getAttribute('aria-labelledby'))) === null || _element_ownerDocument_getElementById === void 0 ? void 0 : (_element_ownerDocument_getElementById_textContent = _element_ownerDocument_getElementById.textContent) === null || _element_ownerDocument_getElementById_textContent === void 0 ? void 0 : _element_ownerDocument_getElementById_textContent.trim();
72
+ label = (_element_ownerDocument_getElementById = element.ownerDocument.getElementById(element.getAttribute('aria-labelledby'))) === null || _element_ownerDocument_getElementById === undefined ? undefined : (_element_ownerDocument_getElementById_textContent = _element_ownerDocument_getElementById.textContent) === null || _element_ownerDocument_getElementById_textContent === undefined ? undefined : _element_ownerDocument_getElementById_textContent.trim();
73
73
  } else if (isElementType.isElementType(element, [
74
74
  'button',
75
75
  'input',
@@ -78,18 +78,18 @@ function getLabelDescr(element) {
78
78
  'progress',
79
79
  'select',
80
80
  'textarea'
81
- ]) && ((_element_labels = element.labels) === null || _element_labels === void 0 ? void 0 : _element_labels.length)) {
81
+ ]) && ((_element_labels = element.labels) === null || _element_labels === undefined ? undefined : _element_labels.length)) {
82
82
  label = Array.from(element.labels).map((el)=>{
83
83
  var _el_textContent;
84
- return (_el_textContent = el.textContent) === null || _el_textContent === void 0 ? void 0 : _el_textContent.trim();
84
+ return (_el_textContent = el.textContent) === null || _el_textContent === undefined ? undefined : _el_textContent.trim();
85
85
  }).join('|');
86
86
  } else if (isElementType.isElementType(element, 'button')) {
87
87
  var _element_textContent;
88
- label = (_element_textContent = element.textContent) === null || _element_textContent === void 0 ? void 0 : _element_textContent.trim();
88
+ label = (_element_textContent = element.textContent) === null || _element_textContent === undefined ? undefined : _element_textContent.trim();
89
89
  }
90
- label = label === null || label === void 0 ? void 0 : label.replace(/\n/g, ' ');
91
- if (Number(label === null || label === void 0 ? void 0 : label.length) > 30) {
92
- label = `${label === null || label === void 0 ? void 0 : label.substring(0, 29)}…`;
90
+ label = label === null || label === undefined ? undefined : label.replace(/\n/g, ' ');
91
+ if (Number(label === null || label === undefined ? undefined : label.length) > 30) {
92
+ label = `${label === null || label === undefined ? undefined : label.substring(0, 29)}…`;
93
93
  }
94
94
  return label ? `(label=${label})` : '';
95
95
  }
@@ -1,16 +1,10 @@
1
- import '../utils/click/isClickableInput.js';
2
1
  import { writeDataTransferToClipboard } from '../utils/dataTransfer/Clipboard.js';
3
- import '../utils/edit/isEditable.js';
4
- import '../utils/edit/maxLength.js';
5
- import '../utils/keyDef/readNextDescriptor.js';
6
- import '../utils/misc/level.js';
7
- import '../options.js';
8
2
  import { copySelection } from '../document/copySelection.js';
9
3
 
10
4
  async function copy() {
11
5
  const doc = this.config.document;
12
6
  var _doc_activeElement;
13
- const target = (_doc_activeElement = doc.activeElement) !== null && _doc_activeElement !== void 0 ? _doc_activeElement : /* istanbul ignore next */ doc.body;
7
+ const target = (_doc_activeElement = doc.activeElement) !== null && _doc_activeElement !== undefined ? _doc_activeElement : /* istanbul ignore next */ doc.body;
14
8
  const clipboardData = copySelection(target);
15
9
  if (clipboardData.items.length === 0) {
16
10
  return;
@@ -1,16 +1,10 @@
1
- import '../utils/click/isClickableInput.js';
2
1
  import { writeDataTransferToClipboard } from '../utils/dataTransfer/Clipboard.js';
3
- import '../utils/edit/isEditable.js';
4
- import '../utils/edit/maxLength.js';
5
- import '../utils/keyDef/readNextDescriptor.js';
6
- import '../utils/misc/level.js';
7
- import '../options.js';
8
2
  import { copySelection } from '../document/copySelection.js';
9
3
 
10
4
  async function cut() {
11
5
  const doc = this.config.document;
12
6
  var _doc_activeElement;
13
- const target = (_doc_activeElement = doc.activeElement) !== null && _doc_activeElement !== void 0 ? _doc_activeElement : /* istanbul ignore next */ doc.body;
7
+ const target = (_doc_activeElement = doc.activeElement) !== null && _doc_activeElement !== undefined ? _doc_activeElement : /* istanbul ignore next */ doc.body;
14
8
  const clipboardData = copySelection(target);
15
9
  if (clipboardData.items.length === 0) {
16
10
  return;
@@ -1,19 +1,13 @@
1
- import '../utils/click/isClickableInput.js';
2
1
  import { createDataTransfer } from '../utils/dataTransfer/DataTransfer.js';
3
2
  import { readDataTransferFromClipboard } from '../utils/dataTransfer/Clipboard.js';
4
- import '../utils/edit/isEditable.js';
5
- import '../utils/edit/maxLength.js';
6
3
  import { getWindow } from '../utils/misc/getWindow.js';
7
- import '../utils/keyDef/readNextDescriptor.js';
8
- import '../utils/misc/level.js';
9
- import '../options.js';
10
4
 
11
5
  async function paste(clipboardData) {
12
6
  const doc = this.config.document;
13
7
  var _doc_activeElement;
14
- const target = (_doc_activeElement = doc.activeElement) !== null && _doc_activeElement !== void 0 ? _doc_activeElement : /* istanbul ignore next */ doc.body;
8
+ const target = (_doc_activeElement = doc.activeElement) !== null && _doc_activeElement !== undefined ? _doc_activeElement : /* istanbul ignore next */ doc.body;
15
9
  var _ref;
16
- const dataTransfer = (_ref = typeof clipboardData === 'string' ? getClipboardDataFromString(doc, clipboardData) : clipboardData) !== null && _ref !== void 0 ? _ref : await readDataTransferFromClipboard(doc).catch(()=>{
10
+ const dataTransfer = (_ref = typeof clipboardData === 'string' ? getClipboardDataFromString(doc, clipboardData) : clipboardData) !== null && _ref !== undefined ? _ref : await readDataTransferFromClipboard(doc).catch(()=>{
17
11
  throw new Error('`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.');
18
12
  });
19
13
  this.dispatchUIEvent(target, 'paste', {
@@ -1,9 +1,4 @@
1
- import '../utils/click/isClickableInput.js';
2
1
  import '../utils/dataTransfer/Clipboard.js';
3
- import '../utils/edit/isEditable.js';
4
- import '../utils/edit/maxLength.js';
5
- import '../utils/keyDef/readNextDescriptor.js';
6
- import '../utils/misc/level.js';
7
2
  import { assertPointerEvents } from '../utils/pointer/cssPointerEvents.js';
8
3
 
9
4
  async function hover(element) {
@@ -59,9 +59,9 @@ function setUISelection(element, { focusOffset: focusOffsetParam, anchorOffset:
59
59
  }
60
60
  function getUISelection(element) {
61
61
  var _element_selectionStart, _element_selectionEnd, _element_UISelection;
62
- const sel = (_element_UISelection = element[UISelection]) !== null && _element_UISelection !== void 0 ? _element_UISelection : {
63
- anchorOffset: (_element_selectionStart = element.selectionStart) !== null && _element_selectionStart !== void 0 ? _element_selectionStart : 0,
64
- focusOffset: (_element_selectionEnd = element.selectionEnd) !== null && _element_selectionEnd !== void 0 ? _element_selectionEnd : 0
62
+ const sel = (_element_UISelection = element[UISelection]) !== null && _element_UISelection !== undefined ? _element_UISelection : {
63
+ anchorOffset: (_element_selectionStart = element.selectionStart) !== null && _element_selectionStart !== undefined ? _element_selectionStart : 0,
64
+ focusOffset: (_element_selectionEnd = element.selectionEnd) !== null && _element_selectionEnd !== undefined ? _element_selectionEnd : 0
65
65
  };
66
66
  return {
67
67
  ...sel,
@@ -1,13 +1,7 @@
1
- import '../utils/click/isClickableInput.js';
2
1
  import { createDataTransfer } from '../utils/dataTransfer/DataTransfer.js';
3
2
  import '../utils/dataTransfer/Clipboard.js';
4
- import '../utils/edit/isEditable.js';
5
- import '../utils/edit/maxLength.js';
6
3
  import { getWindow } from '../utils/misc/getWindow.js';
7
4
  import { hasOwnSelection } from '../utils/focus/selection.js';
8
- import '../utils/keyDef/readNextDescriptor.js';
9
- import '../utils/misc/level.js';
10
- import '../options.js';
11
5
  import { getUISelection, getUIValue } from './UI.js';
12
6
 
13
7
  function copySelection(target) {
@@ -1,11 +1,5 @@
1
- import '../utils/click/isClickableInput.js';
2
1
  import '../utils/dataTransfer/Clipboard.js';
3
2
  import { isContentEditable } from '../utils/edit/isContentEditable.js';
4
- import '../utils/edit/isEditable.js';
5
- import '../utils/edit/maxLength.js';
6
- import '../utils/keyDef/readNextDescriptor.js';
7
- import '../utils/misc/level.js';
8
- import '../options.js';
9
3
  import { getUIValue } from './UI.js';
10
4
 
11
5
  function getValueOrTextContent(element) {
@@ -1,11 +1,5 @@
1
- import '../utils/click/isClickableInput.js';
2
- import '../utils/dataTransfer/Clipboard.js';
3
- import '../utils/edit/isEditable.js';
4
- import '../utils/edit/maxLength.js';
5
1
  import { isElementType } from '../utils/misc/isElementType.js';
6
- import '../utils/keyDef/readNextDescriptor.js';
7
- import '../utils/misc/level.js';
8
- import '../options.js';
2
+ import '../utils/dataTransfer/Clipboard.js';
9
3
  import { startTrackValue, trackOrSetValue } from './trackValue.js';
10
4
  import { setUISelectionClean, setUISelectionRaw, getUIValue, setUIValueClean, isUIValue, isUISelectionStart } from './UI.js';
11
5
 
@@ -13,8 +7,8 @@ const Interceptor = Symbol('Interceptor for programmatical calls');
13
7
  function prepareInterceptor(element, propName, interceptorImpl) {
14
8
  const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
15
9
  const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
16
- const target = (prototypeDescriptor === null || prototypeDescriptor === void 0 ? void 0 : prototypeDescriptor.set) ? 'set' : 'value';
17
- /* istanbul ignore if */ if (typeof (prototypeDescriptor === null || prototypeDescriptor === void 0 ? void 0 : prototypeDescriptor[target]) !== 'function' || prototypeDescriptor[target][Interceptor]) {
10
+ const target = (prototypeDescriptor === null || prototypeDescriptor === undefined ? undefined : prototypeDescriptor.set) ? 'set' : 'value';
11
+ /* istanbul ignore if */ if (typeof (prototypeDescriptor === null || prototypeDescriptor === undefined ? undefined : prototypeDescriptor[target]) !== 'function' || prototypeDescriptor[target][Interceptor]) {
18
12
  throw new Error(`Element ${element.tagName} does not implement "${String(propName)}".`);
19
13
  }
20
14
  function intercept(...args) {
@@ -25,11 +19,11 @@ function prepareInterceptor(element, propName, interceptorImpl) {
25
19
  } else {
26
20
  realFunc.call(this, ...realArgs);
27
21
  }
28
- then === null || then === void 0 ? void 0 : then();
22
+ then === null || then === undefined ? undefined : then();
29
23
  }
30
24
  intercept[Interceptor] = Interceptor;
31
25
  Object.defineProperty(element, propName, {
32
- ...objectDescriptor !== null && objectDescriptor !== void 0 ? objectDescriptor : prototypeDescriptor,
26
+ ...objectDescriptor !== null && objectDescriptor !== undefined ? objectDescriptor : prototypeDescriptor,
33
27
  [target]: intercept
34
28
  });
35
29
  }
@@ -0,0 +1,101 @@
1
+ import { dispatchDOMEvent } from '../event/dispatchEvent.js';
2
+ import '../utils/dataTransfer/Clipboard.js';
3
+ import { getActiveElement } from '../utils/focus/getActiveElement.js';
4
+ import '@testing-library/dom';
5
+
6
+ const patched = Symbol('patched focus/blur methods');
7
+ function patchFocus(HTMLElement) {
8
+ if (HTMLElement.prototype[patched]) {
9
+ return;
10
+ }
11
+ // eslint-disable-next-line @typescript-eslint/unbound-method
12
+ const { focus, blur } = HTMLElement.prototype;
13
+ Object.defineProperties(HTMLElement.prototype, {
14
+ focus: {
15
+ configurable: true,
16
+ get: ()=>patchedFocus
17
+ },
18
+ blur: {
19
+ configurable: true,
20
+ get: ()=>patchedBlur
21
+ },
22
+ [patched]: {
23
+ configurable: true,
24
+ get: ()=>({
25
+ focus,
26
+ blur
27
+ })
28
+ }
29
+ });
30
+ let activeCall;
31
+ function patchedFocus(options) {
32
+ if (this.ownerDocument.visibilityState !== 'hidden') {
33
+ return focus.call(this, options);
34
+ }
35
+ const blured = getActiveTarget(this.ownerDocument);
36
+ if (blured === this) {
37
+ return;
38
+ }
39
+ const thisCall = Symbol('focus call');
40
+ activeCall = thisCall;
41
+ if (blured) {
42
+ blur.call(blured);
43
+ dispatchDOMEvent(blured, 'blur', {
44
+ relatedTarget: this
45
+ });
46
+ dispatchDOMEvent(blured, 'focusout', {
47
+ relatedTarget: activeCall === thisCall ? this : null
48
+ });
49
+ }
50
+ if (activeCall === thisCall) {
51
+ focus.call(this, options);
52
+ dispatchDOMEvent(this, 'focus', {
53
+ relatedTarget: blured
54
+ });
55
+ }
56
+ if (activeCall === thisCall) {
57
+ dispatchDOMEvent(this, 'focusin', {
58
+ relatedTarget: blured
59
+ });
60
+ }
61
+ }
62
+ function patchedBlur() {
63
+ if (this.ownerDocument.visibilityState !== 'hidden') {
64
+ return blur.call(this);
65
+ }
66
+ const blured = getActiveTarget(this.ownerDocument);
67
+ if (blured !== this) {
68
+ return;
69
+ }
70
+ const thisCall = Symbol('blur call');
71
+ activeCall = thisCall;
72
+ blur.call(this);
73
+ dispatchDOMEvent(blured, 'blur', {
74
+ relatedTarget: null
75
+ });
76
+ dispatchDOMEvent(blured, 'focusout', {
77
+ relatedTarget: null
78
+ });
79
+ }
80
+ }
81
+ function getActiveTarget(document) {
82
+ const active = getActiveElement(document);
83
+ return (active === null || active === undefined ? undefined : active.tagName) === 'BODY' ? null : active;
84
+ }
85
+ function restoreFocus(HTMLElement) {
86
+ if (HTMLElement.prototype[patched]) {
87
+ const { focus, blur } = HTMLElement.prototype[patched];
88
+ Object.defineProperties(HTMLElement.prototype, {
89
+ focus: {
90
+ configurable: true,
91
+ get: ()=>focus
92
+ },
93
+ blur: {
94
+ configurable: true,
95
+ get: ()=>blur
96
+ }
97
+ });
98
+ }
99
+ }
100
+
101
+ export { patchFocus, restoreFocus };
@@ -1,12 +1,6 @@
1
1
  import { dispatchDOMEvent } from '../event/dispatchEvent.js';
2
- import '../utils/click/isClickableInput.js';
3
- import '../utils/dataTransfer/Clipboard.js';
4
- import '../utils/edit/isEditable.js';
5
- import '../utils/edit/maxLength.js';
6
2
  import { isElementType } from '../utils/misc/isElementType.js';
7
- import '../utils/keyDef/readNextDescriptor.js';
8
- import '../utils/misc/level.js';
9
- import '../options.js';
3
+ import '../utils/dataTransfer/Clipboard.js';
10
4
  import { getInitialValue, clearInitialValue } from './UI.js';
11
5
  import '@testing-library/dom';
12
6
  import { prepareValueInterceptor, prepareSelectionInterceptor, prepareRangeTextInterceptor } from './interceptor.js';
@@ -1,11 +1,5 @@
1
- import '../utils/click/isClickableInput.js';
2
1
  import '../utils/dataTransfer/Clipboard.js';
3
- import '../utils/edit/isEditable.js';
4
- import '../utils/edit/maxLength.js';
5
2
  import { getWindow } from '../utils/misc/getWindow.js';
6
- import '../utils/keyDef/readNextDescriptor.js';
7
- import '../utils/misc/level.js';
8
- import '../options.js';
9
3
  import { setUIValueClean, setUISelection, hasUISelection } from './UI.js';
10
4
 
11
5
  const TrackChanges = Symbol('Track programmatic changes for React workaround');
@@ -30,7 +24,7 @@ function startTrackValue(element) {
30
24
  }
31
25
  function trackOrSetValue(element, v) {
32
26
  var _element_TrackChanges_tracked, _element_TrackChanges;
33
- (_element_TrackChanges = element[TrackChanges]) === null || _element_TrackChanges === void 0 ? void 0 : (_element_TrackChanges_tracked = _element_TrackChanges.tracked) === null || _element_TrackChanges_tracked === void 0 ? void 0 : _element_TrackChanges_tracked.push(v);
27
+ (_element_TrackChanges = element[TrackChanges]) === null || _element_TrackChanges === undefined ? undefined : (_element_TrackChanges_tracked = _element_TrackChanges.tracked) === null || _element_TrackChanges_tracked === undefined ? undefined : _element_TrackChanges_tracked.push(v);
34
28
  if (!element[TrackChanges]) {
35
29
  setUIValueClean(element);
36
30
  setUISelection(element, {
@@ -42,7 +36,7 @@ function commitValueAfterInput(element, cursorOffset) {
42
36
  var _changes_tracked;
43
37
  const changes = element[TrackChanges];
44
38
  element[TrackChanges] = undefined;
45
- if (!(changes === null || changes === void 0 ? void 0 : (_changes_tracked = changes.tracked) === null || _changes_tracked === void 0 ? void 0 : _changes_tracked.length)) {
39
+ if (!(changes === null || changes === undefined ? undefined : (_changes_tracked = changes.tracked) === null || _changes_tracked === undefined ? undefined : _changes_tracked.length)) {
46
40
  return;
47
41
  }
48
42
  const isJustReactStateUpdate = changes.tracked.length === 2 && changes.tracked[0] === changes.previousValue && changes.tracked[1] === element.value;
@@ -1,14 +1,8 @@
1
- import '../../utils/click/isClickableInput.js';
2
- import '../../utils/dataTransfer/Clipboard.js';
3
- import '../../utils/edit/isEditable.js';
4
- import '../../utils/edit/maxLength.js';
5
1
  import { isElementType } from '../../utils/misc/isElementType.js';
2
+ import '../../utils/dataTransfer/Clipboard.js';
6
3
  import { getWindow } from '../../utils/misc/getWindow.js';
7
4
  import { isFocusable } from '../../utils/focus/isFocusable.js';
8
- import '../../utils/keyDef/readNextDescriptor.js';
9
5
  import { cloneEvent } from '../../utils/misc/cloneEvent.js';
10
- import '../../utils/misc/level.js';
11
- import '../../options.js';
12
6
  import { focusElement, blurElement } from '../focus.js';
13
7
  import { behavior } from './registry.js';
14
8
 
@@ -1,10 +1,5 @@
1
- import '../../utils/click/isClickableInput.js';
2
1
  import '../../utils/dataTransfer/Clipboard.js';
3
2
  import { isEditable } from '../../utils/edit/isEditable.js';
4
- import '../../utils/edit/maxLength.js';
5
- import '../../utils/keyDef/readNextDescriptor.js';
6
- import '../../utils/misc/level.js';
7
- import '../../options.js';
8
3
  import { input } from '../input.js';
9
4
  import { behavior } from './registry.js';
10
5
 
@@ -1,16 +1,11 @@
1
1
  import { getUIValue, setUISelection } from '../../document/UI.js';
2
2
  import { getValueOrTextContent } from '../../document/getValueOrTextContent.js';
3
- import '../../utils/click/isClickableInput.js';
3
+ import { isElementType } from '../../utils/misc/isElementType.js';
4
4
  import '../../utils/dataTransfer/Clipboard.js';
5
5
  import { isContentEditable } from '../../utils/edit/isContentEditable.js';
6
6
  import { isEditable } from '../../utils/edit/isEditable.js';
7
- import '../../utils/edit/maxLength.js';
8
- import { isElementType } from '../../utils/misc/isElementType.js';
9
7
  import { getTabDestination } from '../../utils/focus/getTabDestination.js';
10
8
  import { hasOwnSelection } from '../../utils/focus/selection.js';
11
- import '../../utils/keyDef/readNextDescriptor.js';
12
- import '../../utils/misc/level.js';
13
- import '../../options.js';
14
9
  import { focusElement } from '../focus.js';
15
10
  import { input } from '../input.js';
16
11
  import { moveSelection } from '../selection/moveSelection.js';
@@ -22,7 +17,7 @@ import { behavior } from './registry.js';
22
17
  behavior.keydown = (event, target, instance)=>{
23
18
  var _keydownBehavior_event_key;
24
19
  var _keydownBehavior_event_key1;
25
- return (_keydownBehavior_event_key1 = (_keydownBehavior_event_key = keydownBehavior[event.key]) === null || _keydownBehavior_event_key === void 0 ? void 0 : _keydownBehavior_event_key.call(keydownBehavior, event, target, instance)) !== null && _keydownBehavior_event_key1 !== void 0 ? _keydownBehavior_event_key1 : combinationBehavior(event, target, instance);
20
+ return (_keydownBehavior_event_key1 = (_keydownBehavior_event_key = keydownBehavior[event.key]) === null || _keydownBehavior_event_key === undefined ? undefined : _keydownBehavior_event_key.call(keydownBehavior, event, target, instance)) !== null && _keydownBehavior_event_key1 !== undefined ? _keydownBehavior_event_key1 : combinationBehavior(event, target, instance);
26
21
  };
27
22
  const keydownBehavior = {
28
23
  ArrowDown: (event, target, instance)=>{
@@ -77,7 +72,7 @@ const keydownBehavior = {
77
72
  return ()=>{
78
73
  var _getValueOrTextContent;
79
74
  var _getValueOrTextContent_length;
80
- const newPos = (_getValueOrTextContent_length = (_getValueOrTextContent = getValueOrTextContent(target)) === null || _getValueOrTextContent === void 0 ? void 0 : _getValueOrTextContent.length) !== null && _getValueOrTextContent_length !== void 0 ? _getValueOrTextContent_length : /* istanbul ignore next */ 0;
75
+ const newPos = (_getValueOrTextContent_length = (_getValueOrTextContent = getValueOrTextContent(target)) === null || _getValueOrTextContent === undefined ? undefined : _getValueOrTextContent.length) !== null && _getValueOrTextContent_length !== undefined ? _getValueOrTextContent_length : /* istanbul ignore next */ 0;
81
76
  setSelectionRange(target, newPos, newPos);
82
77
  };
83
78
  }
@@ -1,12 +1,7 @@
1
- import '../../utils/click/isClickableInput.js';
1
+ import { isElementType } from '../../utils/misc/isElementType.js';
2
2
  import '../../utils/dataTransfer/Clipboard.js';
3
3
  import { isContentEditable } from '../../utils/edit/isContentEditable.js';
4
4
  import { isEditable } from '../../utils/edit/isEditable.js';
5
- import '../../utils/edit/maxLength.js';
6
- import { isElementType } from '../../utils/misc/isElementType.js';
7
- import '../../utils/keyDef/readNextDescriptor.js';
8
- import '../../utils/misc/level.js';
9
- import '../../options.js';
10
5
  import { input } from '../input.js';
11
6
  import { behavior } from './registry.js';
12
7
 
@@ -18,7 +13,7 @@ behavior.keypress = (event, target, instance)=>{
18
13
  };
19
14
  } else if (isElementType(target, 'input')) {
20
15
  const form = target.form;
21
- const submit = form === null || form === void 0 ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]');
16
+ const submit = form === null || form === undefined ? undefined : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]');
22
17
  if (submit) {
23
18
  return ()=>instance.dispatchUIEvent(submit, 'click');
24
19
  } else if (form && SubmitSingleInputOnEnter.includes(target.type) && form.querySelectorAll('input').length === 1) {
@@ -1,15 +1,10 @@
1
1
  import { isClickableInput } from '../../utils/click/isClickableInput.js';
2
2
  import '../../utils/dataTransfer/Clipboard.js';
3
- import '../../utils/edit/isEditable.js';
4
- import '../../utils/edit/maxLength.js';
5
- import '../../utils/keyDef/readNextDescriptor.js';
6
- import '../../utils/misc/level.js';
7
- import '../../options.js';
8
3
  import { behavior } from './registry.js';
9
4
 
10
5
  behavior.keyup = (event, target, instance)=>{
11
6
  var _keyupBehavior_event_key;
12
- return (_keyupBehavior_event_key = keyupBehavior[event.key]) === null || _keyupBehavior_event_key === void 0 ? void 0 : _keyupBehavior_event_key.call(keyupBehavior, event, target, instance);
7
+ return (_keyupBehavior_event_key = keyupBehavior[event.key]) === null || _keyupBehavior_event_key === undefined ? undefined : _keyupBehavior_event_key.call(keyupBehavior, event, target, instance);
13
8
  };
14
9
  const keyupBehavior = {
15
10
  ' ': (event, target, instance)=>{