@testing-library/user-event 12.1.10 → 12.2.0
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 +2 -1
- package/dist/keys/navigation-key.js +54 -0
- package/dist/type.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
[![MIT License][license-badge]][license]
|
|
24
24
|
|
|
25
25
|
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
26
|
-
[](#contributors-)
|
|
27
27
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
28
28
|
[![PRs Welcome][prs-badge]][prs]
|
|
29
29
|
[![Code of Conduct][coc-badge]][coc]
|
|
@@ -595,6 +595,7 @@ Thanks goes to these people ([emoji key][emojis]):
|
|
|
595
595
|
</tr>
|
|
596
596
|
<tr>
|
|
597
597
|
<td align="center"><a href="https://www.linkedin.com/in/luis-takahashi/"><img src="https://avatars0.githubusercontent.com/u/19766035?v=4" width="100px;" alt=""/><br /><sub><b>Luís Takahashi</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=luistak" title="Code">💻</a> <a href="https://github.com/testing-library/user-event/commits?author=luistak" title="Tests">⚠️</a></td>
|
|
598
|
+
<td align="center"><a href="https://github.com/jesujcastillom"><img src="https://avatars3.githubusercontent.com/u/7827281?v=4" width="100px;" alt=""/><br /><sub><b>Jesu Castillo</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=jesujcastillom" title="Code">💻</a> <a href="https://github.com/testing-library/user-event/commits?author=jesujcastillom" title="Tests">⚠️</a></td>
|
|
598
599
|
</tr>
|
|
599
600
|
</table>
|
|
600
601
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.navigationKey = navigationKey;
|
|
7
|
+
|
|
8
|
+
var _dom = require("@testing-library/dom");
|
|
9
|
+
|
|
10
|
+
var _utils = require("../utils");
|
|
11
|
+
|
|
12
|
+
const keys = {
|
|
13
|
+
ArrowLeft: {
|
|
14
|
+
keyCode: 37
|
|
15
|
+
},
|
|
16
|
+
ArrowRight: {
|
|
17
|
+
keyCode: 39
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function getSelectionRange(currentElement, key) {
|
|
22
|
+
const {
|
|
23
|
+
selectionStart,
|
|
24
|
+
selectionEnd
|
|
25
|
+
} = currentElement();
|
|
26
|
+
const cursorChange = Number(key in keys) * (key === 'ArrowLeft' ? -1 : 1);
|
|
27
|
+
return {
|
|
28
|
+
selectionStart: selectionStart + cursorChange,
|
|
29
|
+
selectionEnd: selectionEnd + cursorChange
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function navigationKey(key) {
|
|
34
|
+
const event = {
|
|
35
|
+
key,
|
|
36
|
+
keyCode: keys[key].keyCode,
|
|
37
|
+
which: keys[key].keyCode
|
|
38
|
+
};
|
|
39
|
+
return ({
|
|
40
|
+
currentElement,
|
|
41
|
+
eventOverrides
|
|
42
|
+
}) => {
|
|
43
|
+
_dom.fireEvent.keyDown(currentElement(), { ...event,
|
|
44
|
+
...eventOverrides
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const range = getSelectionRange(currentElement, key);
|
|
48
|
+
(0, _utils.setSelectionRangeIfNecessary)(currentElement(), range.selectionStart, range.selectionEnd);
|
|
49
|
+
|
|
50
|
+
_dom.fireEvent.keyUp(currentElement(), { ...event,
|
|
51
|
+
...eventOverrides
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
}
|
package/dist/type.js
CHANGED
|
@@ -11,6 +11,8 @@ var _utils = require("./utils");
|
|
|
11
11
|
|
|
12
12
|
var _click = require("./click");
|
|
13
13
|
|
|
14
|
+
var _navigationKey = require("./keys/navigation-key");
|
|
15
|
+
|
|
14
16
|
// TODO: wrap in asyncWrapper
|
|
15
17
|
const modifierCallbackMap = { ...createModifierCallbackEntries({
|
|
16
18
|
name: 'shift',
|
|
@@ -38,6 +40,8 @@ const modifierCallbackMap = { ...createModifierCallbackEntries({
|
|
|
38
40
|
})
|
|
39
41
|
};
|
|
40
42
|
const specialCharCallbackMap = {
|
|
43
|
+
'{arrowleft}': (0, _navigationKey.navigationKey)('ArrowLeft'),
|
|
44
|
+
'{arrowright}': (0, _navigationKey.navigationKey)('ArrowRight'),
|
|
41
45
|
'{enter}': handleEnter,
|
|
42
46
|
'{esc}': handleEsc,
|
|
43
47
|
'{del}': handleDel,
|