@testing-library/user-event 14.6.3 → 14.6.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/cjs/event/behavior/keydown.js +4 -1
- package/dist/cjs/keyboard/index.js +1 -1
- package/dist/cjs/system/keyboard.js +3 -2
- package/dist/esm/event/behavior/keydown.js +4 -1
- package/dist/esm/keyboard/index.js +1 -1
- package/dist/esm/system/keyboard.js +3 -2
- package/dist/types/system/keyboard.d.ts +1 -1
- package/package.json +1 -1
|
@@ -6,6 +6,7 @@ var isElementType = require('../../utils/misc/isElementType.js');
|
|
|
6
6
|
require('../../utils/dataTransfer/Clipboard.js');
|
|
7
7
|
var isContentEditable = require('../../utils/edit/isContentEditable.js');
|
|
8
8
|
var isEditable = require('../../utils/edit/isEditable.js');
|
|
9
|
+
var getActiveElement = require('../../utils/focus/getActiveElement.js');
|
|
9
10
|
var getTabDestination = require('../../utils/focus/getTabDestination.js');
|
|
10
11
|
var selection = require('../../utils/focus/selection.js');
|
|
11
12
|
var focus = require('../focus.js');
|
|
@@ -110,7 +111,9 @@ const keydownBehavior = {
|
|
|
110
111
|
},
|
|
111
112
|
Tab: (event, target, instance)=>{
|
|
112
113
|
return ()=>{
|
|
113
|
-
const dest = getTabDestination.getTabDestination(target,
|
|
114
|
+
const dest = getTabDestination.getTabDestination(// get target here because target would be stale, it's the element that keydown happened on, but
|
|
115
|
+
// focus may have been moved to another element so that browser tab behaviour picks up from there
|
|
116
|
+
getActiveElement.getActiveElementOrBody(instance.config.document), instance.system.keyboard.modifiers.Shift);
|
|
114
117
|
focus.focusElement(dest);
|
|
115
118
|
if (selection.hasOwnSelection(dest)) {
|
|
116
119
|
UI.setUISelection(dest, {
|
|
@@ -19,7 +19,7 @@ async function keyboardAction(instance, { keyDef, releasePrevious, releaseSelf,
|
|
|
19
19
|
}
|
|
20
20
|
if (!releasePrevious) {
|
|
21
21
|
for(let i = 1; i <= repeat; i++){
|
|
22
|
-
await system.keyboard.keydown(instance, keyDef);
|
|
22
|
+
await system.keyboard.keydown(instance, keyDef, i > 1);
|
|
23
23
|
if (i < repeat) {
|
|
24
24
|
await wait.wait(instance.config);
|
|
25
25
|
}
|
|
@@ -50,7 +50,7 @@ class KeyboardHost {
|
|
|
50
50
|
getPressedKeys() {
|
|
51
51
|
return this.pressed.values().map((p)=>p.keyDef);
|
|
52
52
|
}
|
|
53
|
-
/** Press a key */ async keydown(instance, keyDef) {
|
|
53
|
+
/** Press a key */ async keydown(instance, keyDef, repeat = false) {
|
|
54
54
|
const key = String(keyDef.key);
|
|
55
55
|
const code = String(keyDef.code);
|
|
56
56
|
const target = getActiveElement.getActiveElementOrBody(instance.config.document);
|
|
@@ -61,7 +61,8 @@ class KeyboardHost {
|
|
|
61
61
|
}
|
|
62
62
|
const unprevented = instance.dispatchUIEvent(target, 'keydown', {
|
|
63
63
|
key,
|
|
64
|
-
code
|
|
64
|
+
code,
|
|
65
|
+
repeat
|
|
65
66
|
});
|
|
66
67
|
if (isModifierLock(key) && !this.modifiers[key]) {
|
|
67
68
|
this.modifiers[key] = true;
|
|
@@ -4,6 +4,7 @@ import { isElementType } from '../../utils/misc/isElementType.js';
|
|
|
4
4
|
import '../../utils/dataTransfer/Clipboard.js';
|
|
5
5
|
import { isContentEditable } from '../../utils/edit/isContentEditable.js';
|
|
6
6
|
import { isEditable } from '../../utils/edit/isEditable.js';
|
|
7
|
+
import { getActiveElementOrBody } from '../../utils/focus/getActiveElement.js';
|
|
7
8
|
import { getTabDestination } from '../../utils/focus/getTabDestination.js';
|
|
8
9
|
import { hasOwnSelection } from '../../utils/focus/selection.js';
|
|
9
10
|
import { focusElement } from '../focus.js';
|
|
@@ -108,7 +109,9 @@ const keydownBehavior = {
|
|
|
108
109
|
},
|
|
109
110
|
Tab: (event, target, instance)=>{
|
|
110
111
|
return ()=>{
|
|
111
|
-
const dest = getTabDestination(target,
|
|
112
|
+
const dest = getTabDestination(// get target here because target would be stale, it's the element that keydown happened on, but
|
|
113
|
+
// focus may have been moved to another element so that browser tab behaviour picks up from there
|
|
114
|
+
getActiveElementOrBody(instance.config.document), instance.system.keyboard.modifiers.Shift);
|
|
112
115
|
focusElement(dest);
|
|
113
116
|
if (hasOwnSelection(dest)) {
|
|
114
117
|
setUISelection(dest, {
|
|
@@ -17,7 +17,7 @@ async function keyboardAction(instance, { keyDef, releasePrevious, releaseSelf,
|
|
|
17
17
|
}
|
|
18
18
|
if (!releasePrevious) {
|
|
19
19
|
for(let i = 1; i <= repeat; i++){
|
|
20
|
-
await system.keyboard.keydown(instance, keyDef);
|
|
20
|
+
await system.keyboard.keydown(instance, keyDef, i > 1);
|
|
21
21
|
if (i < repeat) {
|
|
22
22
|
await wait(instance.config);
|
|
23
23
|
}
|
|
@@ -48,7 +48,7 @@ class KeyboardHost {
|
|
|
48
48
|
getPressedKeys() {
|
|
49
49
|
return this.pressed.values().map((p)=>p.keyDef);
|
|
50
50
|
}
|
|
51
|
-
/** Press a key */ async keydown(instance, keyDef) {
|
|
51
|
+
/** Press a key */ async keydown(instance, keyDef, repeat = false) {
|
|
52
52
|
const key = String(keyDef.key);
|
|
53
53
|
const code = String(keyDef.code);
|
|
54
54
|
const target = getActiveElementOrBody(instance.config.document);
|
|
@@ -59,7 +59,8 @@ class KeyboardHost {
|
|
|
59
59
|
}
|
|
60
60
|
const unprevented = instance.dispatchUIEvent(target, 'keydown', {
|
|
61
61
|
key,
|
|
62
|
-
code
|
|
62
|
+
code,
|
|
63
|
+
repeat
|
|
63
64
|
});
|
|
64
65
|
if (isModifierLock(key) && !this.modifiers[key]) {
|
|
65
66
|
this.modifiers[key] = true;
|
|
@@ -42,7 +42,7 @@ export declare class KeyboardHost {
|
|
|
42
42
|
isKeyPressed(keyDef: keyboardKey): boolean;
|
|
43
43
|
getPressedKeys(): keyboardKey[];
|
|
44
44
|
/** Press a key */
|
|
45
|
-
keydown(instance: Instance, keyDef: keyboardKey): Promise<void>;
|
|
45
|
+
keydown(instance: Instance, keyDef: keyboardKey, repeat?: boolean): Promise<void>;
|
|
46
46
|
/** Release a key */
|
|
47
47
|
keyup(instance: Instance, keyDef: keyboardKey): Promise<void>;
|
|
48
48
|
private setKeydownTarget;
|