@testing-library/user-event 13.5.0 → 14.0.0-alpha.4
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/README.md +3 -0
- package/dist/clear.d.ts +2 -2
- package/dist/clear.js +1 -3
- package/dist/click.d.ts +3 -3
- package/dist/click.js +13 -144
- package/dist/document/index.d.ts +9 -0
- package/dist/document/index.js +100 -0
- package/dist/document/interceptor.d.ts +15 -0
- package/dist/document/interceptor.js +37 -0
- package/dist/document/selection.d.ts +17 -0
- package/dist/document/selection.js +64 -0
- package/dist/document/value.d.ts +18 -0
- package/dist/document/value.js +77 -0
- package/dist/hover.d.ts +3 -3
- package/dist/hover.js +15 -57
- package/dist/index.d.ts +4 -21
- package/dist/index.js +4 -29
- package/dist/keyboard/getNextKeyDef.js +3 -92
- package/dist/keyboard/index.d.ts +1 -0
- package/dist/keyboard/index.js +4 -0
- package/dist/keyboard/keyMap.js +4 -0
- package/dist/keyboard/plugins/character.js +8 -18
- package/dist/keyboard/plugins/control.js +3 -6
- package/dist/keyboard/plugins/functional.js +20 -6
- package/dist/keyboard/plugins/index.js +2 -4
- package/dist/keyboard/shared/index.d.ts +0 -2
- package/dist/keyboard/shared/index.js +0 -26
- package/dist/keyboard/types.d.ts +3 -0
- package/dist/paste.d.ts +3 -2
- package/dist/pointer/index.d.ts +18 -0
- package/dist/pointer/index.js +90 -0
- package/dist/pointer/keyMap.d.ts +2 -0
- package/dist/pointer/keyMap.js +29 -0
- package/dist/pointer/parseKeyDef.d.ts +6 -0
- package/dist/pointer/parseKeyDef.js +36 -0
- package/dist/pointer/pointerAction.d.ts +6 -0
- package/dist/pointer/pointerAction.js +52 -0
- package/dist/pointer/pointerMove.d.ts +5 -0
- package/dist/pointer/pointerMove.js +125 -0
- package/dist/pointer/pointerPress.d.ts +7 -0
- package/dist/pointer/pointerPress.js +328 -0
- package/dist/pointer/resolveSelectionTarget.d.ts +5 -0
- package/dist/pointer/resolveSelectionTarget.js +74 -0
- package/dist/pointer/types.d.ts +72 -0
- package/dist/pointer/types.js +1 -0
- package/dist/selectOptions.d.ts +4 -0
- package/dist/{select-options.js → selectOptions.js} +18 -20
- package/dist/setup.d.ts +89 -0
- package/dist/setup.js +206 -0
- package/dist/tab.d.ts +3 -3
- package/dist/tab.js +18 -97
- package/dist/type.d.ts +14 -0
- package/dist/type.js +74 -0
- package/dist/upload.d.ts +4 -3
- package/dist/upload.js +3 -9
- package/dist/{keyboard/shared → utils/edit}/fireInputEvent.d.ts +0 -9
- package/dist/utils/edit/fireInputEvent.js +59 -0
- package/dist/utils/edit/getValue.d.ts +1 -1
- package/dist/utils/edit/getValue.js +3 -1
- package/dist/utils/edit/selectionRange.d.ts +0 -11
- package/dist/utils/edit/selectionRange.js +9 -49
- package/dist/{blur.d.ts → utils/focus/blur.d.ts} +0 -0
- package/dist/utils/focus/blur.js +19 -0
- package/dist/{focus.d.ts → utils/focus/focus.d.ts} +0 -0
- package/dist/utils/focus/focus.js +19 -0
- package/dist/utils/focus/getTabDestination.d.ts +1 -0
- package/dist/utils/focus/getTabDestination.js +72 -0
- package/dist/utils/focus/isFocusable.js +1 -3
- package/dist/utils/index.d.ts +10 -3
- package/dist/utils/index.js +120 -29
- package/dist/utils/keyDef/readNextDescriptor.d.ts +19 -0
- package/dist/utils/keyDef/readNextDescriptor.js +102 -0
- package/dist/utils/misc/findClosest.d.ts +1 -0
- package/dist/utils/misc/findClosest.js +20 -0
- package/dist/utils/misc/isDescendantOrSelf.d.ts +1 -0
- package/dist/utils/misc/isDescendantOrSelf.js +20 -0
- package/dist/utils/pointer/fakeEvent.d.ts +20 -0
- package/dist/utils/pointer/fakeEvent.js +91 -0
- package/dist/utils/pointer/firePointerEvents.d.ts +14 -0
- package/dist/utils/pointer/firePointerEvents.js +55 -0
- package/dist/utils/pointer/mouseButtons.d.ts +12 -0
- package/dist/utils/pointer/mouseButtons.js +45 -0
- package/package.json +4 -3
- package/dist/blur.js +0 -15
- package/dist/dom-helpers.d.ts +0 -3
- package/dist/focus.js +0 -15
- package/dist/keyboard/shared/carryValue.d.ts +0 -2
- package/dist/keyboard/shared/carryValue.js +0 -13
- package/dist/keyboard/shared/fireInputEvent.js +0 -110
- package/dist/select-options.d.ts +0 -4
- package/dist/type/index.d.ts +0 -7
- package/dist/type/index.js +0 -33
- package/dist/type/typeImplementation.d.ts +0 -10
- package/dist/type/typeImplementation.js +0 -64
- package/dist/utils/click/getMouseEventOptions.d.ts +0 -31
- package/dist/utils/click/getMouseEventOptions.js +0 -61
- package/dist/utils/edit/hasUnreliableEmptyValue.d.ts +0 -10
- package/dist/utils/edit/hasUnreliableEmptyValue.js +0 -21
- package/dist/utils/misc/isLabelWithInternallyDisabledControl.d.ts +0 -1
- package/dist/utils/misc/isLabelWithInternallyDisabledControl.js +0 -22
package/README.md
CHANGED
|
@@ -257,6 +257,9 @@ Thanks goes to these people ([emoji key][emojis]):
|
|
|
257
257
|
<td align="center"><a href="https://johannesfischer.github.io/"><img src="https://avatars.githubusercontent.com/u/28100?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Johannes Fischer</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=JohannesFischer" title="Code">💻</a></td>
|
|
258
258
|
<td align="center"><a href="https://github.com/777PolarFox777"><img src="https://avatars.githubusercontent.com/u/19393384?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Andrew D.</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=777PolarFox777" title="Code">💻</a></td>
|
|
259
259
|
</tr>
|
|
260
|
+
<tr>
|
|
261
|
+
<td align="center"><a href="https://github.com/patricklizon"><img src="https://avatars.githubusercontent.com/u/12571855?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Patrick Lizoń</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=patricklizon" title="Code">💻</a></td>
|
|
262
|
+
</tr>
|
|
260
263
|
</table>
|
|
261
264
|
|
|
262
265
|
<!-- markdownlint-restore -->
|
package/dist/clear.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
1
|
+
import type { UserEvent } from './setup';
|
|
2
|
+
export declare function clear(this: UserEvent, element: Element): void;
|
package/dist/clear.js
CHANGED
|
@@ -7,8 +7,6 @@ exports.clear = clear;
|
|
|
7
7
|
|
|
8
8
|
var _utils = require("./utils");
|
|
9
9
|
|
|
10
|
-
var _type = require("./type");
|
|
11
|
-
|
|
12
10
|
function clear(element) {
|
|
13
11
|
var _element$selectionSta, _element$selectionEnd;
|
|
14
12
|
|
|
@@ -31,7 +29,7 @@ function clear(element) {
|
|
|
31
29
|
element.type = 'text';
|
|
32
30
|
}
|
|
33
31
|
|
|
34
|
-
|
|
32
|
+
this.type(element, '{selectall}{del}', {
|
|
35
33
|
delay: 0,
|
|
36
34
|
initialSelectionStart: (_element$selectionSta = element.selectionStart) != null ? _element$selectionSta :
|
|
37
35
|
/* istanbul ignore next */
|
package/dist/click.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { PointerOptions } from './utils';
|
|
2
|
+
import type { UserEvent } from './setup';
|
|
2
3
|
export declare interface clickOptions {
|
|
3
4
|
skipHover?: boolean;
|
|
4
5
|
clickCount?: number;
|
|
5
6
|
}
|
|
6
|
-
declare function click(element: Element, init?: MouseEventInit, { skipHover,
|
|
7
|
-
declare function dblClick(element: Element, init?: MouseEventInit, { skipPointerEventsCheck }?: clickOptions & PointerOptions): void;
|
|
8
|
-
export { click, dblClick };
|
|
7
|
+
export declare function click(this: UserEvent, element: Element, init?: MouseEventInit, { skipHover, skipPointerEventsCheck, }?: clickOptions & PointerOptions): void;
|
|
8
|
+
export declare function dblClick(this: UserEvent, element: Element, init?: MouseEventInit, { skipPointerEventsCheck }?: clickOptions & PointerOptions): void;
|
package/dist/click.js
CHANGED
|
@@ -6,149 +6,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.click = click;
|
|
7
7
|
exports.dblClick = dblClick;
|
|
8
8
|
|
|
9
|
-
var _dom = require("@testing-library/dom");
|
|
10
|
-
|
|
11
9
|
var _utils = require("./utils");
|
|
12
10
|
|
|
13
|
-
var _hover = require("./hover");
|
|
14
|
-
|
|
15
|
-
var _blur = require("./blur");
|
|
16
|
-
|
|
17
|
-
var _focus = require("./focus");
|
|
18
|
-
|
|
19
|
-
function getPreviouslyFocusedElement(element) {
|
|
20
|
-
const focusedElement = element.ownerDocument.activeElement;
|
|
21
|
-
const wasAnotherElementFocused = focusedElement && focusedElement !== element.ownerDocument.body && focusedElement !== element;
|
|
22
|
-
return wasAnotherElementFocused ? focusedElement : null;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function clickLabel(label, init, {
|
|
26
|
-
clickCount
|
|
27
|
-
}) {
|
|
28
|
-
if ((0, _utils.isLabelWithInternallyDisabledControl)(label)) return;
|
|
29
|
-
|
|
30
|
-
_dom.fireEvent.pointerDown(label, init);
|
|
31
|
-
|
|
32
|
-
_dom.fireEvent.mouseDown(label, (0, _utils.getMouseEventOptions)('mousedown', init, clickCount));
|
|
33
|
-
|
|
34
|
-
_dom.fireEvent.pointerUp(label, init);
|
|
35
|
-
|
|
36
|
-
_dom.fireEvent.mouseUp(label, (0, _utils.getMouseEventOptions)('mouseup', init, clickCount));
|
|
37
|
-
|
|
38
|
-
fireClick(label, (0, _utils.getMouseEventOptions)('click', init, clickCount)); // clicking the label will trigger a click of the label.control
|
|
39
|
-
// however, it will not focus the label.control so we have to do it
|
|
40
|
-
// ourselves.
|
|
41
|
-
|
|
42
|
-
if (label.control) (0, _focus.focus)(label.control);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function clickBooleanElement(element, init, {
|
|
46
|
-
clickCount
|
|
47
|
-
}) {
|
|
48
|
-
_dom.fireEvent.pointerDown(element, init);
|
|
49
|
-
|
|
50
|
-
if (!element.disabled) {
|
|
51
|
-
_dom.fireEvent.mouseDown(element, (0, _utils.getMouseEventOptions)('mousedown', init, clickCount));
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
(0, _focus.focus)(element);
|
|
55
|
-
|
|
56
|
-
_dom.fireEvent.pointerUp(element, init);
|
|
57
|
-
|
|
58
|
-
if (!element.disabled) {
|
|
59
|
-
_dom.fireEvent.mouseUp(element, (0, _utils.getMouseEventOptions)('mouseup', init, clickCount));
|
|
60
|
-
|
|
61
|
-
fireClick(element, (0, _utils.getMouseEventOptions)('click', init, clickCount));
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function clickElement(element, init, {
|
|
66
|
-
clickCount
|
|
67
|
-
}) {
|
|
68
|
-
const previousElement = getPreviouslyFocusedElement(element);
|
|
69
|
-
|
|
70
|
-
_dom.fireEvent.pointerDown(element, init);
|
|
71
|
-
|
|
72
|
-
if (!(0, _utils.isDisabled)(element)) {
|
|
73
|
-
const continueDefaultHandling = _dom.fireEvent.mouseDown(element, (0, _utils.getMouseEventOptions)('mousedown', init, clickCount));
|
|
74
|
-
|
|
75
|
-
if (continueDefaultHandling) {
|
|
76
|
-
const closestFocusable = findClosest(element, _utils.isFocusable);
|
|
77
|
-
|
|
78
|
-
if (previousElement && !closestFocusable) {
|
|
79
|
-
(0, _blur.blur)(previousElement);
|
|
80
|
-
} else if (closestFocusable) {
|
|
81
|
-
(0, _focus.focus)(closestFocusable);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
_dom.fireEvent.pointerUp(element, init);
|
|
87
|
-
|
|
88
|
-
if (!(0, _utils.isDisabled)(element)) {
|
|
89
|
-
_dom.fireEvent.mouseUp(element, (0, _utils.getMouseEventOptions)('mouseup', init, clickCount));
|
|
90
|
-
|
|
91
|
-
fireClick(element, (0, _utils.getMouseEventOptions)('click', init, clickCount));
|
|
92
|
-
const parentLabel = element.closest('label');
|
|
93
|
-
if (parentLabel != null && parentLabel.control) (0, _focus.focus)(parentLabel.control);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function findClosest(element, callback) {
|
|
98
|
-
let el = element;
|
|
99
|
-
|
|
100
|
-
do {
|
|
101
|
-
if (callback(el)) {
|
|
102
|
-
return el;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
el = el.parentElement;
|
|
106
|
-
} while (el && el !== element.ownerDocument.body);
|
|
107
|
-
|
|
108
|
-
return undefined;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
11
|
function click(element, init, {
|
|
112
12
|
skipHover = false,
|
|
113
|
-
clickCount = 0,
|
|
114
13
|
skipPointerEventsCheck = false
|
|
115
14
|
} = {}) {
|
|
116
15
|
if (!skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
|
|
117
16
|
throw new Error('unable to click element as it has or inherits pointer-events set to "none".');
|
|
118
|
-
} //
|
|
17
|
+
} // istanbul ignore else
|
|
119
18
|
|
|
120
19
|
|
|
121
|
-
if (!skipHover)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if ((0, _utils.isElementType)(element, 'label')) {
|
|
126
|
-
clickLabel(element, init, {
|
|
127
|
-
clickCount
|
|
128
|
-
});
|
|
129
|
-
} else if ((0, _utils.isElementType)(element, 'input')) {
|
|
130
|
-
if (element.type === 'checkbox' || element.type === 'radio') {
|
|
131
|
-
clickBooleanElement(element, init, {
|
|
132
|
-
clickCount
|
|
133
|
-
});
|
|
134
|
-
} else {
|
|
135
|
-
clickElement(element, init, {
|
|
136
|
-
clickCount
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
} else {
|
|
140
|
-
clickElement(element, init, {
|
|
141
|
-
clickCount
|
|
20
|
+
if (!skipHover) // We just checked for `pointerEvents`. We can always skip this one in `hover`.
|
|
21
|
+
this.hover(element, init, {
|
|
22
|
+
skipPointerEventsCheck: true
|
|
142
23
|
});
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
_dom.fireEvent.contextMenu(element, mouseEventOptions);
|
|
149
|
-
} else {
|
|
150
|
-
_dom.fireEvent.click(element, mouseEventOptions);
|
|
151
|
-
}
|
|
24
|
+
const keys = (init == null ? void 0 : init.button) === 2 || (init == null ? void 0 : init.buttons) === 2 ? '[MouseRight]' : '[MouseLeft]';
|
|
25
|
+
this.pointer({
|
|
26
|
+
keys,
|
|
27
|
+
target: element
|
|
28
|
+
});
|
|
152
29
|
}
|
|
153
30
|
|
|
154
31
|
function dblClick(element, init, {
|
|
@@ -158,19 +35,11 @@ function dblClick(element, init, {
|
|
|
158
35
|
throw new Error('unable to double-click element as it has or inherits pointer-events set to "none".');
|
|
159
36
|
}
|
|
160
37
|
|
|
161
|
-
|
|
162
|
-
skipPointerEventsCheck
|
|
163
|
-
});
|
|
164
|
-
click(element, init, {
|
|
165
|
-
skipHover: true,
|
|
166
|
-
clickCount: 0,
|
|
38
|
+
this.hover(element, init, {
|
|
167
39
|
skipPointerEventsCheck
|
|
168
40
|
});
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
skipPointerEventsCheck
|
|
41
|
+
this.pointer({
|
|
42
|
+
keys: '[MouseLeft][MouseLeft]',
|
|
43
|
+
target: element
|
|
173
44
|
});
|
|
174
|
-
|
|
175
|
-
_dom.fireEvent.dblClick(element, (0, _utils.getMouseEventOptions)('dblclick', init, 2));
|
|
176
45
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const isPrepared: unique symbol;
|
|
2
|
+
declare global {
|
|
3
|
+
interface Node {
|
|
4
|
+
[isPrepared]?: typeof isPrepared;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export declare function prepareDocument(document: Document): void;
|
|
8
|
+
export { getUIValue, setUIValue, startTrackValue, endTrackValue } from './value';
|
|
9
|
+
export { getUISelection, setUISelection } from './selection';
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "endTrackValue", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _value.endTrackValue;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "getUISelection", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _selection.getUISelection;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "getUIValue", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _value.getUIValue;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
exports.prepareDocument = prepareDocument;
|
|
25
|
+
Object.defineProperty(exports, "setUISelection", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return _selection.setUISelection;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, "setUIValue", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () {
|
|
34
|
+
return _value.setUIValue;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(exports, "startTrackValue", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function () {
|
|
40
|
+
return _value.startTrackValue;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
var _dom = require("@testing-library/dom");
|
|
45
|
+
|
|
46
|
+
var _selection = require("./selection");
|
|
47
|
+
|
|
48
|
+
var _value = require("./value");
|
|
49
|
+
|
|
50
|
+
const isPrepared = Symbol('Node prepared with document state workarounds');
|
|
51
|
+
|
|
52
|
+
function prepareDocument(document) {
|
|
53
|
+
if (document[isPrepared]) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
document.addEventListener('focus', e => {
|
|
58
|
+
const el = e.target;
|
|
59
|
+
prepareElement(el);
|
|
60
|
+
}, {
|
|
61
|
+
capture: true,
|
|
62
|
+
passive: true
|
|
63
|
+
}); // Our test environment defaults to `document.body` as `activeElement`.
|
|
64
|
+
// In other environments this might be `null` when preparing.
|
|
65
|
+
// istanbul ignore else
|
|
66
|
+
|
|
67
|
+
if (document.activeElement) {
|
|
68
|
+
prepareElement(document.activeElement);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
document.addEventListener('blur', e => {
|
|
72
|
+
const el = e.target;
|
|
73
|
+
const initialValue = (0, _value.getInitialValue)(el);
|
|
74
|
+
|
|
75
|
+
if (typeof initialValue === 'string' && el.value !== initialValue) {
|
|
76
|
+
_dom.fireEvent.change(el);
|
|
77
|
+
}
|
|
78
|
+
}, {
|
|
79
|
+
capture: true,
|
|
80
|
+
passive: true
|
|
81
|
+
});
|
|
82
|
+
document[isPrepared] = isPrepared;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function prepareElement(el) {
|
|
86
|
+
if ('value' in el) {
|
|
87
|
+
(0, _value.setInitialValue)(el);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (el[isPrepared]) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if ('value' in el) {
|
|
95
|
+
(0, _value.prepareValueInterceptor)(el);
|
|
96
|
+
(0, _selection.prepareSelectionInterceptor)(el);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
el[isPrepared] = isPrepared;
|
|
100
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare type anyFunc = (...a: any[]) => any;
|
|
2
|
+
declare type Params<Prop> = Prop extends anyFunc ? Parameters<Prop> : [Prop];
|
|
3
|
+
declare type ImplReturn<Prop> = Prop extends anyFunc ? Parameters<Prop> : Prop;
|
|
4
|
+
export declare function prepareInterceptor<ElementType extends Node, PropName extends keyof ElementType>(element: ElementType, propName: PropName, interceptorImpl: (this: ElementType, ...args: Params<ElementType[PropName]>) => {
|
|
5
|
+
/**
|
|
6
|
+
* React tracks the changes on element properties.
|
|
7
|
+
* This workaround tries to alter the DOM element without React noticing,
|
|
8
|
+
* so that it later picks up the change.
|
|
9
|
+
*
|
|
10
|
+
* @see https://github.com/facebook/react/blob/148f8e497c7d37a3c7ab99f01dec2692427272b1/packages/react-dom/src/client/inputValueTracking.js#L51-L104
|
|
11
|
+
*/
|
|
12
|
+
applyNative?: boolean;
|
|
13
|
+
realArgs?: ImplReturn<ElementType[PropName]>;
|
|
14
|
+
}): void;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.prepareInterceptor = prepareInterceptor;
|
|
7
|
+
const Interceptor = Symbol('Interceptor for programmatical calls');
|
|
8
|
+
|
|
9
|
+
function prepareInterceptor(element, propName, interceptorImpl) {
|
|
10
|
+
const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
|
|
11
|
+
const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
|
|
12
|
+
const target = prototypeDescriptor != null && prototypeDescriptor.set ? 'set' : 'value';
|
|
13
|
+
|
|
14
|
+
if (typeof (prototypeDescriptor == null ? void 0 : prototypeDescriptor[target]) !== 'function' || prototypeDescriptor[target][Interceptor]) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function intercept(...args) {
|
|
19
|
+
const {
|
|
20
|
+
applyNative = true,
|
|
21
|
+
realArgs
|
|
22
|
+
} = interceptorImpl.call(this, ...args);
|
|
23
|
+
const realFunc = (!applyNative && objectDescriptor || prototypeDescriptor)[target];
|
|
24
|
+
|
|
25
|
+
if (target === 'set') {
|
|
26
|
+
realFunc.call(this, realArgs);
|
|
27
|
+
} else {
|
|
28
|
+
realFunc.call(this, ...realArgs);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
;
|
|
33
|
+
intercept[Interceptor] = Interceptor;
|
|
34
|
+
Object.defineProperty(element, propName, { ...(objectDescriptor != null ? objectDescriptor : prototypeDescriptor),
|
|
35
|
+
[target]: intercept
|
|
36
|
+
});
|
|
37
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare const UISelection: unique symbol;
|
|
2
|
+
declare global {
|
|
3
|
+
interface Element {
|
|
4
|
+
[UISelection]?: {
|
|
5
|
+
start: number;
|
|
6
|
+
end: number;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export declare function prepareSelectionInterceptor(element: HTMLInputElement | HTMLTextAreaElement): void;
|
|
11
|
+
export declare function setUISelection(element: HTMLInputElement | HTMLTextAreaElement, start: number, end: number): void;
|
|
12
|
+
export declare function getUISelection(element: HTMLInputElement | HTMLTextAreaElement): {
|
|
13
|
+
selectionStart: number | null;
|
|
14
|
+
selectionEnd: number | null;
|
|
15
|
+
};
|
|
16
|
+
export declare function clearUISelection(element: HTMLInputElement | HTMLTextAreaElement): void;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.clearUISelection = clearUISelection;
|
|
7
|
+
exports.getUISelection = getUISelection;
|
|
8
|
+
exports.prepareSelectionInterceptor = prepareSelectionInterceptor;
|
|
9
|
+
exports.setUISelection = setUISelection;
|
|
10
|
+
|
|
11
|
+
var _interceptor = require("./interceptor");
|
|
12
|
+
|
|
13
|
+
const UISelection = Symbol('Displayed selection in UI');
|
|
14
|
+
|
|
15
|
+
function setSelectionInterceptor(start, end, direction = 'none') {
|
|
16
|
+
const isUI = start && typeof start === 'object' && start[UISelection];
|
|
17
|
+
this[UISelection] = isUI ? {
|
|
18
|
+
start: start.valueOf(),
|
|
19
|
+
end: Number(end)
|
|
20
|
+
} : undefined;
|
|
21
|
+
return {
|
|
22
|
+
realArgs: [Number(start), end, direction]
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function prepareSelectionInterceptor(element) {
|
|
27
|
+
(0, _interceptor.prepareInterceptor)(element, 'setSelectionRange', setSelectionInterceptor);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function setUISelection(element, start, end) {
|
|
31
|
+
element[UISelection] = {
|
|
32
|
+
start,
|
|
33
|
+
end
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
if (element.selectionStart === start && element.selectionEnd === end) {
|
|
37
|
+
return;
|
|
38
|
+
} // eslint-disable-next-line no-new-wrappers
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
const startObj = new Number(start);
|
|
42
|
+
startObj[UISelection] = UISelection;
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
element.setSelectionRange(startObj, end);
|
|
46
|
+
} catch {// DOMException for invalid state is expected when calling this
|
|
47
|
+
// on an element without support for setSelectionRange
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function getUISelection(element) {
|
|
52
|
+
const ui = element[UISelection];
|
|
53
|
+
return ui === undefined ? {
|
|
54
|
+
selectionStart: element.selectionStart,
|
|
55
|
+
selectionEnd: element.selectionEnd
|
|
56
|
+
} : {
|
|
57
|
+
selectionStart: ui.start,
|
|
58
|
+
selectionEnd: ui.end
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function clearUISelection(element) {
|
|
63
|
+
element[UISelection] = undefined;
|
|
64
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare const UIValue: unique symbol;
|
|
2
|
+
declare const InitialValue: unique symbol;
|
|
3
|
+
declare const TrackChanges: unique symbol;
|
|
4
|
+
declare global {
|
|
5
|
+
interface Element {
|
|
6
|
+
[UIValue]?: string;
|
|
7
|
+
[InitialValue]?: string;
|
|
8
|
+
[TrackChanges]?: string[];
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export declare function prepareValueInterceptor(element: HTMLInputElement): void;
|
|
12
|
+
export declare function setUIValue(element: HTMLInputElement | HTMLTextAreaElement, value: string): void;
|
|
13
|
+
export declare function getUIValue(element: HTMLInputElement | HTMLTextAreaElement): string | undefined;
|
|
14
|
+
export declare function setInitialValue(element: HTMLInputElement | HTMLTextAreaElement): void;
|
|
15
|
+
export declare function getInitialValue(element: HTMLInputElement | HTMLTextAreaElement): string | undefined;
|
|
16
|
+
export declare function startTrackValue(element: HTMLInputElement | HTMLTextAreaElement): void;
|
|
17
|
+
export declare function endTrackValue(element: HTMLInputElement | HTMLTextAreaElement): string[] | undefined;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.endTrackValue = endTrackValue;
|
|
7
|
+
exports.getInitialValue = getInitialValue;
|
|
8
|
+
exports.getUIValue = getUIValue;
|
|
9
|
+
exports.prepareValueInterceptor = prepareValueInterceptor;
|
|
10
|
+
exports.setInitialValue = setInitialValue;
|
|
11
|
+
exports.setUIValue = setUIValue;
|
|
12
|
+
exports.startTrackValue = startTrackValue;
|
|
13
|
+
|
|
14
|
+
var _interceptor = require("./interceptor");
|
|
15
|
+
|
|
16
|
+
var _selection = require("./selection");
|
|
17
|
+
|
|
18
|
+
const UIValue = Symbol('Displayed value in UI');
|
|
19
|
+
const InitialValue = Symbol('Initial value to compare on blur');
|
|
20
|
+
const TrackChanges = Symbol('Track programmatic changes for React workaround');
|
|
21
|
+
|
|
22
|
+
function valueInterceptor(v) {
|
|
23
|
+
const isUI = typeof v === 'object' && v[UIValue];
|
|
24
|
+
this[UIValue] = isUI ? String(v) : undefined;
|
|
25
|
+
|
|
26
|
+
if (!isUI) {
|
|
27
|
+
trackValue(this, String(v));
|
|
28
|
+
this[InitialValue] = String(v); // Programmatically setting the value property
|
|
29
|
+
// moves the cursor to the end of the input.
|
|
30
|
+
|
|
31
|
+
(0, _selection.clearUISelection)(this);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
applyNative: !!isUI,
|
|
36
|
+
realArgs: String(v)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function prepareValueInterceptor(element) {
|
|
41
|
+
(0, _interceptor.prepareInterceptor)(element, 'value', valueInterceptor);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function setUIValue(element, value) {
|
|
45
|
+
element.value = {
|
|
46
|
+
[UIValue]: UIValue,
|
|
47
|
+
toString: () => value
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function getUIValue(element) {
|
|
52
|
+
return element[UIValue] === undefined ? element.value : element[UIValue];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function setInitialValue(element) {
|
|
56
|
+
element[InitialValue] = element.value;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function getInitialValue(element) {
|
|
60
|
+
return element[InitialValue];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function startTrackValue(element) {
|
|
64
|
+
element[TrackChanges] = [];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function trackValue(element, v) {
|
|
68
|
+
var _element$TrackChanges;
|
|
69
|
+
|
|
70
|
+
(_element$TrackChanges = element[TrackChanges]) == null ? void 0 : _element$TrackChanges.push(v);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function endTrackValue(element) {
|
|
74
|
+
const tracked = element[TrackChanges];
|
|
75
|
+
element[TrackChanges] = undefined;
|
|
76
|
+
return tracked;
|
|
77
|
+
}
|
package/dist/hover.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
+
import type { UserEvent } from './setup';
|
|
1
2
|
import { PointerOptions } from './utils';
|
|
2
|
-
declare function hover(element: Element, init?: MouseEventInit, { skipPointerEventsCheck }?: PointerOptions): void;
|
|
3
|
-
declare function unhover(element: Element, init?: MouseEventInit, { skipPointerEventsCheck }?: PointerOptions): void;
|
|
4
|
-
export { hover, unhover };
|
|
3
|
+
export declare function hover(this: UserEvent, element: Element, init?: MouseEventInit, { skipPointerEventsCheck }?: PointerOptions): void;
|
|
4
|
+
export declare function unhover(this: UserEvent, element: Element, init?: MouseEventInit, { skipPointerEventsCheck }?: PointerOptions): void;
|
package/dist/hover.js
CHANGED
|
@@ -6,22 +6,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.hover = hover;
|
|
7
7
|
exports.unhover = unhover;
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _pointer = require("./pointer");
|
|
10
10
|
|
|
11
11
|
var _utils = require("./utils");
|
|
12
12
|
|
|
13
|
-
// includes `element`
|
|
14
|
-
function getParentElements(element) {
|
|
15
|
-
const parentElements = [element];
|
|
16
|
-
let currentElement = element;
|
|
17
|
-
|
|
18
|
-
while ((currentElement = currentElement.parentElement) != null) {
|
|
19
|
-
parentElements.push(currentElement);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return parentElements;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
13
|
function hover(element, init, {
|
|
26
14
|
skipPointerEventsCheck = false
|
|
27
15
|
} = {}) {
|
|
@@ -29,28 +17,13 @@ function hover(element, init, {
|
|
|
29
17
|
throw new Error('unable to hover element as it has or inherits pointer-events set to "none".');
|
|
30
18
|
}
|
|
31
19
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (!(0, _utils.isDisabled)(element)) {
|
|
42
|
-
_dom.fireEvent.mouseOver(element, (0, _utils.getMouseEventOptions)('mouseover', init));
|
|
43
|
-
|
|
44
|
-
for (const el of parentElements) {
|
|
45
|
-
_dom.fireEvent.mouseEnter(el, (0, _utils.getMouseEventOptions)('mouseenter', init));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
_dom.fireEvent.pointerMove(element, init);
|
|
50
|
-
|
|
51
|
-
if (!(0, _utils.isDisabled)(element)) {
|
|
52
|
-
_dom.fireEvent.mouseMove(element, (0, _utils.getMouseEventOptions)('mousemove', init));
|
|
53
|
-
}
|
|
20
|
+
const pointerState = (0, _pointer.createPointerState)();
|
|
21
|
+
pointerState.position.mouse.target = element.ownerDocument.body;
|
|
22
|
+
this.pointer({
|
|
23
|
+
target: element
|
|
24
|
+
}, {
|
|
25
|
+
pointerState
|
|
26
|
+
});
|
|
54
27
|
}
|
|
55
28
|
|
|
56
29
|
function unhover(element, init, {
|
|
@@ -60,26 +33,11 @@ function unhover(element, init, {
|
|
|
60
33
|
throw new Error('unable to unhover element as it has or inherits pointer-events set to "none".');
|
|
61
34
|
}
|
|
62
35
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
_dom.fireEvent.pointerOut(element, init);
|
|
73
|
-
|
|
74
|
-
for (const el of parentElements) {
|
|
75
|
-
_dom.fireEvent.pointerLeave(el, init);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (!(0, _utils.isDisabled)(element)) {
|
|
79
|
-
_dom.fireEvent.mouseOut(element, (0, _utils.getMouseEventOptions)('mouseout', init));
|
|
80
|
-
|
|
81
|
-
for (const el of parentElements) {
|
|
82
|
-
_dom.fireEvent.mouseLeave(el, (0, _utils.getMouseEventOptions)('mouseleave', init));
|
|
83
|
-
}
|
|
84
|
-
}
|
|
36
|
+
const pointerState = (0, _pointer.createPointerState)();
|
|
37
|
+
pointerState.position.mouse.target = element;
|
|
38
|
+
this.pointer({
|
|
39
|
+
target: element.ownerDocument.body
|
|
40
|
+
}, {
|
|
41
|
+
pointerState
|
|
42
|
+
});
|
|
85
43
|
}
|