@testing-library/user-event 14.0.0-alpha.2 → 14.0.0-alpha.6
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/click.d.ts +1 -0
- package/dist/click.js +17 -0
- package/dist/document/index.d.ts +2 -3
- package/dist/document/index.js +8 -10
- package/dist/document/interceptor.d.ts +11 -1
- package/dist/document/interceptor.js +7 -4
- package/dist/document/selection.d.ts +0 -1
- package/dist/document/selection.js +22 -15
- package/dist/document/value.d.ts +4 -0
- package/dist/document/value.js +26 -5
- package/dist/keyboard/keyMap.js +4 -0
- package/dist/keyboard/keyboardImplementation.js +3 -1
- package/dist/keyboard/plugins/functional.js +17 -0
- package/dist/pointer/pointerAction.d.ts +2 -6
- package/dist/pointer/pointerAction.js +2 -26
- package/dist/pointer/pointerMove.d.ts +3 -3
- package/dist/pointer/pointerMove.js +38 -5
- package/dist/pointer/pointerPress.d.ts +3 -3
- package/dist/pointer/pointerPress.js +133 -29
- package/dist/pointer/resolveSelectionTarget.d.ts +5 -0
- package/dist/pointer/resolveSelectionTarget.js +74 -0
- package/dist/pointer/types.d.ts +18 -4
- package/dist/setup.d.ts +5 -2
- package/dist/setup.js +4 -7
- package/dist/tab.d.ts +1 -2
- package/dist/tab.js +3 -132
- package/dist/type.js +3 -19
- package/dist/utils/edit/fireInputEvent.js +20 -16
- package/dist/utils/edit/getValue.js +1 -3
- package/dist/utils/focus/getTabDestination.d.ts +1 -0
- package/dist/utils/focus/getTabDestination.js +71 -0
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +13 -13
- package/dist/utils/pointer/fakeEvent.d.ts +7 -3
- package/dist/utils/pointer/fakeEvent.js +18 -9
- package/dist/utils/pointer/firePointerEvents.d.ts +2 -11
- package/package.json +1 -1
- package/dist/document/applyNative.d.ts +0 -8
- package/dist/document/applyNative.js +0 -28
- package/dist/utils/misc/isDocument.d.ts +0 -1
- package/dist/utils/misc/isDocument.js +0 -10
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getTabDestination(activeElement: Element, shift: boolean): HTMLElement;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getTabDestination = getTabDestination;
|
|
7
|
+
|
|
8
|
+
var _isDisabled = require("../misc/isDisabled");
|
|
9
|
+
|
|
10
|
+
var _isElementType = require("../misc/isElementType");
|
|
11
|
+
|
|
12
|
+
var _isVisible = require("../misc/isVisible");
|
|
13
|
+
|
|
14
|
+
var _selector = require("./selector");
|
|
15
|
+
|
|
16
|
+
function getTabDestination(activeElement, shift) {
|
|
17
|
+
const document = activeElement.ownerDocument;
|
|
18
|
+
const focusableElements = document.querySelectorAll(_selector.FOCUSABLE_SELECTOR);
|
|
19
|
+
const enabledElements = Array.from(focusableElements).filter(el => el === activeElement || el.getAttribute('tabindex') !== '-1' && !(0, _isDisabled.isDisabled)(el) && // Hidden elements are not tabable
|
|
20
|
+
(0, _isVisible.isVisible)(el));
|
|
21
|
+
|
|
22
|
+
if (activeElement.getAttribute('tabindex') !== '-1') {
|
|
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')));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const checkedRadio = {};
|
|
28
|
+
let prunedElements = [document.body];
|
|
29
|
+
const activeRadioGroup = (0, _isElementType.isElementType)(activeElement, 'input', {
|
|
30
|
+
type: 'radio'
|
|
31
|
+
}) ? activeElement.name : undefined;
|
|
32
|
+
enabledElements.forEach(currentElement => {
|
|
33
|
+
const el = currentElement; // For radio groups keep only the active radio
|
|
34
|
+
// If there is no active radio, keep only the checked radio
|
|
35
|
+
// If there is no checked radio, treat like everything else
|
|
36
|
+
|
|
37
|
+
if ((0, _isElementType.isElementType)(el, 'input', {
|
|
38
|
+
type: 'radio'
|
|
39
|
+
}) && el.name) {
|
|
40
|
+
// If the active element is part of the group, add only that
|
|
41
|
+
if (el === activeElement) {
|
|
42
|
+
prunedElements.push(el);
|
|
43
|
+
return;
|
|
44
|
+
} else if (el.name === activeRadioGroup) {
|
|
45
|
+
return;
|
|
46
|
+
} // If we stumble upon a checked radio, remove the others
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
if (el.checked) {
|
|
50
|
+
prunedElements = prunedElements.filter(e => !(0, _isElementType.isElementType)(e, 'input', {
|
|
51
|
+
type: 'radio',
|
|
52
|
+
name: el.name
|
|
53
|
+
}));
|
|
54
|
+
prunedElements.push(el);
|
|
55
|
+
checkedRadio[el.name] = el;
|
|
56
|
+
return;
|
|
57
|
+
} // If we already found the checked one, skip
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
if (typeof checkedRadio[el.name] !== 'undefined') {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
prunedElements.push(el);
|
|
66
|
+
});
|
|
67
|
+
const currentIndex = prunedElements.findIndex(el => el === activeElement);
|
|
68
|
+
const nextIndex = shift ? currentIndex - 1 : currentIndex + 1;
|
|
69
|
+
const defaultIndex = shift ? prunedElements.length - 1 : 0;
|
|
70
|
+
return prunedElements[nextIndex] || prunedElements[defaultIndex];
|
|
71
|
+
}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export * from './edit/selectionRange';
|
|
|
13
13
|
export * from './focus/blur';
|
|
14
14
|
export * from './focus/focus';
|
|
15
15
|
export * from './focus/getActiveElement';
|
|
16
|
+
export * from './focus/getTabDestination';
|
|
16
17
|
export * from './focus/isFocusable';
|
|
17
18
|
export * from './focus/selector';
|
|
18
19
|
export * from './keyDef/readNextDescriptor';
|
|
@@ -22,7 +23,6 @@ export * from './misc/isDescendantOrSelf';
|
|
|
22
23
|
export * from './misc/isElementType';
|
|
23
24
|
export * from './misc/isVisible';
|
|
24
25
|
export * from './misc/isDisabled';
|
|
25
|
-
export * from './misc/isDocument';
|
|
26
26
|
export * from './misc/wait';
|
|
27
27
|
export * from './misc/hasPointerEvents';
|
|
28
28
|
export * from './misc/hasFormSubmit';
|
package/dist/utils/index.js
CHANGED
|
@@ -199,6 +199,19 @@ Object.keys(_getActiveElement).forEach(function (key) {
|
|
|
199
199
|
});
|
|
200
200
|
});
|
|
201
201
|
|
|
202
|
+
var _getTabDestination = require("./focus/getTabDestination");
|
|
203
|
+
|
|
204
|
+
Object.keys(_getTabDestination).forEach(function (key) {
|
|
205
|
+
if (key === "default" || key === "__esModule") return;
|
|
206
|
+
if (key in exports && exports[key] === _getTabDestination[key]) return;
|
|
207
|
+
Object.defineProperty(exports, key, {
|
|
208
|
+
enumerable: true,
|
|
209
|
+
get: function () {
|
|
210
|
+
return _getTabDestination[key];
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
|
|
202
215
|
var _isFocusable = require("./focus/isFocusable");
|
|
203
216
|
|
|
204
217
|
Object.keys(_isFocusable).forEach(function (key) {
|
|
@@ -316,19 +329,6 @@ Object.keys(_isDisabled).forEach(function (key) {
|
|
|
316
329
|
});
|
|
317
330
|
});
|
|
318
331
|
|
|
319
|
-
var _isDocument = require("./misc/isDocument");
|
|
320
|
-
|
|
321
|
-
Object.keys(_isDocument).forEach(function (key) {
|
|
322
|
-
if (key === "default" || key === "__esModule") return;
|
|
323
|
-
if (key in exports && exports[key] === _isDocument[key]) return;
|
|
324
|
-
Object.defineProperty(exports, key, {
|
|
325
|
-
enumerable: true,
|
|
326
|
-
get: function () {
|
|
327
|
-
return _isDocument[key];
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
});
|
|
331
|
-
|
|
332
332
|
var _wait = require("./misc/wait");
|
|
333
333
|
|
|
334
334
|
Object.keys(_wait).forEach(function (key) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface PointerCoords {
|
|
2
2
|
x?: number;
|
|
3
3
|
y?: number;
|
|
4
4
|
clientX?: number;
|
|
@@ -7,10 +7,14 @@ export interface FakeEventInit extends MouseEventInit, PointerEventInit {
|
|
|
7
7
|
offsetY?: number;
|
|
8
8
|
pageX?: number;
|
|
9
9
|
pageY?: number;
|
|
10
|
+
screenX?: number;
|
|
11
|
+
screenY?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface FakePointerEventInit extends MouseEventInit, PointerEventInit, PointerCoords {
|
|
10
14
|
}
|
|
11
15
|
export declare class FakeMouseEvent extends MouseEvent {
|
|
12
|
-
constructor(type: string, init:
|
|
16
|
+
constructor(type: string, init: FakePointerEventInit);
|
|
13
17
|
}
|
|
14
18
|
export declare class FakePointerEvent extends MouseEvent {
|
|
15
|
-
constructor(type: string, init:
|
|
19
|
+
constructor(type: string, init: FakePointerEventInit);
|
|
16
20
|
}
|
|
@@ -22,17 +22,26 @@ function assignPositionInit(obj, {
|
|
|
22
22
|
offsetX,
|
|
23
23
|
offsetY,
|
|
24
24
|
pageX,
|
|
25
|
-
pageY
|
|
25
|
+
pageY,
|
|
26
|
+
screenX,
|
|
27
|
+
screenY
|
|
26
28
|
}) {
|
|
29
|
+
var _ref, _ref2, _ref3, _ref4;
|
|
30
|
+
|
|
27
31
|
assignProps(obj, {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
/* istanbul ignore start */
|
|
33
|
+
x: (_ref = x != null ? x : clientX) != null ? _ref : 0,
|
|
34
|
+
y: (_ref2 = y != null ? y : clientY) != null ? _ref2 : 0,
|
|
35
|
+
clientX: (_ref3 = x != null ? x : clientX) != null ? _ref3 : 0,
|
|
36
|
+
clientY: (_ref4 = y != null ? y : clientY) != null ? _ref4 : 0,
|
|
37
|
+
offsetX: offsetX != null ? offsetX : 0,
|
|
38
|
+
offsetY: offsetY != null ? offsetY : 0,
|
|
39
|
+
pageX: pageX != null ? pageX : 0,
|
|
40
|
+
pageY: pageY != null ? pageY : 0,
|
|
41
|
+
screenX: screenX != null ? screenX : 0,
|
|
42
|
+
screenY: screenY != null ? screenY : 0
|
|
43
|
+
/* istanbul ignore end */
|
|
44
|
+
|
|
36
45
|
});
|
|
37
46
|
}
|
|
38
47
|
|
|
@@ -1,22 +1,13 @@
|
|
|
1
1
|
import type { pointerState } from '../../pointer/types';
|
|
2
2
|
import type { keyboardState } from '../../keyboard/types';
|
|
3
|
+
import { PointerCoords } from './fakeEvent';
|
|
3
4
|
import { MouseButton } from './mouseButtons';
|
|
4
|
-
export interface Coords {
|
|
5
|
-
x: number;
|
|
6
|
-
y: number;
|
|
7
|
-
clientX: number;
|
|
8
|
-
clientY: number;
|
|
9
|
-
offsetX: number;
|
|
10
|
-
offsetY: number;
|
|
11
|
-
pageX: number;
|
|
12
|
-
pageY: number;
|
|
13
|
-
}
|
|
14
5
|
export declare function firePointerEvent(target: Element, type: string, { pointerState, keyboardState, pointerType, button, coords, pointerId, isPrimary, clickCount, }: {
|
|
15
6
|
pointerState: pointerState;
|
|
16
7
|
keyboardState: keyboardState;
|
|
17
8
|
pointerType?: 'mouse' | 'pen' | 'touch';
|
|
18
9
|
button?: MouseButton;
|
|
19
|
-
coords
|
|
10
|
+
coords?: PointerCoords;
|
|
20
11
|
pointerId?: number;
|
|
21
12
|
isPrimary?: boolean;
|
|
22
13
|
clickCount?: number;
|
package/package.json
CHANGED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* React tracks the changes on element properties.
|
|
3
|
-
* This workaround tries to alter the DOM element without React noticing,
|
|
4
|
-
* so that it later picks up the change.
|
|
5
|
-
*
|
|
6
|
-
* @see https://github.com/facebook/react/blob/148f8e497c7d37a3c7ab99f01dec2692427272b1/packages/react-dom/src/client/inputValueTracking.js#L51-L104
|
|
7
|
-
*/
|
|
8
|
-
export declare function applyNative<T extends Element, P extends keyof T>(element: T, propName: P, propValue: T[P]): void;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.applyNative = applyNative;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* React tracks the changes on element properties.
|
|
10
|
-
* This workaround tries to alter the DOM element without React noticing,
|
|
11
|
-
* so that it later picks up the change.
|
|
12
|
-
*
|
|
13
|
-
* @see https://github.com/facebook/react/blob/148f8e497c7d37a3c7ab99f01dec2692427272b1/packages/react-dom/src/client/inputValueTracking.js#L51-L104
|
|
14
|
-
*/
|
|
15
|
-
function applyNative(element, propName, propValue) {
|
|
16
|
-
const descriptor = Object.getOwnPropertyDescriptor(element, propName);
|
|
17
|
-
const nativeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
|
|
18
|
-
|
|
19
|
-
if (descriptor && nativeDescriptor) {
|
|
20
|
-
Object.defineProperty(element, propName, nativeDescriptor);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
element[propName] = propValue;
|
|
24
|
-
|
|
25
|
-
if (descriptor) {
|
|
26
|
-
Object.defineProperty(element, propName, descriptor);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isDocument(el: Document | Element): el is Document;
|