@testing-library/user-event 14.0.0-beta.2 → 14.0.0-beta.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.
@@ -5,8 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.pointerPress = pointerPress;
7
7
 
8
- var _dom = require("@testing-library/dom");
9
-
10
8
  var _utils = require("../utils");
11
9
 
12
10
  var _document = require("../document");
@@ -126,6 +124,10 @@ function down({
126
124
  });
127
125
  }
128
126
 
127
+ if (pointerType === 'mouse' && button === 'secondary') {
128
+ fire('contextmenu');
129
+ }
130
+
129
131
  return pressObj;
130
132
 
131
133
  function fire(type) {
@@ -210,25 +212,20 @@ function up({
210
212
  const canClick = pointerType !== 'mouse' || button === 'primary';
211
213
 
212
214
  if (canClick && target === pressed.downTarget) {
213
- fire('click');
215
+ var _target$closest;
216
+
217
+ const unpreventedClick = fire('click');
214
218
 
215
219
  if (clickCount === 2) {
216
220
  fire('dblclick');
217
- } // If the click happens inside a `label` with a control, the control (or closes focusable) is focused.
218
-
219
-
220
- const label = target.closest('label');
221
+ }
221
222
 
222
- if (label != null && label.control) {
223
- var _findClosest;
223
+ const control = (_target$closest = target.closest('label')) == null ? void 0 : _target$closest.control;
224
224
 
225
- (0, _utils.focus)((_findClosest = (0, _utils.findClosest)(label.control, _utils.isFocusable)) != null ? _findClosest : target.ownerDocument.body);
225
+ if (unpreventedClick && control && (0, _utils.isFocusable)(control)) {
226
+ (0, _utils.focus)(control);
226
227
  }
227
228
  }
228
-
229
- if (pointerType === 'mouse' && button === 'secondary') {
230
- _dom.fireEvent.contextMenu(target);
231
- }
232
229
  }
233
230
  }
234
231
 
@@ -254,12 +251,12 @@ function mousedownDefaultBehavior({
254
251
  node,
255
252
  offset
256
253
  }) {
257
- var _findClosest2;
254
+ var _findClosest;
258
255
 
259
256
  // The closest focusable element is focused when a `mousedown` would have been fired.
260
257
  // Even if there was no `mousedown` because the element was disabled.
261
258
  // A `mousedown` that preventsDefault cancels this though.
262
- (0, _utils.focus)((_findClosest2 = (0, _utils.findClosest)(target, _utils.isFocusable)) != null ? _findClosest2 : target.ownerDocument.body); // TODO: What happens if a focus event handler interfers?
259
+ (0, _utils.focus)((_findClosest = (0, _utils.findClosest)(target, _utils.isFocusable)) != null ? _findClosest : target.ownerDocument.body); // TODO: What happens if a focus event handler interfers?
263
260
  // An unprevented mousedown moves the cursor to the closest character.
264
261
  // We try to approximate the behavior for a no-layout environment.
265
262
 
@@ -21,7 +21,20 @@ function getTabDestination(activeElement, shift) {
21
21
 
22
22
  if (activeElement.getAttribute('tabindex') !== '-1') {
23
23
  // tabindex has no effect if the active element has tabindex="-1"
24
- enabledElements.sort((a, b) => Number(a.getAttribute('tabindex')) - Number(b.getAttribute('tabindex')));
24
+ enabledElements.sort((a, b) => {
25
+ const i = Number(a.getAttribute('tabindex'));
26
+ const j = Number(b.getAttribute('tabindex'));
27
+
28
+ if (i === j) {
29
+ return 0;
30
+ } else if (i === 0) {
31
+ return 1;
32
+ } else if (j === 0) {
33
+ return -1;
34
+ }
35
+
36
+ return i - j;
37
+ });
25
38
  }
26
39
 
27
40
  const checkedRadio = {};
@@ -5,6 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.hasFormSubmit = void 0;
7
7
 
8
- const hasFormSubmit = form => !!(form && (form.querySelector('input[type="submit"]') || form.querySelector('button[type="submit"]')));
8
+ const hasFormSubmit = form => !!(form != null && form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]'));
9
9
 
10
10
  exports.hasFormSubmit = hasFormSubmit;
@@ -37,16 +37,14 @@ function firePointerEvent(target, type, {
37
37
  init.isPrimary = isPrimary;
38
38
  }
39
39
 
40
- if (['mousedown', 'mouseup', 'pointerdown', 'pointerup', 'click'].includes(type)) {
41
- init.button = (0, _mouseButtons.getMouseButton)(button != null ? button : 0);
42
- init.buttons = (0, _mouseButtons.getMouseButtons)(...pointerState.pressed.filter(p => p.keyDef.pointerType === pointerType).map(p => {
43
- var _p$keyDef$button;
40
+ init.button = (0, _mouseButtons.getMouseButton)(button != null ? button : 0);
41
+ init.buttons = (0, _mouseButtons.getMouseButtons)(...pointerState.pressed.filter(p => p.keyDef.pointerType === pointerType).map(p => {
42
+ var _p$keyDef$button;
44
43
 
45
- return (_p$keyDef$button = p.keyDef.button) != null ? _p$keyDef$button : 0;
46
- }));
47
- }
44
+ return (_p$keyDef$button = p.keyDef.button) != null ? _p$keyDef$button : 0;
45
+ }));
48
46
 
49
- if (['mousedown', 'mouseup', 'click', 'dblclick'].includes(type)) {
47
+ if (['mousedown', 'mouseup', 'click', 'dblclick', 'contextmenu'].includes(type)) {
50
48
  init.detail = clickCount;
51
49
  }
52
50
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testing-library/user-event",
3
- "version": "14.0.0-beta.2",
3
+ "version": "14.0.0-beta.3",
4
4
  "description": "Fire events the same way the user does",
5
5
  "main": "dist/index.js",
6
6
  "keywords": [