@testing-library/user-event 14.0.0-alpha.1 → 14.0.0-alpha.10
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/{src/clear.d.ts → clear.d.ts} +0 -0
- package/dist/clear.js +14 -27
- package/dist/{src/click.d.ts → click.d.ts} +1 -0
- package/dist/click.js +17 -0
- package/dist/document/index.d.ts +10 -0
- package/dist/document/index.js +8 -10
- package/dist/document/interceptor.d.ts +15 -0
- package/dist/document/interceptor.js +7 -4
- package/dist/document/selection.d.ts +27 -0
- package/dist/document/selection.js +51 -28
- package/dist/{src/document → document}/value.d.ts +5 -1
- package/dist/document/value.js +27 -6
- package/dist/{src/hover.d.ts → hover.d.ts} +0 -0
- package/dist/{src/index.d.ts → index.d.ts} +0 -0
- package/dist/{src/keyboard → keyboard}/getEventProps.d.ts +0 -0
- package/dist/{src/keyboard → keyboard}/getNextKeyDef.d.ts +0 -0
- package/dist/{src/keyboard → keyboard}/index.d.ts +0 -0
- package/dist/{src/keyboard → keyboard}/keyMap.d.ts +0 -0
- package/dist/keyboard/keyMap.js +4 -0
- package/dist/{src/keyboard → keyboard}/keyboardImplementation.d.ts +0 -0
- package/dist/keyboard/keyboardImplementation.js +3 -1
- package/dist/{src/keyboard → keyboard}/plugins/arrow.d.ts +0 -0
- package/dist/keyboard/plugins/arrow.js +7 -12
- package/dist/{src/keyboard → keyboard}/plugins/character.d.ts +0 -0
- package/dist/keyboard/plugins/character.js +27 -45
- package/dist/keyboard/plugins/combination.d.ts +5 -0
- package/dist/keyboard/plugins/combination.js +17 -0
- package/dist/{src/keyboard → keyboard}/plugins/control.d.ts +0 -0
- package/dist/keyboard/plugins/control.js +4 -12
- package/dist/{src/keyboard → keyboard}/plugins/functional.d.ts +0 -0
- package/dist/keyboard/plugins/functional.js +23 -11
- package/dist/{src/keyboard → keyboard}/plugins/index.d.ts +0 -0
- package/dist/keyboard/plugins/index.js +3 -1
- package/dist/{src/keyboard → keyboard}/shared/fireChangeForInputTimeIfValid.d.ts +0 -0
- package/dist/{src/keyboard → keyboard}/shared/index.d.ts +0 -0
- package/dist/{src/keyboard → keyboard}/specialCharMap.d.ts +0 -0
- package/dist/{src/keyboard → keyboard}/types.d.ts +0 -0
- package/dist/{src/paste.d.ts → paste.d.ts} +0 -0
- package/dist/paste.js +8 -15
- package/dist/{src/pointer → pointer}/index.d.ts +0 -0
- package/dist/{src/pointer → pointer}/keyMap.d.ts +0 -0
- package/dist/{src/pointer → pointer}/parseKeyDef.d.ts +0 -0
- package/dist/{src/pointer → pointer}/pointerAction.d.ts +2 -6
- package/dist/pointer/pointerAction.js +2 -26
- package/dist/pointer/pointerMove.d.ts +5 -0
- package/dist/pointer/pointerMove.js +49 -5
- package/dist/pointer/pointerPress.d.ts +7 -0
- package/dist/pointer/pointerPress.js +135 -29
- package/dist/pointer/resolveSelectionTarget.d.ts +5 -0
- package/dist/pointer/resolveSelectionTarget.js +75 -0
- package/dist/{src/pointer → pointer}/types.d.ts +18 -4
- package/dist/{src/selectOptions.d.ts → selectOptions.d.ts} +0 -0
- package/dist/{src/setup.d.ts → setup.d.ts} +5 -2
- package/dist/setup.js +4 -7
- package/dist/tab.d.ts +5 -0
- package/dist/tab.js +3 -132
- package/dist/{src/type.d.ts → type.d.ts} +0 -0
- package/dist/type.js +3 -19
- package/dist/{src/upload.d.ts → upload.d.ts} +0 -0
- package/dist/{src/utils → utils}/click/isClickableInput.d.ts +0 -0
- package/dist/{src/utils → utils}/edit/buildTimeValue.d.ts +0 -0
- package/dist/utils/edit/calculateNewValue.d.ts +14 -0
- package/dist/utils/edit/calculateNewValue.js +19 -21
- package/dist/utils/edit/editInputElement.d.ts +16 -0
- package/dist/utils/edit/editInputElement.js +53 -0
- package/dist/{src/utils → utils}/edit/getValue.d.ts +0 -0
- package/dist/utils/edit/getValue.js +1 -3
- package/dist/utils/edit/isContentEditable.d.ts +7 -0
- package/dist/utils/edit/isContentEditable.js +14 -0
- package/dist/{src/utils → utils}/edit/isEditable.d.ts +1 -0
- package/dist/{src/utils → utils}/edit/isValidDateValue.d.ts +0 -0
- package/dist/{src/utils → utils}/edit/isValidInputTimeValue.d.ts +0 -0
- package/dist/{src/utils → utils}/edit/maxLength.d.ts +0 -0
- package/dist/utils/edit/prepareInput.d.ts +7 -0
- package/dist/utils/edit/prepareInput.js +77 -0
- package/dist/{src/utils → utils}/focus/blur.d.ts +0 -0
- package/dist/{src/utils → utils}/focus/focus.d.ts +0 -0
- package/dist/utils/focus/focus.js +3 -0
- package/dist/{src/utils → utils}/focus/getActiveElement.d.ts +0 -0
- package/dist/utils/focus/getTabDestination.d.ts +1 -0
- package/dist/utils/focus/getTabDestination.js +71 -0
- package/dist/{src/utils → utils}/focus/isFocusable.d.ts +0 -0
- package/dist/utils/focus/selectAll.d.ts +5 -0
- package/dist/utils/focus/selectAll.js +51 -0
- package/dist/utils/focus/selection.d.ts +42 -0
- package/dist/utils/focus/selection.js +190 -0
- package/dist/{src/utils → utils}/focus/selector.d.ts +0 -0
- package/dist/{src/utils → utils}/index.d.ts +5 -5
- package/dist/utils/index.js +47 -47
- package/dist/{src/utils → utils}/keyDef/readNextDescriptor.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/eventWrapper.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/findClosest.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/hasFormSubmit.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/hasPointerEvents.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/isDescendantOrSelf.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/isDisabled.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/isElementType.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/isVisible.d.ts +0 -0
- package/dist/{src/utils → utils}/misc/wait.d.ts +0 -0
- package/dist/{src/utils → utils}/pointer/firePointerEvents.d.ts +13 -11
- package/dist/utils/pointer/firePointerEvents.js +62 -5
- package/dist/{src/utils → utils}/pointer/mouseButtons.d.ts +0 -0
- package/package.json +2 -2
- package/dist/document/applyNative.js +0 -28
- package/dist/src/document/applyNative.d.ts +0 -8
- package/dist/src/document/index.d.ts +0 -10
- package/dist/src/document/interceptor.d.ts +0 -5
- package/dist/src/document/selection.d.ts +0 -18
- package/dist/src/pointer/pointerMove.d.ts +0 -5
- package/dist/src/pointer/pointerPress.d.ts +0 -7
- package/dist/src/tab.d.ts +0 -6
- package/dist/src/utils/edit/calculateNewValue.d.ts +0 -7
- package/dist/src/utils/edit/cursorPosition.d.ts +0 -2
- package/dist/src/utils/edit/fireInputEvent.d.ts +0 -8
- package/dist/src/utils/edit/isContentEditable.d.ts +0 -3
- package/dist/src/utils/edit/selectionRange.d.ts +0 -5
- package/dist/src/utils/misc/isDocument.d.ts +0 -1
- package/dist/src/utils/pointer/fakeEvent.d.ts +0 -16
- package/dist/tests/_helpers/custom-element.d.ts +0 -8
- package/dist/tests/_helpers/utils.d.ts +0 -73
- package/dist/tests/_setup-env.d.ts +0 -1
- package/dist/tests/clear.d.ts +0 -1
- package/dist/tests/click/click.d.ts +0 -1
- package/dist/tests/click/dblclick.d.ts +0 -1
- package/dist/tests/document/index.d.ts +0 -1
- package/dist/tests/document/selectionRange.d.ts +0 -1
- package/dist/tests/hover/hover.d.ts +0 -1
- package/dist/tests/hover/unhover.d.ts +0 -1
- package/dist/tests/keyboard/getNextKeyDef.d.ts +0 -1
- package/dist/tests/keyboard/index.d.ts +0 -1
- package/dist/tests/keyboard/keyboardImplementation.d.ts +0 -1
- package/dist/tests/keyboard/plugin/arrow.d.ts +0 -1
- package/dist/tests/keyboard/plugin/character.d.ts +0 -1
- package/dist/tests/keyboard/plugin/control.d.ts +0 -1
- package/dist/tests/keyboard/plugin/functional.d.ts +0 -1
- package/dist/tests/keyboard/shared/fireInputEvent.d.ts +0 -1
- package/dist/tests/paste.d.ts +0 -1
- package/dist/tests/pointer/index.d.ts +0 -1
- package/dist/tests/react/keyboard.d.ts +0 -1
- package/dist/tests/react/type.d.ts +0 -1
- package/dist/tests/selectOptions/deselect.d.ts +0 -1
- package/dist/tests/selectOptions/select.d.ts +0 -1
- package/dist/tests/setup.d.ts +0 -10
- package/dist/tests/tab.d.ts +0 -1
- package/dist/tests/type/index.d.ts +0 -1
- package/dist/tests/type/modifiers.d.ts +0 -1
- package/dist/tests/upload.d.ts +0 -1
- package/dist/tests/utils/edit/calculateNewValue.d.ts +0 -1
- package/dist/tests/utils/edit/isContentEditable.d.ts +0 -1
- package/dist/tests/utils/focus/blur.d.ts +0 -1
- package/dist/tests/utils/focus/focus.d.ts +0 -1
- package/dist/tests/utils/misc/hasPointerEvents.d.ts +0 -1
- package/dist/tests/utils/misc/isDescendantOrSelf.d.ts +0 -1
- package/dist/tests/utils/misc/isElementType.d.ts +0 -1
- package/dist/tests/utils/misc/isVisible.d.ts +0 -1
- package/dist/utils/edit/cursorPosition.js +0 -35
- package/dist/utils/edit/fireInputEvent.js +0 -55
- package/dist/utils/edit/selectionRange.js +0 -64
- package/dist/utils/misc/dom-helpers.d.ts +0 -3
- package/dist/utils/misc/isDocument.js +0 -10
- package/dist/utils/pointer/fakeEvent.js +0 -82
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { keyboardState } from '../keyboard/types';
|
|
2
|
-
import {
|
|
2
|
+
import { PointerCoords, MouseButton } from '../utils';
|
|
3
3
|
/**
|
|
4
4
|
* @internal Do not create/alter this by yourself as this type might be subject to changes.
|
|
5
5
|
*/
|
|
@@ -26,8 +26,8 @@ export declare type pointerState = {
|
|
|
26
26
|
position: Record<string, {
|
|
27
27
|
pointerId: number;
|
|
28
28
|
pointerType: 'mouse' | 'pen' | 'touch';
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
} & Partial<PointerTarget> & {
|
|
30
|
+
selectionRange?: Range | SelectionInputRange;
|
|
31
31
|
}>;
|
|
32
32
|
/**
|
|
33
33
|
* Last applied pointer id
|
|
@@ -50,7 +50,21 @@ export interface pointerKey {
|
|
|
50
50
|
}
|
|
51
51
|
export interface PointerTarget {
|
|
52
52
|
target: Element;
|
|
53
|
-
coords
|
|
53
|
+
coords?: PointerCoords;
|
|
54
|
+
}
|
|
55
|
+
export interface SelectionTarget {
|
|
56
|
+
node?: Node;
|
|
57
|
+
/**
|
|
58
|
+
* If `node` is set, this is the DOM offset.
|
|
59
|
+
* Otherwise this is the `textContent`/`value` offset on the `target`.
|
|
60
|
+
*/
|
|
61
|
+
offset?: number;
|
|
62
|
+
}
|
|
63
|
+
/** Describes a selection inside `HTMLInputElement`/`HTMLTextareaElement` */
|
|
64
|
+
export interface SelectionInputRange {
|
|
65
|
+
node: HTMLInputElement | HTMLTextAreaElement;
|
|
66
|
+
start: number;
|
|
67
|
+
end: number;
|
|
54
68
|
}
|
|
55
69
|
export interface inputDeviceState {
|
|
56
70
|
pointerState: pointerState;
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { clear } from './clear';
|
|
2
|
-
import { click, clickOptions, dblClick } from './click';
|
|
2
|
+
import { click, clickOptions, dblClick, tripleClick } from './click';
|
|
3
3
|
import { hover, unhover } from './hover';
|
|
4
4
|
import { keyboard, keyboardOptions } from './keyboard';
|
|
5
5
|
import type { keyboardState } from './keyboard/types';
|
|
@@ -22,6 +22,7 @@ export declare const userEventApis: {
|
|
|
22
22
|
pointer: typeof pointer;
|
|
23
23
|
selectOptions: typeof selectOptions;
|
|
24
24
|
tab: typeof tab;
|
|
25
|
+
tripleClick: typeof tripleClick;
|
|
25
26
|
type: typeof type;
|
|
26
27
|
unhover: typeof unhover;
|
|
27
28
|
upload: typeof upload;
|
|
@@ -54,6 +55,7 @@ export declare function setup(options?: SetupOptions): {
|
|
|
54
55
|
pointer: typeof pointer;
|
|
55
56
|
selectOptions: typeof selectOptions;
|
|
56
57
|
tab: typeof tab;
|
|
58
|
+
tripleClick: typeof tripleClick;
|
|
57
59
|
type: typeof type;
|
|
58
60
|
unhover: typeof unhover;
|
|
59
61
|
upload: typeof upload;
|
|
@@ -72,12 +74,13 @@ export declare function setup(options?: SetupOptions): {
|
|
|
72
74
|
pointer: typeof pointer;
|
|
73
75
|
selectOptions: typeof selectOptions;
|
|
74
76
|
tab: typeof tab;
|
|
77
|
+
tripleClick: typeof tripleClick;
|
|
75
78
|
type: typeof type;
|
|
76
79
|
unhover: typeof unhover;
|
|
77
80
|
upload: typeof upload;
|
|
78
81
|
} & any;
|
|
79
82
|
};
|
|
80
|
-
declare function _setup({ applyAccept, autoModify, delay, document,
|
|
83
|
+
declare function _setup({ applyAccept, autoModify, delay, document, keyboardMap, pointerMap, skipAutoClose, skipClick, skipHover, skipPointerEventsCheck, }: SetupOptions, { keyboardState, pointerState, }: {
|
|
81
84
|
keyboardState: keyboardState;
|
|
82
85
|
pointerState: pointerState;
|
|
83
86
|
}): UserEventApis & {
|
package/dist/setup.js
CHANGED
|
@@ -39,6 +39,7 @@ const userEventApis = {
|
|
|
39
39
|
pointer: _pointer.pointer,
|
|
40
40
|
selectOptions: _selectOptions.selectOptions,
|
|
41
41
|
tab: _tab.tab,
|
|
42
|
+
tripleClick: _click.tripleClick,
|
|
42
43
|
type: _type.type,
|
|
43
44
|
unhover: _hover.unhover,
|
|
44
45
|
upload: _upload.upload
|
|
@@ -64,7 +65,6 @@ function _setup({
|
|
|
64
65
|
autoModify,
|
|
65
66
|
delay = 0,
|
|
66
67
|
document,
|
|
67
|
-
focusTrap,
|
|
68
68
|
keyboardMap,
|
|
69
69
|
pointerMap,
|
|
70
70
|
skipAutoClose,
|
|
@@ -91,9 +91,6 @@ function _setup({
|
|
|
91
91
|
const clickDefaults = {
|
|
92
92
|
skipHover
|
|
93
93
|
};
|
|
94
|
-
const tabDefaults = {
|
|
95
|
-
focusTrap
|
|
96
|
-
};
|
|
97
94
|
const typeDefaults = {
|
|
98
95
|
delay,
|
|
99
96
|
skipAutoClose,
|
|
@@ -177,11 +174,11 @@ function _setup({
|
|
|
177
174
|
});
|
|
178
175
|
},
|
|
179
176
|
tab: (...args) => {
|
|
180
|
-
args[0] = { ...tabDefaults,
|
|
181
|
-
...args[0]
|
|
182
|
-
};
|
|
183
177
|
return _tab.tab.call(userEvent, ...args);
|
|
184
178
|
},
|
|
179
|
+
tripleClick: (...args) => {
|
|
180
|
+
return _click.tripleClick.call(userEvent, ...args);
|
|
181
|
+
},
|
|
185
182
|
// type needs typecasting because of the overloading
|
|
186
183
|
type: (...args) => {
|
|
187
184
|
args[2] = { ...typeDefaults,
|
package/dist/tab.d.ts
ADDED
package/dist/tab.js
CHANGED
|
@@ -5,137 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.tab = tab;
|
|
7
7
|
|
|
8
|
-
var _dom = require("@testing-library/dom");
|
|
9
|
-
|
|
10
|
-
var _utils = require("./utils");
|
|
11
|
-
|
|
12
|
-
function getNextElement(currentIndex, shift, elements, focusTrap) {
|
|
13
|
-
if ((0, _utils.isDocument)(focusTrap) && (currentIndex === 0 && shift || currentIndex === elements.length - 1 && !shift)) {
|
|
14
|
-
return focusTrap.body;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const nextIndex = shift ? currentIndex - 1 : currentIndex + 1;
|
|
18
|
-
const defaultIndex = shift ? elements.length - 1 : 0;
|
|
19
|
-
return elements[nextIndex] || elements[defaultIndex];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
8
|
function tab({
|
|
23
|
-
shift
|
|
24
|
-
focusTrap
|
|
9
|
+
shift
|
|
25
10
|
} = {}) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const doc = (_focusTrap$ownerDocum = (_focusTrap = focusTrap) == null ? void 0 : _focusTrap.ownerDocument) != null ? _focusTrap$ownerDocum : document;
|
|
29
|
-
const previousElement = (0, _utils.getActiveElement)(doc);
|
|
30
|
-
|
|
31
|
-
if (!focusTrap) {
|
|
32
|
-
focusTrap = doc;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const focusableElements = focusTrap.querySelectorAll(_utils.FOCUSABLE_SELECTOR);
|
|
36
|
-
const enabledElements = Array.from(focusableElements).filter(el => el === previousElement || el.getAttribute('tabindex') !== '-1' && !(0, _utils.isDisabled)(el) && // Hidden elements are not tabable
|
|
37
|
-
(0, _utils.isVisible)(el));
|
|
38
|
-
if (enabledElements.length === 0) return;
|
|
39
|
-
const orderedElements = enabledElements.map((el, idx) => ({
|
|
40
|
-
el,
|
|
41
|
-
idx
|
|
42
|
-
})).sort((a, b) => {
|
|
43
|
-
// tabindex has no effect if the active element has tabindex="-1"
|
|
44
|
-
if (previousElement && previousElement.getAttribute('tabindex') === '-1') {
|
|
45
|
-
return a.idx - b.idx;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const tabIndexA = Number(a.el.getAttribute('tabindex'));
|
|
49
|
-
const tabIndexB = Number(b.el.getAttribute('tabindex'));
|
|
50
|
-
const diff = tabIndexA - tabIndexB;
|
|
51
|
-
return diff === 0 ? a.idx - b.idx : diff;
|
|
52
|
-
}).map(({
|
|
53
|
-
el
|
|
54
|
-
}) => el); // TODO: verify/remove type casts
|
|
55
|
-
|
|
56
|
-
const checkedRadio = {};
|
|
57
|
-
let prunedElements = [];
|
|
58
|
-
orderedElements.forEach(currentElement => {
|
|
59
|
-
// For radio groups keep only the active radio
|
|
60
|
-
// If there is no active radio, keep only the checked radio
|
|
61
|
-
// If there is no checked radio, treat like everything else
|
|
62
|
-
const el = currentElement;
|
|
63
|
-
|
|
64
|
-
if (el.type === 'radio' && el.name) {
|
|
65
|
-
// If the active element is part of the group, add only that
|
|
66
|
-
const prev = previousElement;
|
|
67
|
-
|
|
68
|
-
if (prev && prev.type === el.type && prev.name === el.name) {
|
|
69
|
-
if (el === prev) {
|
|
70
|
-
prunedElements.push(el);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return;
|
|
74
|
-
} // If we stumble upon a checked radio, remove the others
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (el.checked) {
|
|
78
|
-
prunedElements = prunedElements.filter(e => e.type !== el.type || e.name !== el.name);
|
|
79
|
-
prunedElements.push(el);
|
|
80
|
-
checkedRadio[el.name] = el;
|
|
81
|
-
return;
|
|
82
|
-
} // If we already found the checked one, skip
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (typeof checkedRadio[el.name] !== 'undefined') {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
prunedElements.push(el);
|
|
91
|
-
});
|
|
92
|
-
const index = prunedElements.findIndex(el => el === previousElement);
|
|
93
|
-
const nextElement = getNextElement(index, shift, prunedElements, focusTrap);
|
|
94
|
-
const shiftKeyInit = {
|
|
95
|
-
key: 'Shift',
|
|
96
|
-
keyCode: 16,
|
|
97
|
-
shiftKey: true
|
|
98
|
-
};
|
|
99
|
-
const tabKeyInit = {
|
|
100
|
-
key: 'Tab',
|
|
101
|
-
keyCode: 9,
|
|
102
|
-
shiftKey: shift
|
|
103
|
-
};
|
|
104
|
-
let continueToTab = true; // not sure how to make it so there's no previous element...
|
|
105
|
-
// istanbul ignore else
|
|
106
|
-
|
|
107
|
-
if (previousElement) {
|
|
108
|
-
// preventDefault on the shift key makes no difference
|
|
109
|
-
if (shift) _dom.fireEvent.keyDown(previousElement, { ...shiftKeyInit
|
|
110
|
-
});
|
|
111
|
-
continueToTab = _dom.fireEvent.keyDown(previousElement, { ...tabKeyInit
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const keyUpTarget = !continueToTab && previousElement ? previousElement : nextElement;
|
|
116
|
-
|
|
117
|
-
if (continueToTab) {
|
|
118
|
-
if (nextElement === doc.body) {
|
|
119
|
-
/* istanbul ignore else */
|
|
120
|
-
if (previousElement) {
|
|
121
|
-
(0, _utils.blur)(previousElement);
|
|
122
|
-
}
|
|
123
|
-
} else {
|
|
124
|
-
(0, _utils.focus)(nextElement);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
_dom.fireEvent.keyUp(keyUpTarget, { ...tabKeyInit
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
if (shift) {
|
|
132
|
-
_dom.fireEvent.keyUp(keyUpTarget, { ...shiftKeyInit,
|
|
133
|
-
shiftKey: false
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
/*
|
|
138
|
-
eslint
|
|
139
|
-
complexity: "off",
|
|
140
|
-
max-statements: "off",
|
|
141
|
-
*/
|
|
11
|
+
this.keyboard(shift === true ? '{Shift>}{Tab}{/Shift}' : shift === false ? '[/ShiftLeft][/ShiftRight]{Tab}' : '{Tab}');
|
|
12
|
+
}
|
|
File without changes
|
package/dist/type.js
CHANGED
|
@@ -47,26 +47,10 @@ async function typeImplementation(userEvent, element, text, {
|
|
|
47
47
|
// TODO: properly type guard
|
|
48
48
|
// we use this workaround for now to prevent changing behavior
|
|
49
49
|
if (element.disabled) return;
|
|
50
|
-
if (!skipClick) userEvent.click(element);
|
|
50
|
+
if (!skipClick) userEvent.click(element);
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// at the end of the current input value. So, if the selection start
|
|
55
|
-
// and end are both the default of 0, then we'll go ahead and change
|
|
56
|
-
// them to the length of the current value.
|
|
57
|
-
// the only time it would make sense to pass the initialSelectionStart or
|
|
58
|
-
// initialSelectionEnd is if you have an input with a value and want to
|
|
59
|
-
// explicitly start typing with the cursor at 0. Not super common.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const value = (0, _utils.getValue)(currentElement());
|
|
63
|
-
const {
|
|
64
|
-
selectionStart,
|
|
65
|
-
selectionEnd
|
|
66
|
-
} = (0, _utils.getSelectionRange)(element);
|
|
67
|
-
|
|
68
|
-
if (value != null && (selectionStart === null || selectionStart === 0) && (selectionEnd === null || selectionEnd === 0)) {
|
|
69
|
-
(0, _utils.setSelectionRange)(currentElement(), initialSelectionStart != null ? initialSelectionStart : value.length, initialSelectionEnd != null ? initialSelectionEnd : value.length);
|
|
52
|
+
if (initialSelectionStart !== undefined) {
|
|
53
|
+
(0, _utils.setSelectionRange)(element, initialSelectionStart, initialSelectionEnd != null ? initialSelectionEnd : initialSelectionStart);
|
|
70
54
|
}
|
|
71
55
|
|
|
72
56
|
const {
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EditableInputType } from './isEditable';
|
|
2
|
+
/**
|
|
3
|
+
* Calculate a new text value.
|
|
4
|
+
*/
|
|
5
|
+
export declare function calculateNewValue(inputData: string, node: (HTMLInputElement & {
|
|
6
|
+
type: EditableInputType;
|
|
7
|
+
}) | HTMLTextAreaElement, { startOffset, endOffset, }: {
|
|
8
|
+
startOffset: number;
|
|
9
|
+
endOffset: number;
|
|
10
|
+
}, inputType?: string): {
|
|
11
|
+
oldValue: string;
|
|
12
|
+
newValue: string;
|
|
13
|
+
newOffset: number;
|
|
14
|
+
};
|
|
@@ -5,44 +5,42 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.calculateNewValue = calculateNewValue;
|
|
7
7
|
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
var _getValue2 = require("./getValue");
|
|
8
|
+
var _document = require("../../document");
|
|
11
9
|
|
|
12
10
|
var _isValidDateValue = require("./isValidDateValue");
|
|
13
11
|
|
|
14
12
|
var _isValidInputTimeValue = require("./isValidInputTimeValue");
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const prologEnd = Math.max(0, selectionStart === selectionEnd && deleteContent === 'backward' ? selectionStart - 1 : selectionStart);
|
|
14
|
+
/**
|
|
15
|
+
* Calculate a new text value.
|
|
16
|
+
*/
|
|
17
|
+
function calculateNewValue(inputData, node, {
|
|
18
|
+
startOffset,
|
|
19
|
+
endOffset
|
|
20
|
+
}, inputType) {
|
|
21
|
+
const value = (0, _document.getUIValue)(node);
|
|
22
|
+
const prologEnd = Math.max(0, startOffset === endOffset && inputType === 'deleteContentBackward' ? startOffset - 1 : startOffset);
|
|
26
23
|
const prolog = value.substring(0, prologEnd);
|
|
27
|
-
const epilogStart = Math.min(value.length,
|
|
24
|
+
const epilogStart = Math.min(value.length, startOffset === endOffset && inputType === 'deleteContentForward' ? startOffset + 1 : endOffset);
|
|
28
25
|
const epilog = value.substring(epilogStart, value.length);
|
|
29
|
-
let newValue = `${prolog}${
|
|
30
|
-
const
|
|
26
|
+
let newValue = `${prolog}${inputData}${epilog}`;
|
|
27
|
+
const newOffset = prologEnd + inputData.length;
|
|
31
28
|
|
|
32
|
-
if (
|
|
29
|
+
if (node.type === 'date' && !(0, _isValidDateValue.isValidDateValue)(node, newValue)) {
|
|
33
30
|
newValue = value;
|
|
34
31
|
}
|
|
35
32
|
|
|
36
|
-
if (
|
|
37
|
-
if ((0, _isValidInputTimeValue.isValidInputTimeValue)(
|
|
38
|
-
newValue =
|
|
33
|
+
if (node.type === 'time' && !(0, _isValidInputTimeValue.isValidInputTimeValue)(node, newValue)) {
|
|
34
|
+
if ((0, _isValidInputTimeValue.isValidInputTimeValue)(node, inputData)) {
|
|
35
|
+
newValue = inputData;
|
|
39
36
|
} else {
|
|
40
37
|
newValue = value;
|
|
41
38
|
}
|
|
42
39
|
}
|
|
43
40
|
|
|
44
41
|
return {
|
|
42
|
+
oldValue: value,
|
|
45
43
|
newValue,
|
|
46
|
-
|
|
44
|
+
newOffset
|
|
47
45
|
};
|
|
48
46
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { fireEvent } from '@testing-library/dom';
|
|
2
|
+
/**
|
|
3
|
+
* Change the value of an element as if it was changed as a result of a user input.
|
|
4
|
+
*
|
|
5
|
+
* Fires the input event.
|
|
6
|
+
*/
|
|
7
|
+
export declare function editInputElement(element: HTMLInputElement | HTMLTextAreaElement, { newValue, newSelection, eventOverrides, }: {
|
|
8
|
+
newValue: string;
|
|
9
|
+
newSelection: {
|
|
10
|
+
node: Node;
|
|
11
|
+
offset: number;
|
|
12
|
+
};
|
|
13
|
+
eventOverrides: Partial<Parameters<typeof fireEvent>[1]> & {
|
|
14
|
+
[k: string]: unknown;
|
|
15
|
+
};
|
|
16
|
+
}): void;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.editInputElement = editInputElement;
|
|
7
|
+
|
|
8
|
+
var _dom = require("@testing-library/dom");
|
|
9
|
+
|
|
10
|
+
var _document = require("../../document");
|
|
11
|
+
|
|
12
|
+
var _selection = require("../focus/selection");
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Change the value of an element as if it was changed as a result of a user input.
|
|
16
|
+
*
|
|
17
|
+
* Fires the input event.
|
|
18
|
+
*/
|
|
19
|
+
function editInputElement(element, {
|
|
20
|
+
newValue,
|
|
21
|
+
newSelection,
|
|
22
|
+
eventOverrides
|
|
23
|
+
}) {
|
|
24
|
+
const oldValue = element.value; // apply the changes before firing the input event, so that input handlers can access the altered dom and selection
|
|
25
|
+
|
|
26
|
+
(0, _document.setUIValue)(element, newValue);
|
|
27
|
+
(0, _selection.setSelection)({
|
|
28
|
+
focusNode: newSelection.node,
|
|
29
|
+
anchorOffset: newSelection.offset,
|
|
30
|
+
focusOffset: newSelection.offset
|
|
31
|
+
}); // When the input event happens in the browser, React executes all event handlers
|
|
32
|
+
// and if they change state of a controlled value, nothing happens.
|
|
33
|
+
// But when we trigger the event handlers in test environment,
|
|
34
|
+
// the changes are rolled back by React before the state update is applied.
|
|
35
|
+
// Then the updated state is applied which results in a resetted cursor.
|
|
36
|
+
// There is probably a better way to work around if we figure out
|
|
37
|
+
// why the batched update is executed differently in our test environment.
|
|
38
|
+
|
|
39
|
+
(0, _document.startTrackValue)(element);
|
|
40
|
+
|
|
41
|
+
_dom.fireEvent.input(element, { ...eventOverrides
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const tracked = (0, _document.endTrackValue)(element);
|
|
45
|
+
|
|
46
|
+
if ((tracked == null ? void 0 : tracked.length) === 2 && tracked[0] === oldValue && tracked[1] === newValue) {
|
|
47
|
+
(0, _selection.setSelection)({
|
|
48
|
+
focusNode: newSelection.node,
|
|
49
|
+
anchorOffset: newSelection.offset,
|
|
50
|
+
focusOffset: newSelection.offset
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
File without changes
|
|
@@ -10,8 +10,6 @@ var _document = require("../../document");
|
|
|
10
10
|
var _isContentEditable = require("./isContentEditable");
|
|
11
11
|
|
|
12
12
|
function getValue(element) {
|
|
13
|
-
var _getUIValue;
|
|
14
|
-
|
|
15
13
|
// istanbul ignore if
|
|
16
14
|
if (!element) {
|
|
17
15
|
return null;
|
|
@@ -21,5 +19,5 @@ function getValue(element) {
|
|
|
21
19
|
return element.textContent;
|
|
22
20
|
}
|
|
23
21
|
|
|
24
|
-
return (
|
|
22
|
+
return (0, _document.getUIValue)(element);
|
|
25
23
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function isContentEditable(element: Element): element is HTMLElement & {
|
|
2
|
+
contenteditable: 'true';
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* If a node is a contenteditable or inside one, return that element.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getContentEditable(node: Node): Element | null;
|
|
@@ -3,9 +3,23 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.getContentEditable = getContentEditable;
|
|
6
7
|
exports.isContentEditable = isContentEditable;
|
|
7
8
|
|
|
8
9
|
//jsdom is not supporting isContentEditable
|
|
9
10
|
function isContentEditable(element) {
|
|
10
11
|
return element.hasAttribute('contenteditable') && (element.getAttribute('contenteditable') == 'true' || element.getAttribute('contenteditable') == '');
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* If a node is a contenteditable or inside one, return that element.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
function getContentEditable(node) {
|
|
19
|
+
const element = getElement(node);
|
|
20
|
+
return element && (element.closest('[contenteditable=""]') || element.closest('[contenteditable="true"]'));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getElement(node) {
|
|
24
|
+
return node.nodeType === 1 ? node : node.parentElement;
|
|
11
25
|
}
|
|
@@ -17,6 +17,7 @@ export declare enum editableInputTypes {
|
|
|
17
17
|
'url' = "url",
|
|
18
18
|
'week' = "week"
|
|
19
19
|
}
|
|
20
|
+
export declare type EditableInputType = keyof typeof editableInputTypes;
|
|
20
21
|
export declare function isEditableInput(element: Element): element is HTMLInputElement & {
|
|
21
22
|
readOnly: false;
|
|
22
23
|
type: editableInputTypes;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.prepareInput = prepareInput;
|
|
7
|
+
|
|
8
|
+
var _dom = require("@testing-library/dom");
|
|
9
|
+
|
|
10
|
+
var _utils = require("../../utils");
|
|
11
|
+
|
|
12
|
+
function prepareInput(data, element, inputType = 'insertText') {
|
|
13
|
+
const inputRange = (0, _utils.getInputRange)(element);
|
|
14
|
+
/* istanbul ignore if */
|
|
15
|
+
|
|
16
|
+
if (!inputRange) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if ('startContainer' in inputRange) {
|
|
21
|
+
return {
|
|
22
|
+
commit: () => {
|
|
23
|
+
const del = !inputRange.collapsed;
|
|
24
|
+
|
|
25
|
+
if (del) {
|
|
26
|
+
inputRange.deleteContents();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (data) {
|
|
30
|
+
if (inputRange.endContainer.nodeType === 3) {
|
|
31
|
+
const offset = inputRange.endOffset;
|
|
32
|
+
inputRange.endContainer.insertData(offset, data);
|
|
33
|
+
inputRange.setStart(inputRange.endContainer, offset + data.length);
|
|
34
|
+
inputRange.setEnd(inputRange.endContainer, offset + data.length);
|
|
35
|
+
} else {
|
|
36
|
+
const text = element.ownerDocument.createTextNode(data);
|
|
37
|
+
inputRange.insertNode(text);
|
|
38
|
+
inputRange.setStart(text, data.length);
|
|
39
|
+
inputRange.setEnd(text, data.length);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (del || data) {
|
|
44
|
+
_dom.fireEvent.input(element, {
|
|
45
|
+
inputType
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
} else {
|
|
51
|
+
return {
|
|
52
|
+
getNewValue: () => (0, _utils.calculateNewValue)(data, element, inputRange, inputType).newValue,
|
|
53
|
+
commit: () => {
|
|
54
|
+
const {
|
|
55
|
+
newValue,
|
|
56
|
+
newOffset,
|
|
57
|
+
oldValue
|
|
58
|
+
} = (0, _utils.calculateNewValue)(data, element, inputRange, inputType);
|
|
59
|
+
|
|
60
|
+
if (newValue === oldValue && newOffset === inputRange.startOffset && newOffset === inputRange.endOffset) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
(0, _utils.editInputElement)(element, {
|
|
65
|
+
newValue,
|
|
66
|
+
newSelection: {
|
|
67
|
+
node: element,
|
|
68
|
+
offset: newOffset
|
|
69
|
+
},
|
|
70
|
+
eventOverrides: {
|
|
71
|
+
inputType
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
File without changes
|
|
File without changes
|
|
@@ -11,9 +11,12 @@ var _getActiveElement = require("./getActiveElement");
|
|
|
11
11
|
|
|
12
12
|
var _isFocusable = require("./isFocusable");
|
|
13
13
|
|
|
14
|
+
var _selection = require("./selection");
|
|
15
|
+
|
|
14
16
|
function focus(element) {
|
|
15
17
|
if (!(0, _isFocusable.isFocusable)(element)) return;
|
|
16
18
|
const isAlreadyActive = (0, _getActiveElement.getActiveElement)(element.ownerDocument) === element;
|
|
17
19
|
if (isAlreadyActive) return;
|
|
18
20
|
(0, _eventWrapper.eventWrapper)(() => element.focus());
|
|
21
|
+
(0, _selection.updateSelectionOnFocus)(element);
|
|
19
22
|
}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getTabDestination(activeElement: Element, shift: boolean): HTMLElement;
|