@testing-library/user-event 14.2.0 → 14.2.3

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/index.cjs CHANGED
@@ -1,24 +1,8 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
- var __spreadValues = (a, b) => {
11
- for (var prop in b || (b = {}))
12
- if (__hasOwnProp.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
14
- if (__getOwnPropSymbols)
15
- for (var prop of __getOwnPropSymbols(b)) {
16
- if (__propIsEnum.call(b, prop))
17
- __defNormalProp(a, prop, b[prop]);
18
- }
19
- return a;
20
- };
21
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
6
  var __export = (target, all) => {
23
7
  for (var name in all)
24
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -86,7 +70,8 @@ function readBlobText(blob, FileReader) {
86
70
 
87
71
  // src/utils/dataTransfer/FileList.ts
88
72
  function createFileList(files) {
89
- const list = __spreadProps(__spreadValues({}, files), {
73
+ const list = {
74
+ ...files,
90
75
  length: files.length,
91
76
  item: (index) => list[index],
92
77
  [Symbol.iterator]: function* nextFile() {
@@ -94,7 +79,7 @@ function createFileList(files) {
94
79
  yield list[i];
95
80
  }
96
81
  }
97
- });
82
+ };
98
83
  list.constructor = FileList;
99
84
  Object.setPrototypeOf(list, FileList.prototype);
100
85
  Object.freeze(list);
@@ -243,9 +228,8 @@ function createClipboardItem(window, ...blobs) {
243
228
  }(dataMap);
244
229
  }
245
230
  var ClipboardStubControl = Symbol("Manage ClipboardSub");
246
- function createClipboardStub(window) {
247
- var _a;
248
- return new (_a = class extends window.EventTarget {
231
+ function createClipboardStub(window, control) {
232
+ return Object.assign(new class Clipboard extends window.EventTarget {
249
233
  constructor() {
250
234
  super(...arguments);
251
235
  this.items = [];
@@ -269,7 +253,9 @@ function createClipboardStub(window) {
269
253
  async writeText(text) {
270
254
  this.items = [createClipboardItem(window, text)];
271
255
  }
272
- }, ClipboardStubControl, _a)();
256
+ }(), {
257
+ [ClipboardStubControl]: control
258
+ });
273
259
  }
274
260
  function isClipboardStub(clipboard) {
275
261
  return !!(clipboard == null ? void 0 : clipboard[ClipboardStubControl]);
@@ -279,11 +265,10 @@ function attachClipboardStubToView(window) {
279
265
  return window.navigator.clipboard[ClipboardStubControl];
280
266
  }
281
267
  const realClipboard = Object.getOwnPropertyDescriptor(window.navigator, "clipboard");
282
- let stub = createClipboardStub(window);
268
+ let stub;
283
269
  const control = {
284
270
  resetClipboardStub: () => {
285
- stub = createClipboardStub(window);
286
- stub[ClipboardStubControl] = control;
271
+ stub = createClipboardStub(window, control);
287
272
  },
288
273
  detachClipboardStub: () => {
289
274
  if (realClipboard) {
@@ -296,7 +281,7 @@ function attachClipboardStubToView(window) {
296
281
  }
297
282
  }
298
283
  };
299
- stub[ClipboardStubControl] = control;
284
+ stub = createClipboardStub(window, control);
300
285
  Object.defineProperty(window.navigator, "clipboard", {
301
286
  get: () => stub,
302
287
  configurable: true
@@ -609,17 +594,30 @@ function setFiles(el, files) {
609
594
  const prototypeDescriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(el));
610
595
  function restore() {
611
596
  Object.defineProperties(el, {
612
- files: __spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files),
613
- value: __spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value),
614
- type: __spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type)
597
+ files: {
598
+ ...prototypeDescriptors.files,
599
+ ...objectDescriptors.files
600
+ },
601
+ value: {
602
+ ...prototypeDescriptors.value,
603
+ ...objectDescriptors.value
604
+ },
605
+ type: {
606
+ ...prototypeDescriptors.type,
607
+ ...objectDescriptors.type
608
+ }
615
609
  });
616
610
  }
617
611
  el[fakeFiles] = { restore };
618
612
  Object.defineProperties(el, {
619
- files: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files), {
613
+ files: {
614
+ ...prototypeDescriptors.files,
615
+ ...objectDescriptors.files,
620
616
  get: () => files
621
- }),
622
- value: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value), {
617
+ },
618
+ value: {
619
+ ...prototypeDescriptors.value,
620
+ ...objectDescriptors.value,
623
621
  get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
624
622
  set(v) {
625
623
  var _a2;
@@ -629,15 +627,17 @@ function setFiles(el, files) {
629
627
  (_a2 = objectDescriptors.value.set) == null ? void 0 : _a2.call(el, v);
630
628
  }
631
629
  }
632
- }),
633
- type: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type), {
630
+ },
631
+ type: {
632
+ ...prototypeDescriptors.type,
633
+ ...objectDescriptors.type,
634
634
  set(v) {
635
635
  if (v !== "file") {
636
636
  restore();
637
637
  el.type = v;
638
638
  }
639
639
  }
640
- })
640
+ }
641
641
  });
642
642
  }
643
643
 
@@ -996,8 +996,8 @@ function isVisible(element) {
996
996
  function getTabDestination(activeElement, shift) {
997
997
  const document = activeElement.ownerDocument;
998
998
  const focusableElements = document.querySelectorAll(FOCUSABLE_SELECTOR);
999
- const enabledElements = Array.from(focusableElements).filter((el) => el === activeElement || el.getAttribute("tabindex") !== "-1" && !isDisabled(el) && isVisible(el));
1000
- if (activeElement.getAttribute("tabindex") !== "-1") {
999
+ const enabledElements = Array.from(focusableElements).filter((el) => el === activeElement || !(Number(el.getAttribute("tabindex")) < 0 || isDisabled(el)));
1000
+ if (Number(activeElement.getAttribute("tabindex")) >= 0) {
1001
1001
  enabledElements.sort((a, b) => {
1002
1002
  const i = Number(a.getAttribute("tabindex"));
1003
1003
  const j = Number(b.getAttribute("tabindex"));
@@ -1037,10 +1037,17 @@ function getTabDestination(activeElement, shift) {
1037
1037
  }
1038
1038
  prunedElements.push(el);
1039
1039
  });
1040
- const currentIndex = prunedElements.findIndex((el) => el === activeElement);
1041
- const nextIndex = shift ? currentIndex - 1 : currentIndex + 1;
1042
- const defaultIndex = shift ? prunedElements.length - 1 : 0;
1043
- return prunedElements[nextIndex] || prunedElements[defaultIndex];
1040
+ for (let index = prunedElements.findIndex((el) => el === activeElement); ; ) {
1041
+ index += shift ? -1 : 1;
1042
+ if (index === prunedElements.length) {
1043
+ index = 0;
1044
+ } else if (index === -1) {
1045
+ index = prunedElements.length - 1;
1046
+ }
1047
+ if (prunedElements[index] === activeElement || prunedElements[index] === document.body || isVisible(prunedElements[index])) {
1048
+ return prunedElements[index];
1049
+ }
1050
+ }
1044
1051
  }
1045
1052
 
1046
1053
  // src/utils/focus/selectAll.ts
@@ -1108,9 +1115,10 @@ function readNextDescriptor(text, context) {
1108
1115
  pos += startBracket.length;
1109
1116
  const isEscapedChar = new RegExp(`^\\${startBracket}{2}`).test(text);
1110
1117
  const type3 = isEscapedChar ? "" : startBracket;
1111
- return __spreadValues({
1112
- type: type3
1113
- }, type3 === "" ? readPrintableChar(text, pos, context) : readTag(text, pos, type3, context));
1118
+ return {
1119
+ type: type3,
1120
+ ...type3 === "" ? readPrintableChar(text, pos, context) : readTag(text, pos, type3, context)
1121
+ };
1114
1122
  }
1115
1123
  function readPrintableChar(text, pos, context) {
1116
1124
  const descriptor = text[pos];
@@ -1311,9 +1319,10 @@ var defaultOptionsDirect = {
1311
1319
  writeToClipboard: false,
1312
1320
  advanceTimers: () => Promise.resolve()
1313
1321
  };
1314
- var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect), {
1322
+ var defaultOptionsSetup = {
1323
+ ...defaultOptionsDirect,
1315
1324
  writeToClipboard: true
1316
- });
1325
+ };
1317
1326
 
1318
1327
  // src/utils/pointer/cssPointerEvents.ts
1319
1328
  function hasPointerEvents(element) {
@@ -1432,12 +1441,13 @@ var import_dom2 = require("@testing-library/dom");
1432
1441
 
1433
1442
  // src/event/eventMap.ts
1434
1443
  var import_event_map = require("@testing-library/dom/dist/event-map.js");
1435
- var eventMap = __spreadProps(__spreadValues({}, import_event_map.eventMap), {
1444
+ var eventMap = {
1445
+ ...import_event_map.eventMap,
1436
1446
  beforeInput: {
1437
1447
  EventType: "InputEvent",
1438
1448
  defaultInit: { bubbles: true, cancelable: true, composed: true }
1439
1449
  }
1440
- });
1450
+ };
1441
1451
  var eventMapKeys = Object.fromEntries(Object.keys(eventMap).map((k) => [k.toLowerCase(), k]));
1442
1452
 
1443
1453
  // src/event/eventTypes.ts
@@ -1711,7 +1721,10 @@ function dispatchEvent(config, target, event, preventDefault = false) {
1711
1721
  // src/event/index.ts
1712
1722
  function dispatchUIEvent(config, target, type3, init, preventDefault = false) {
1713
1723
  if (isMouseEvent(type3) || isKeyboardEvent(type3)) {
1714
- init = __spreadValues(__spreadValues({}, init), getUIEventModifiers(config.keyboardState));
1724
+ init = {
1725
+ ...init,
1726
+ ...getUIEventModifiers(config.keyboardState)
1727
+ };
1715
1728
  }
1716
1729
  const event = createEvent(type3, target, init);
1717
1730
  return dispatchEvent(config, target, event, preventDefault);
@@ -1731,7 +1744,7 @@ function prepareInterceptor(element, propName, interceptorImpl) {
1731
1744
  }
1732
1745
  function intercept(...args) {
1733
1746
  const {
1734
- applyNative = true,
1747
+ applyNative = false,
1735
1748
  realArgs,
1736
1749
  then
1737
1750
  } = interceptorImpl.call(this, ...args);
@@ -1745,21 +1758,23 @@ function prepareInterceptor(element, propName, interceptorImpl) {
1745
1758
  }
1746
1759
  ;
1747
1760
  intercept[Interceptor] = Interceptor;
1748
- Object.defineProperty(element, propName, __spreadProps(__spreadValues({}, objectDescriptor != null ? objectDescriptor : prototypeDescriptor), {
1761
+ Object.defineProperty(element, propName, {
1762
+ ...objectDescriptor != null ? objectDescriptor : prototypeDescriptor,
1749
1763
  [target]: intercept
1750
- }));
1764
+ });
1751
1765
  }
1752
1766
 
1753
1767
  // src/document/selection.ts
1754
1768
  var UISelection = Symbol("Displayed selection in UI");
1755
1769
  function prepareSelectionInterceptor(element) {
1756
- prepareInterceptor(element, "setSelectionRange", function interceptorImpl(start, end, direction = "none") {
1770
+ prepareInterceptor(element, "setSelectionRange", function interceptorImpl(start, ...others) {
1757
1771
  const isUI = start && typeof start === "object" && start[UISelection];
1758
1772
  if (!isUI) {
1759
1773
  this[UISelection] = void 0;
1760
1774
  }
1761
1775
  return {
1762
- realArgs: [Number(start), end, direction]
1776
+ applyNative: !!isUI,
1777
+ realArgs: [Number(start), ...others]
1763
1778
  };
1764
1779
  });
1765
1780
  prepareInterceptor(element, "selectionStart", function interceptorImpl(v) {
@@ -1808,10 +1823,14 @@ function getUISelection(element) {
1808
1823
  anchorOffset: (_a = element.selectionStart) != null ? _a : 0,
1809
1824
  focusOffset: (_b = element.selectionEnd) != null ? _b : 0
1810
1825
  };
1811
- return __spreadProps(__spreadValues({}, sel), {
1826
+ return {
1827
+ ...sel,
1812
1828
  startOffset: Math.min(sel.anchorOffset, sel.focusOffset),
1813
1829
  endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
1814
- });
1830
+ };
1831
+ }
1832
+ function setUISelectionClean(element) {
1833
+ element[UISelection] = void 0;
1815
1834
  }
1816
1835
 
1817
1836
  // src/document/value.ts
@@ -1851,6 +1870,9 @@ function setUIValue(element, value) {
1851
1870
  function getUIValue(element) {
1852
1871
  return element[UIValue] === void 0 ? element.value : String(element[UIValue]);
1853
1872
  }
1873
+ function setUIValueClean(element) {
1874
+ element[UIValue] = void 0;
1875
+ }
1854
1876
  function clearInitialValue(element) {
1855
1877
  element[InitialValue] = void 0;
1856
1878
  }
@@ -1858,13 +1880,14 @@ function getInitialValue(element) {
1858
1880
  return element[InitialValue];
1859
1881
  }
1860
1882
  function setPreviousValue(element, v) {
1861
- element[TrackChanges] = __spreadProps(__spreadValues({}, element[TrackChanges]), { previousValue: v });
1883
+ element[TrackChanges] = { ...element[TrackChanges], previousValue: v };
1862
1884
  }
1863
1885
  function startTrackValue(element) {
1864
- element[TrackChanges] = __spreadProps(__spreadValues({}, element[TrackChanges]), {
1886
+ element[TrackChanges] = {
1887
+ ...element[TrackChanges],
1865
1888
  nextValue: String(element.value),
1866
1889
  tracked: []
1867
- });
1890
+ };
1868
1891
  }
1869
1892
  function trackOrSetValue(element, v) {
1870
1893
  var _a, _b, _c;
@@ -1888,6 +1911,19 @@ function endTrackValue(element) {
1888
1911
  return isJustReactStateUpdate;
1889
1912
  }
1890
1913
 
1914
+ // src/document/setRangeText.ts
1915
+ function prepareRangeTextInterceptor(element) {
1916
+ prepareInterceptor(element, "setRangeText", function interceptorImpl(...realArgs) {
1917
+ return {
1918
+ realArgs,
1919
+ then: () => {
1920
+ setUIValueClean(element);
1921
+ setUISelectionClean(element);
1922
+ }
1923
+ };
1924
+ });
1925
+ }
1926
+
1891
1927
  // src/document/index.ts
1892
1928
  var isPrepared = Symbol("Node prepared with document state workarounds");
1893
1929
  function prepareDocument(document) {
@@ -1926,6 +1962,7 @@ function prepareElement(el) {
1926
1962
  if ("value" in el) {
1927
1963
  prepareValueInterceptor(el);
1928
1964
  prepareSelectionInterceptor(el);
1965
+ prepareRangeTextInterceptor(el);
1929
1966
  }
1930
1967
  el[isPrepared] = isPrepared;
1931
1968
  }
@@ -2041,9 +2078,10 @@ async function keydown(keyDef, getCurrentElement, config) {
2041
2078
  }
2042
2079
  async function keypress(keyDef, getCurrentElement, config) {
2043
2080
  const element = getCurrentElement();
2044
- dispatchUIEvent(config, element, "keypress", __spreadProps(__spreadValues({}, getKeyEventProps(keyDef)), {
2081
+ dispatchUIEvent(config, element, "keypress", {
2082
+ ...getKeyEventProps(keyDef),
2045
2083
  charCode: keyDef.key === "Enter" ? 13 : String(keyDef.key).charCodeAt(0)
2046
- }));
2084
+ });
2047
2085
  }
2048
2086
  async function keyup(keyDef, getCurrentElement, config, unprevented) {
2049
2087
  const element = getCurrentElement();
@@ -2145,7 +2183,9 @@ function firePointerEvent(config, target, type3, {
2145
2183
  isPrimary,
2146
2184
  clickCount
2147
2185
  }) {
2148
- const init = __spreadValues({}, coords);
2186
+ const init = {
2187
+ ...coords
2188
+ };
2149
2189
  if (type3 === "click" || type3.startsWith("pointer")) {
2150
2190
  init.pointerId = pointerId;
2151
2191
  init.pointerType = pointerType;
@@ -2231,10 +2271,11 @@ async function pointerMove(config, { pointerName = "mouse", target, coords, node
2231
2271
  }
2232
2272
  setLevelRef(config, 2 /* Trigger */);
2233
2273
  assertPointerEvents(config, target);
2234
- pointerState.position[pointerName] = __spreadProps(__spreadValues({}, pointerState.position[pointerName]), {
2274
+ pointerState.position[pointerName] = {
2275
+ ...pointerState.position[pointerName],
2235
2276
  target,
2236
2277
  coords
2237
- });
2278
+ };
2238
2279
  if (prevTarget !== target) {
2239
2280
  if (!prevTarget || !isDescendantOrSelf(prevTarget, target)) {
2240
2281
  fireEnter(target, coords);
@@ -2320,12 +2361,13 @@ function down(config, pointerName, { keyDef, node, offset, target, coords }, tar
2320
2361
  const { pointerState } = config;
2321
2362
  const { name, pointerType, button } = keyDef;
2322
2363
  const pointerId = pointerType === "mouse" ? 1 : getNextPointerId(pointerState);
2323
- pointerState.position[pointerName] = __spreadProps(__spreadValues({}, pointerState.position[pointerName]), {
2364
+ pointerState.position[pointerName] = {
2365
+ ...pointerState.position[pointerName],
2324
2366
  pointerId,
2325
2367
  pointerType,
2326
2368
  target,
2327
2369
  coords
2328
- });
2370
+ };
2329
2371
  let isMultiTouch = false;
2330
2372
  let isPrimary = true;
2331
2373
  if (pointerType !== "mouse") {
@@ -2402,10 +2444,11 @@ function up(config, pointerName, {
2402
2444
  pointerState.pressed = pointerState.pressed.filter((p) => p !== pressed);
2403
2445
  const { isMultiTouch, isPrimary, pointerId, clickCount } = pressed;
2404
2446
  let { unpreventedDefault } = pressed;
2405
- pointerState.position[pointerName] = __spreadProps(__spreadValues({}, pointerState.position[pointerName]), {
2447
+ pointerState.position[pointerName] = {
2448
+ ...pointerState.position[pointerName],
2406
2449
  target,
2407
2450
  coords
2408
- });
2451
+ };
2409
2452
  if (pointerType !== "mouse" || !pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).length) {
2410
2453
  fire("pointerup");
2411
2454
  }
@@ -2526,7 +2569,7 @@ async function pointerAction(config, actions) {
2526
2569
  const pointerName = "pointerName" in action && action.pointerName ? action.pointerName : "keyDef" in action ? action.keyDef.pointerType === "touch" ? action.keyDef.name : action.keyDef.pointerType : "mouse";
2527
2570
  const target = (_a = action.target) != null ? _a : getPrevTarget(pointerName, config.pointerState);
2528
2571
  const coords = (_b = action.coords) != null ? _b : pointerName in config.pointerState.position ? config.pointerState.position[pointerName].coords : void 0;
2529
- await ("keyDef" in action ? pointerPress(config, __spreadProps(__spreadValues({}, action), { target, coords })) : pointerMove(config, __spreadProps(__spreadValues({}, action), { target, coords })));
2572
+ await ("keyDef" in action ? pointerPress(config, { ...action, target, coords }) : pointerMove(config, { ...action, target, coords }));
2530
2573
  if (i < actions.length - 1) {
2531
2574
  await wait(config);
2532
2575
  }
@@ -2548,7 +2591,10 @@ async function pointer(input2) {
2548
2591
  if (typeof actionInput === "string") {
2549
2592
  actions.push(...parseKeyDef2(pointerMap, actionInput));
2550
2593
  } else if ("keys" in actionInput) {
2551
- actions.push(...parseKeyDef2(pointerMap, actionInput.keys).map((i) => __spreadValues(__spreadValues({}, actionInput), i)));
2594
+ actions.push(...parseKeyDef2(pointerMap, actionInput.keys).map((i) => ({
2595
+ ...actionInput,
2596
+ ...i
2597
+ })));
2552
2598
  } else {
2553
2599
  actions.push(actionInput);
2554
2600
  }
@@ -2869,11 +2915,13 @@ function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
2869
2915
  keyboardState = createKeyboardState(),
2870
2916
  pointerState = createPointerState(document)
2871
2917
  } = options;
2872
- return __spreadProps(__spreadValues(__spreadValues({}, defaults), options), {
2918
+ return {
2919
+ ...defaults,
2920
+ ...options,
2873
2921
  document,
2874
2922
  keyboardState,
2875
2923
  pointerState
2876
- });
2924
+ };
2877
2925
  }
2878
2926
  function setupMain(options = {}) {
2879
2927
  var _a;
@@ -2892,7 +2940,10 @@ function setupDirect(options = {}, node) {
2892
2940
  };
2893
2941
  }
2894
2942
  function setupSub(options) {
2895
- return doSetup(__spreadValues(__spreadValues({}, this[Config]), options));
2943
+ return doSetup({
2944
+ ...this[Config],
2945
+ ...options
2946
+ });
2896
2947
  }
2897
2948
  function wrapAndBindImpl(instance, impl) {
2898
2949
  function method(...args) {
@@ -2906,16 +2957,18 @@ function wrapAndBindImpl(instance, impl) {
2906
2957
  return method;
2907
2958
  }
2908
2959
  function doSetup(config) {
2909
- const instance = __spreadValues({
2960
+ const instance = {
2910
2961
  [Config]: config,
2911
- dispatchUIEvent: bindDispatchUIEvent(config)
2912
- }, api_exports);
2913
- return __spreadProps(__spreadValues({}, Object.fromEntries(Object.entries(api_exports).map(([name, api]) => [
2914
- name,
2915
- wrapAndBindImpl(instance, api)
2916
- ]))), {
2962
+ dispatchUIEvent: bindDispatchUIEvent(config),
2963
+ ...api_exports
2964
+ };
2965
+ return {
2966
+ ...Object.fromEntries(Object.entries(api_exports).map(([name, api]) => [
2967
+ name,
2968
+ wrapAndBindImpl(instance, api)
2969
+ ])),
2917
2970
  setup: setupSub.bind(instance)
2918
- });
2971
+ };
2919
2972
  }
2920
2973
  function getDocument(options, node, defaults) {
2921
2974
  var _a, _b;
@@ -2996,6 +3049,7 @@ function tab2(options = {}) {
2996
3049
  }
2997
3050
 
2998
3051
  // src/setup/index.ts
2999
- var userEvent = __spreadProps(__spreadValues({}, directApi_exports), {
3052
+ var userEvent = {
3053
+ ...directApi_exports,
3000
3054
  setup: setupMain
3001
- });
3055
+ };
package/dist/index.mjs CHANGED
@@ -247,9 +247,8 @@ function createClipboardItem(window, ...blobs) {
247
247
  }(dataMap);
248
248
  }
249
249
  var ClipboardStubControl = Symbol("Manage ClipboardSub");
250
- function createClipboardStub(window) {
251
- var _a;
252
- return new (_a = class extends window.EventTarget {
250
+ function createClipboardStub(window, control) {
251
+ return Object.assign(new class Clipboard extends window.EventTarget {
253
252
  constructor() {
254
253
  super(...arguments);
255
254
  this.items = [];
@@ -281,7 +280,9 @@ function createClipboardStub(window) {
281
280
  this.items = [createClipboardItem(window, text)];
282
281
  });
283
282
  }
284
- }, ClipboardStubControl, _a)();
283
+ }(), {
284
+ [ClipboardStubControl]: control
285
+ });
285
286
  }
286
287
  function isClipboardStub(clipboard) {
287
288
  return !!(clipboard == null ? void 0 : clipboard[ClipboardStubControl]);
@@ -291,11 +292,10 @@ function attachClipboardStubToView(window) {
291
292
  return window.navigator.clipboard[ClipboardStubControl];
292
293
  }
293
294
  const realClipboard = Object.getOwnPropertyDescriptor(window.navigator, "clipboard");
294
- let stub = createClipboardStub(window);
295
+ let stub;
295
296
  const control = {
296
297
  resetClipboardStub: () => {
297
- stub = createClipboardStub(window);
298
- stub[ClipboardStubControl] = control;
298
+ stub = createClipboardStub(window, control);
299
299
  },
300
300
  detachClipboardStub: () => {
301
301
  if (realClipboard) {
@@ -308,7 +308,7 @@ function attachClipboardStubToView(window) {
308
308
  }
309
309
  }
310
310
  };
311
- stub[ClipboardStubControl] = control;
311
+ stub = createClipboardStub(window, control);
312
312
  Object.defineProperty(window.navigator, "clipboard", {
313
313
  get: () => stub,
314
314
  configurable: true
@@ -1012,8 +1012,8 @@ function isVisible(element) {
1012
1012
  function getTabDestination(activeElement, shift) {
1013
1013
  const document = activeElement.ownerDocument;
1014
1014
  const focusableElements = document.querySelectorAll(FOCUSABLE_SELECTOR);
1015
- const enabledElements = Array.from(focusableElements).filter((el) => el === activeElement || el.getAttribute("tabindex") !== "-1" && !isDisabled(el) && isVisible(el));
1016
- if (activeElement.getAttribute("tabindex") !== "-1") {
1015
+ const enabledElements = Array.from(focusableElements).filter((el) => el === activeElement || !(Number(el.getAttribute("tabindex")) < 0 || isDisabled(el)));
1016
+ if (Number(activeElement.getAttribute("tabindex")) >= 0) {
1017
1017
  enabledElements.sort((a, b) => {
1018
1018
  const i = Number(a.getAttribute("tabindex"));
1019
1019
  const j = Number(b.getAttribute("tabindex"));
@@ -1053,10 +1053,17 @@ function getTabDestination(activeElement, shift) {
1053
1053
  }
1054
1054
  prunedElements.push(el);
1055
1055
  });
1056
- const currentIndex = prunedElements.findIndex((el) => el === activeElement);
1057
- const nextIndex = shift ? currentIndex - 1 : currentIndex + 1;
1058
- const defaultIndex = shift ? prunedElements.length - 1 : 0;
1059
- return prunedElements[nextIndex] || prunedElements[defaultIndex];
1056
+ for (let index = prunedElements.findIndex((el) => el === activeElement); ; ) {
1057
+ index += shift ? -1 : 1;
1058
+ if (index === prunedElements.length) {
1059
+ index = 0;
1060
+ } else if (index === -1) {
1061
+ index = prunedElements.length - 1;
1062
+ }
1063
+ if (prunedElements[index] === activeElement || prunedElements[index] === document.body || isVisible(prunedElements[index])) {
1064
+ return prunedElements[index];
1065
+ }
1066
+ }
1060
1067
  }
1061
1068
 
1062
1069
  // src/utils/focus/selectAll.ts
@@ -1747,7 +1754,7 @@ function prepareInterceptor(element, propName, interceptorImpl) {
1747
1754
  }
1748
1755
  function intercept(...args) {
1749
1756
  const {
1750
- applyNative = true,
1757
+ applyNative = false,
1751
1758
  realArgs,
1752
1759
  then
1753
1760
  } = interceptorImpl.call(this, ...args);
@@ -1769,13 +1776,14 @@ function prepareInterceptor(element, propName, interceptorImpl) {
1769
1776
  // src/document/selection.ts
1770
1777
  var UISelection = Symbol("Displayed selection in UI");
1771
1778
  function prepareSelectionInterceptor(element) {
1772
- prepareInterceptor(element, "setSelectionRange", function interceptorImpl(start, end, direction = "none") {
1779
+ prepareInterceptor(element, "setSelectionRange", function interceptorImpl(start, ...others) {
1773
1780
  const isUI = start && typeof start === "object" && start[UISelection];
1774
1781
  if (!isUI) {
1775
1782
  this[UISelection] = void 0;
1776
1783
  }
1777
1784
  return {
1778
- realArgs: [Number(start), end, direction]
1785
+ applyNative: !!isUI,
1786
+ realArgs: [Number(start), ...others]
1779
1787
  };
1780
1788
  });
1781
1789
  prepareInterceptor(element, "selectionStart", function interceptorImpl(v) {
@@ -1829,6 +1837,9 @@ function getUISelection(element) {
1829
1837
  endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
1830
1838
  });
1831
1839
  }
1840
+ function setUISelectionClean(element) {
1841
+ element[UISelection] = void 0;
1842
+ }
1832
1843
 
1833
1844
  // src/document/value.ts
1834
1845
  var UIValue = Symbol("Displayed value in UI");
@@ -1867,6 +1878,9 @@ function setUIValue(element, value) {
1867
1878
  function getUIValue(element) {
1868
1879
  return element[UIValue] === void 0 ? element.value : String(element[UIValue]);
1869
1880
  }
1881
+ function setUIValueClean(element) {
1882
+ element[UIValue] = void 0;
1883
+ }
1870
1884
  function clearInitialValue(element) {
1871
1885
  element[InitialValue] = void 0;
1872
1886
  }
@@ -1904,6 +1918,19 @@ function endTrackValue(element) {
1904
1918
  return isJustReactStateUpdate;
1905
1919
  }
1906
1920
 
1921
+ // src/document/setRangeText.ts
1922
+ function prepareRangeTextInterceptor(element) {
1923
+ prepareInterceptor(element, "setRangeText", function interceptorImpl(...realArgs) {
1924
+ return {
1925
+ realArgs,
1926
+ then: () => {
1927
+ setUIValueClean(element);
1928
+ setUISelectionClean(element);
1929
+ }
1930
+ };
1931
+ });
1932
+ }
1933
+
1907
1934
  // src/document/index.ts
1908
1935
  var isPrepared = Symbol("Node prepared with document state workarounds");
1909
1936
  function prepareDocument(document) {
@@ -1942,6 +1969,7 @@ function prepareElement(el) {
1942
1969
  if ("value" in el) {
1943
1970
  prepareValueInterceptor(el);
1944
1971
  prepareSelectionInterceptor(el);
1972
+ prepareRangeTextInterceptor(el);
1945
1973
  }
1946
1974
  el[isPrepared] = isPrepared;
1947
1975
  }
@@ -23,4 +23,6 @@ export declare function getUISelection(element: HTMLInputElement | HTMLTextAreaE
23
23
  anchorOffset: number;
24
24
  focusOffset: number;
25
25
  };
26
+ /** Flag the IDL selection as clean. This does not change the selection. */
27
+ export declare function setUISelectionClean(element: HTMLInputElement | HTMLTextAreaElement): void;
26
28
  export {};
@@ -0,0 +1 @@
1
+ export declare function prepareRangeTextInterceptor(element: HTMLInputElement | HTMLTextAreaElement): void;
@@ -15,6 +15,8 @@ declare global {
15
15
  export declare function prepareValueInterceptor(element: HTMLInputElement): void;
16
16
  export declare function setUIValue(element: HTMLInputElement | HTMLTextAreaElement, value: string): void;
17
17
  export declare function getUIValue(element: HTMLInputElement | HTMLTextAreaElement): string;
18
+ /** Flag the IDL value as clean. This does not change the value.*/
19
+ export declare function setUIValueClean(element: HTMLInputElement | HTMLTextAreaElement): void;
18
20
  export declare function clearInitialValue(element: HTMLInputElement | HTMLTextAreaElement): void;
19
21
  export declare function getInitialValue(element: HTMLInputElement | HTMLTextAreaElement): string | undefined;
20
22
  export declare function startTrackValue(element: HTMLInputElement | HTMLTextAreaElement): void;
@@ -1,9 +1,11 @@
1
1
  export declare function createClipboardItem(window: Window & typeof globalThis, ...blobs: Array<Blob | string>): ClipboardItem;
2
- export declare function attachClipboardStubToView(window: Window & typeof globalThis): {
2
+ declare type ClipboardStubControlInstance = {
3
3
  resetClipboardStub: () => void;
4
4
  detachClipboardStub: () => void;
5
5
  };
6
+ export declare function attachClipboardStubToView(window: Window & typeof globalThis): ClipboardStubControlInstance;
6
7
  export declare function resetClipboardStubOnView(window: Window & typeof globalThis): void;
7
8
  export declare function detachClipboardStubFromView(window: Window & typeof globalThis): void;
8
9
  export declare function readDataTransferFromClipboard(document: Document): Promise<DataTransfer>;
9
10
  export declare function writeDataTransferToClipboard(document: Document, clipboardData: DataTransfer): Promise<void>;
11
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testing-library/user-event",
3
- "version": "14.2.0",
3
+ "version": "14.2.3",
4
4
  "description": "Fire events the same way the user does",
5
5
  "keywords": [
6
6
  "react-testing-library",