@testing-library/user-event 14.0.0-alpha.4 → 14.0.0-alpha.5
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/document/selection.js +22 -12
- package/dist/keyboard/keyboardImplementation.js +3 -1
- package/dist/keyboard/plugins/functional.js +1 -1
- package/dist/setup.d.ts +1 -1
- package/dist/setup.js +0 -7
- package/dist/tab.d.ts +1 -2
- package/dist/tab.js +2 -56
- package/dist/utils/focus/getTabDestination.d.ts +1 -1
- package/dist/utils/focus/getTabDestination.js +4 -5
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -13
- package/package.json +1 -1
- package/dist/utils/misc/isDocument.d.ts +0 -1
- package/dist/utils/misc/isDocument.js +0 -10
|
@@ -12,19 +12,29 @@ var _interceptor = require("./interceptor");
|
|
|
12
12
|
|
|
13
13
|
const UISelection = Symbol('Displayed selection in UI');
|
|
14
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
15
|
function prepareSelectionInterceptor(element) {
|
|
27
|
-
(0, _interceptor.prepareInterceptor)(element, 'setSelectionRange',
|
|
16
|
+
(0, _interceptor.prepareInterceptor)(element, 'setSelectionRange', function interceptorImpl(start, end, direction = 'none') {
|
|
17
|
+
const isUI = start && typeof start === 'object' && start[UISelection];
|
|
18
|
+
this[UISelection] = isUI ? {
|
|
19
|
+
start: start.valueOf(),
|
|
20
|
+
end: Number(end)
|
|
21
|
+
} : undefined;
|
|
22
|
+
return {
|
|
23
|
+
realArgs: [Number(start), end, direction]
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
(0, _interceptor.prepareInterceptor)(element, 'selectionStart', function interceptorImpl(v) {
|
|
27
|
+
this[UISelection] = undefined;
|
|
28
|
+
return {
|
|
29
|
+
realArgs: v
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
(0, _interceptor.prepareInterceptor)(element, 'selectionEnd', function interceptorImpl(v) {
|
|
33
|
+
this[UISelection] = undefined;
|
|
34
|
+
return {
|
|
35
|
+
realArgs: v
|
|
36
|
+
};
|
|
37
|
+
});
|
|
28
38
|
}
|
|
29
39
|
|
|
30
40
|
function setUISelection(element, start, end) {
|
|
@@ -129,7 +129,9 @@ function keydown(keyDef, getCurrentElement, options, state) {
|
|
|
129
129
|
function keypress(keyDef, getCurrentElement, options, state) {
|
|
130
130
|
const element = getCurrentElement();
|
|
131
131
|
|
|
132
|
-
const unpreventedDefault = _dom.fireEvent.keyPress(element, (0, _getEventProps.getKeyEventProps)(keyDef, state)
|
|
132
|
+
const unpreventedDefault = _dom.fireEvent.keyPress(element, { ...(0, _getEventProps.getKeyEventProps)(keyDef, state),
|
|
133
|
+
charCode: keyDef.key === 'Enter' ? 13 : String(keyDef.key).charCodeAt(0)
|
|
134
|
+
});
|
|
133
135
|
|
|
134
136
|
if (unpreventedDefault) {
|
|
135
137
|
applyPlugins(plugins.keypressBehavior, keyDef, getCurrentElement(), options, state);
|
|
@@ -70,7 +70,7 @@ const keydownBehavior = [{
|
|
|
70
70
|
}, {
|
|
71
71
|
matches: keyDef => keyDef.key === 'Tab',
|
|
72
72
|
handle: (keyDef, element, options, state) => {
|
|
73
|
-
const dest = (0, _utils.getTabDestination)(element, state.modifiers.shift
|
|
73
|
+
const dest = (0, _utils.getTabDestination)(element, state.modifiers.shift);
|
|
74
74
|
|
|
75
75
|
if (dest === element.ownerDocument.body) {
|
|
76
76
|
(0, _utils.blur)(element);
|
package/dist/setup.d.ts
CHANGED
|
@@ -77,7 +77,7 @@ export declare function setup(options?: SetupOptions): {
|
|
|
77
77
|
upload: typeof upload;
|
|
78
78
|
} & any;
|
|
79
79
|
};
|
|
80
|
-
declare function _setup({ applyAccept, autoModify, delay, document,
|
|
80
|
+
declare function _setup({ applyAccept, autoModify, delay, document, keyboardMap, pointerMap, skipAutoClose, skipClick, skipHover, skipPointerEventsCheck, }: SetupOptions, { keyboardState, pointerState, }: {
|
|
81
81
|
keyboardState: keyboardState;
|
|
82
82
|
pointerState: pointerState;
|
|
83
83
|
}): UserEventApis & {
|
package/dist/setup.js
CHANGED
|
@@ -64,7 +64,6 @@ function _setup({
|
|
|
64
64
|
autoModify,
|
|
65
65
|
delay = 0,
|
|
66
66
|
document,
|
|
67
|
-
focusTrap,
|
|
68
67
|
keyboardMap,
|
|
69
68
|
pointerMap,
|
|
70
69
|
skipAutoClose,
|
|
@@ -91,9 +90,6 @@ function _setup({
|
|
|
91
90
|
const clickDefaults = {
|
|
92
91
|
skipHover
|
|
93
92
|
};
|
|
94
|
-
const tabDefaults = {
|
|
95
|
-
focusTrap
|
|
96
|
-
};
|
|
97
93
|
const typeDefaults = {
|
|
98
94
|
delay,
|
|
99
95
|
skipAutoClose,
|
|
@@ -177,9 +173,6 @@ function _setup({
|
|
|
177
173
|
});
|
|
178
174
|
},
|
|
179
175
|
tab: (...args) => {
|
|
180
|
-
args[0] = { ...tabDefaults,
|
|
181
|
-
...args[0]
|
|
182
|
-
};
|
|
183
176
|
return _tab.tab.call(userEvent, ...args);
|
|
184
177
|
},
|
|
185
178
|
// type needs typecasting because of the overloading
|
package/dist/tab.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { UserEvent } from './setup';
|
|
2
2
|
export interface tabOptions {
|
|
3
3
|
shift?: boolean;
|
|
4
|
-
focusTrap?: Document | Element;
|
|
5
4
|
}
|
|
6
|
-
export declare function tab(this: UserEvent, { shift
|
|
5
|
+
export declare function tab(this: UserEvent, { shift }?: tabOptions): void;
|
package/dist/tab.js
CHANGED
|
@@ -5,62 +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
8
|
function tab({
|
|
13
|
-
shift
|
|
14
|
-
focusTrap
|
|
9
|
+
shift
|
|
15
10
|
} = {}) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const doc = (_focusTrap$ownerDocum = (_focusTrap = focusTrap) == null ? void 0 : _focusTrap.ownerDocument) != null ? _focusTrap$ownerDocum : document;
|
|
19
|
-
const previousElement = (0, _utils.getActiveElement)(doc); // Never the case in our test environment
|
|
20
|
-
// Only happens if the activeElement is inside a shadowRoot that is not part of `doc`.
|
|
21
|
-
|
|
22
|
-
/* istanbul ignore next */
|
|
23
|
-
|
|
24
|
-
if (!previousElement) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (!focusTrap) {
|
|
29
|
-
focusTrap = doc;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const nextElement = (0, _utils.getTabDestination)(previousElement, shift, focusTrap);
|
|
33
|
-
const shiftKeyInit = {
|
|
34
|
-
key: 'Shift',
|
|
35
|
-
keyCode: 16,
|
|
36
|
-
shiftKey: true
|
|
37
|
-
};
|
|
38
|
-
const tabKeyInit = {
|
|
39
|
-
key: 'Tab',
|
|
40
|
-
keyCode: 9,
|
|
41
|
-
shiftKey: shift
|
|
42
|
-
};
|
|
43
|
-
let continueToTab = true;
|
|
44
|
-
if (shift) _dom.fireEvent.keyDown(previousElement, { ...shiftKeyInit
|
|
45
|
-
});
|
|
46
|
-
continueToTab = _dom.fireEvent.keyDown(previousElement, { ...tabKeyInit
|
|
47
|
-
});
|
|
48
|
-
const keyUpTarget = continueToTab ? nextElement : previousElement;
|
|
49
|
-
|
|
50
|
-
if (continueToTab) {
|
|
51
|
-
if (nextElement === doc.body) {
|
|
52
|
-
(0, _utils.blur)(previousElement);
|
|
53
|
-
} else {
|
|
54
|
-
(0, _utils.focus)(nextElement);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
_dom.fireEvent.keyUp(keyUpTarget, { ...tabKeyInit
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
if (shift) {
|
|
62
|
-
_dom.fireEvent.keyUp(keyUpTarget, { ...shiftKeyInit,
|
|
63
|
-
shiftKey: false
|
|
64
|
-
});
|
|
65
|
-
}
|
|
11
|
+
this.keyboard(shift === true ? '{Shift>}{Tab}{/Shift}' : shift === false ? '[/ShiftLeft][/ShiftRight]{Tab}' : '{Tab}');
|
|
66
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getTabDestination(activeElement: Element, shift: boolean
|
|
1
|
+
export declare function getTabDestination(activeElement: Element, shift: boolean): HTMLElement;
|
|
@@ -7,16 +7,15 @@ exports.getTabDestination = getTabDestination;
|
|
|
7
7
|
|
|
8
8
|
var _isDisabled = require("../misc/isDisabled");
|
|
9
9
|
|
|
10
|
-
var _isDocument = require("../misc/isDocument");
|
|
11
|
-
|
|
12
10
|
var _isElementType = require("../misc/isElementType");
|
|
13
11
|
|
|
14
12
|
var _isVisible = require("../misc/isVisible");
|
|
15
13
|
|
|
16
14
|
var _selector = require("./selector");
|
|
17
15
|
|
|
18
|
-
function getTabDestination(activeElement, shift
|
|
19
|
-
const
|
|
16
|
+
function getTabDestination(activeElement, shift) {
|
|
17
|
+
const document = activeElement.ownerDocument;
|
|
18
|
+
const focusableElements = document.querySelectorAll(_selector.FOCUSABLE_SELECTOR);
|
|
20
19
|
const enabledElements = Array.from(focusableElements).filter(el => el === activeElement || el.getAttribute('tabindex') !== '-1' && !(0, _isDisabled.isDisabled)(el) && // Hidden elements are not tabable
|
|
21
20
|
(0, _isVisible.isVisible)(el));
|
|
22
21
|
|
|
@@ -26,7 +25,7 @@ function getTabDestination(activeElement, shift, focusTrap) {
|
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
const checkedRadio = {};
|
|
29
|
-
let prunedElements =
|
|
28
|
+
let prunedElements = [document.body];
|
|
30
29
|
const activeRadioGroup = (0, _isElementType.isElementType)(activeElement, 'input', {
|
|
31
30
|
type: 'radio'
|
|
32
31
|
}) ? activeElement.name : undefined;
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -23,7 +23,6 @@ export * from './misc/isDescendantOrSelf';
|
|
|
23
23
|
export * from './misc/isElementType';
|
|
24
24
|
export * from './misc/isVisible';
|
|
25
25
|
export * from './misc/isDisabled';
|
|
26
|
-
export * from './misc/isDocument';
|
|
27
26
|
export * from './misc/wait';
|
|
28
27
|
export * from './misc/hasPointerEvents';
|
|
29
28
|
export * from './misc/hasFormSubmit';
|
package/dist/utils/index.js
CHANGED
|
@@ -329,19 +329,6 @@ Object.keys(_isDisabled).forEach(function (key) {
|
|
|
329
329
|
});
|
|
330
330
|
});
|
|
331
331
|
|
|
332
|
-
var _isDocument = require("./misc/isDocument");
|
|
333
|
-
|
|
334
|
-
Object.keys(_isDocument).forEach(function (key) {
|
|
335
|
-
if (key === "default" || key === "__esModule") return;
|
|
336
|
-
if (key in exports && exports[key] === _isDocument[key]) return;
|
|
337
|
-
Object.defineProperty(exports, key, {
|
|
338
|
-
enumerable: true,
|
|
339
|
-
get: function () {
|
|
340
|
-
return _isDocument[key];
|
|
341
|
-
}
|
|
342
|
-
});
|
|
343
|
-
});
|
|
344
|
-
|
|
345
332
|
var _wait = require("./misc/wait");
|
|
346
333
|
|
|
347
334
|
Object.keys(_wait).forEach(function (key) {
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isDocument(el: Document | Element): el is Document;
|