@testing-library/user-event 12.1.7 → 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 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
- [![All Contributors](https://img.shields.io/badge/all_contributors-61-orange.svg?style=flat-square)](#contributors-)
26
+ [![All Contributors](https://img.shields.io/badge/all_contributors-65-orange.svg?style=flat-square)](#contributors-)
27
27
  <!-- ALL-CONTRIBUTORS-BADGE:END -->
28
28
  [![PRs Welcome][prs-badge]][prs]
29
29
  [![Code of Conduct][coc-badge]][coc]
@@ -590,6 +590,12 @@ Thanks goes to these people ([emoji key][emojis]):
590
590
  <td align="center"><a href="https://github.com/mischnic"><img src="https://avatars1.githubusercontent.com/u/4586894?v=4" width="100px;" alt=""/><br /><sub><b>Niklas Mischkulnig</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=mischnic" title="Code">💻</a> <a href="https://github.com/testing-library/user-event/commits?author=mischnic" title="Tests">⚠️</a></td>
591
591
  <td align="center"><a href="http://pascalduez.me"><img src="https://avatars3.githubusercontent.com/u/335467?v=4" width="100px;" alt=""/><br /><sub><b>Pascal Duez</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=pascalduez" title="Code">💻</a></td>
592
592
  <td align="center"><a href="http://malachi.dev"><img src="https://avatars3.githubusercontent.com/u/10888943?v=4" width="100px;" alt=""/><br /><sub><b>Malachi Willey</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=malwilley" title="Code">💻</a> <a href="https://github.com/testing-library/user-event/commits?author=malwilley" title="Tests">⚠️</a></td>
593
+ <td align="center"><a href="https://clarkwinters.com"><img src="https://avatars2.githubusercontent.com/u/40615752?v=4" width="100px;" alt=""/><br /><sub><b>Clark Winters</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=cwinters8" title="Documentation">📖</a></td>
594
+ <td align="center"><a href="https://github.com/lazytype"><img src="https://avatars1.githubusercontent.com/u/840985?v=4" width="100px;" alt=""/><br /><sub><b>lazytype</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=lazytype" title="Code">💻</a> <a href="https://github.com/testing-library/user-event/commits?author=lazytype" title="Tests">⚠️</a></td>
595
+ </tr>
596
+ <tr>
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>
593
599
  </tr>
594
600
  </table>
595
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
+ }
@@ -11,18 +11,20 @@ var _click = require("./click");
11
11
 
12
12
  var _focus = require("./focus");
13
13
 
14
+ var _hover = require("./hover");
15
+
14
16
  function selectOptionsBase(newValue, select, values, init) {
15
17
  if (!newValue && !select.multiple) {
16
18
  throw (0, _dom.getConfig)().getElementError(`Unable to deselect an option in a non-multiple select. Use selectOptions to change the selection instead.`, select);
17
19
  }
18
20
 
19
21
  const valArray = Array.isArray(values) ? values : [values];
20
- const allOptions = Array.from(select.querySelectorAll('option'));
22
+ const allOptions = Array.from(select.querySelectorAll('option, [role="option"]'));
21
23
  const selectedOptions = valArray.map(val => {
22
24
  if (allOptions.includes(val)) {
23
25
  return val;
24
26
  } else {
25
- const matchingOption = allOptions.find(o => o.value === val);
27
+ const matchingOption = allOptions.find(o => o.value === val || o.innerHTML === val);
26
28
 
27
29
  if (matchingOption) {
28
30
  return matchingOption;
@@ -70,15 +72,22 @@ function selectOptionsBase(newValue, select, values, init) {
70
72
  }
71
73
 
72
74
  function selectOption(option) {
73
- option.selected = newValue;
74
- (0, _dom.fireEvent)(select, (0, _dom.createEvent)('input', select, {
75
- bubbles: true,
76
- cancelable: false,
77
- composed: true,
78
- ...init
79
- }));
80
-
81
- _dom.fireEvent.change(select, init);
75
+ if (option.getAttribute('role') === 'option') {
76
+ option == null ? void 0 : option.setAttribute == null ? void 0 : option.setAttribute('aria-selected', newValue);
77
+ (0, _hover.hover)(option, init);
78
+ (0, _click.click)(option, init);
79
+ (0, _hover.unhover)(option, init);
80
+ } else {
81
+ option.selected = newValue;
82
+ (0, _dom.fireEvent)(select, (0, _dom.createEvent)('input', select, {
83
+ bubbles: true,
84
+ cancelable: false,
85
+ composed: true,
86
+ ...init
87
+ }));
88
+
89
+ _dom.fireEvent.change(select, init);
90
+ }
82
91
  }
83
92
  }
84
93
 
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,
package/dist/utils.js CHANGED
@@ -223,7 +223,7 @@ function setSelectionRangeIfNecessary(element, newSelectionStart, newSelectionEn
223
223
  }
224
224
  }
225
225
 
226
- const FOCUSABLE_SELECTOR = ['input:not([disabled])', 'button:not([disabled])', 'select:not([disabled])', 'textarea:not([disabled])', '[contenteditable=""]', '[contenteditable="true"]', 'a[href]', '[tabindex]:not([disabled])'].join(', ');
226
+ const FOCUSABLE_SELECTOR = ['input:not([type=hidden]):not([disabled])', 'button:not([disabled])', 'select:not([disabled])', 'textarea:not([disabled])', '[contenteditable=""]', '[contenteditable="true"]', 'a[href]', '[tabindex]:not([disabled])'].join(', ');
227
227
  exports.FOCUSABLE_SELECTOR = FOCUSABLE_SELECTOR;
228
228
 
229
229
  function isFocusable(element) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testing-library/user-event",
3
- "version": "12.1.7",
3
+ "version": "12.2.0",
4
4
  "description": "Fire events the same way the user does",
5
5
  "main": "dist/index.js",
6
6
  "typings": "typings/index.d.ts",