@testing-library/user-event 12.1.2 → 12.1.6

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-57-orange.svg?style=flat-square)](#contributors-)
26
+ [![All Contributors](https://img.shields.io/badge/all_contributors-60-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]
@@ -586,6 +586,9 @@ Thanks goes to these people ([emoji key][emojis]):
586
586
  </tr>
587
587
  <tr>
588
588
  <td align="center"><a href="https://github.com/ph-fritsche"><img src="https://avatars3.githubusercontent.com/u/39068198?v=4" width="100px;" alt=""/><br /><sub><b>ph-fritsche</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=ph-fritsche" title="Code">💻</a> <a href="https://github.com/testing-library/user-event/commits?author=ph-fritsche" title="Tests">⚠️</a></td>
589
+ <td align="center"><a href="https://github.com/reywright"><img src="https://avatars3.githubusercontent.com/u/708820?v=4" width="100px;" alt=""/><br /><sub><b>Rey Wright</b></sub></a><br /><a href="https://github.com/testing-library/user-event/issues?q=author%3Areywright" title="Bug reports">🐛</a> <a href="https://github.com/testing-library/user-event/commits?author=reywright" title="Code">💻</a></td>
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
+ <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>
589
592
  </tr>
590
593
  </table>
591
594
 
package/dist/hover.js CHANGED
@@ -10,17 +10,34 @@ var _dom = require("@testing-library/dom");
10
10
 
11
11
  var _utils = require("./utils");
12
12
 
13
+ // includes `element`
14
+ function getParentElements(element) {
15
+ const parentElements = [element];
16
+ let currentElement = element;
17
+
18
+ while ((currentElement = currentElement.parentElement) != null) {
19
+ parentElements.push(currentElement);
20
+ }
21
+
22
+ return parentElements;
23
+ }
24
+
13
25
  function hover(element, init) {
14
26
  if ((0, _utils.isLabelWithInternallyDisabledControl)(element)) return;
27
+ const parentElements = getParentElements(element).reverse();
15
28
 
16
29
  _dom.fireEvent.pointerOver(element, init);
17
30
 
18
- _dom.fireEvent.pointerEnter(element, init);
31
+ for (const el of parentElements) {
32
+ _dom.fireEvent.pointerEnter(el, init);
33
+ }
19
34
 
20
35
  if (!element.disabled) {
21
36
  _dom.fireEvent.mouseOver(element, (0, _utils.getMouseEventOptions)('mouseover', init));
22
37
 
23
- _dom.fireEvent.mouseEnter(element, (0, _utils.getMouseEventOptions)('mouseenter', init));
38
+ for (const el of parentElements) {
39
+ _dom.fireEvent.mouseEnter(el, (0, _utils.getMouseEventOptions)('mouseenter', init));
40
+ }
24
41
  }
25
42
 
26
43
  _dom.fireEvent.pointerMove(element, init);
@@ -32,6 +49,7 @@ function hover(element, init) {
32
49
 
33
50
  function unhover(element, init) {
34
51
  if ((0, _utils.isLabelWithInternallyDisabledControl)(element)) return;
52
+ const parentElements = getParentElements(element);
35
53
 
36
54
  _dom.fireEvent.pointerMove(element, init);
37
55
 
@@ -41,11 +59,15 @@ function unhover(element, init) {
41
59
 
42
60
  _dom.fireEvent.pointerOut(element, init);
43
61
 
44
- _dom.fireEvent.pointerLeave(element, init);
62
+ for (const el of parentElements) {
63
+ _dom.fireEvent.pointerLeave(el, init);
64
+ }
45
65
 
46
66
  if (!element.disabled) {
47
67
  _dom.fireEvent.mouseOut(element, (0, _utils.getMouseEventOptions)('mouseout', init));
48
68
 
49
- _dom.fireEvent.mouseLeave(element, (0, _utils.getMouseEventOptions)('mouseleave', init));
69
+ for (const el of parentElements) {
70
+ _dom.fireEvent.mouseLeave(el, (0, _utils.getMouseEventOptions)('mouseleave', init));
71
+ }
50
72
  }
51
73
  }
package/dist/tab.js CHANGED
@@ -38,12 +38,17 @@ function tab({
38
38
  }
39
39
 
40
40
  const focusableElements = focusTrap.querySelectorAll(_utils.FOCUSABLE_SELECTOR);
41
- const enabledElements = [...focusableElements].filter(el => el.getAttribute('tabindex') !== '-1' && !el.disabled);
41
+ const enabledElements = [...focusableElements].filter(el => el === previousElement || el.getAttribute('tabindex') !== '-1' && !el.disabled);
42
42
  if (enabledElements.length === 0) return;
43
43
  const orderedElements = enabledElements.map((el, idx) => ({
44
44
  el,
45
45
  idx
46
46
  })).sort((a, b) => {
47
+ // tabindex has no effect if the active element has tabindex="-1"
48
+ if (previousElement && previousElement.getAttribute('tabindex') === '-1') {
49
+ return a.idx - b.idx;
50
+ }
51
+
47
52
  const tabIndexA = a.el.getAttribute('tabindex');
48
53
  const tabIndexB = b.el.getAttribute('tabindex');
49
54
  const diff = tabIndexA - tabIndexB;
@@ -51,29 +56,39 @@ function tab({
51
56
  }).map(({
52
57
  el
53
58
  }) => el);
54
- if (shift) orderedElements.reverse(); // keep only the checked or first element in each radio group
59
+ const checkedRadio = {};
60
+ let prunedElements = [];
61
+ orderedElements.forEach(el => {
62
+ // For radio groups keep only the active radio
63
+ // If there is no active radio, keep only the checked radio
64
+ // If there is no checked radio, treat like everything else
65
+ if (el.type === 'radio' && el.name) {
66
+ // If the active element is part of the group, add only that
67
+ if (previousElement && previousElement.type === el.type && previousElement.name === el.name) {
68
+ if (el === previousElement) {
69
+ prunedElements.push(el);
70
+ }
55
71
 
56
- const prunedElements = [];
72
+ return;
73
+ } // If we stumble upon a checked radio, remove the others
57
74
 
58
- for (const el of orderedElements) {
59
- if (el.type === 'radio' && el.name) {
60
- const replacedIndex = prunedElements.findIndex(({
61
- name
62
- }) => name === el.name);
63
75
 
64
- if (replacedIndex === -1) {
65
- prunedElements.push(el);
66
- } else if (el.checked) {
67
- prunedElements.splice(replacedIndex, 1);
76
+ if (el.checked) {
77
+ prunedElements = prunedElements.filter(e => e.type !== el.type || e.name !== el.name);
68
78
  prunedElements.push(el);
79
+ checkedRadio[el.name] = el;
80
+ return;
81
+ } // If we already found the checked one, skip
82
+
83
+
84
+ if (checkedRadio[el.name]) {
85
+ return;
69
86
  }
70
- } else {
71
- prunedElements.push(el);
72
87
  }
73
- }
74
88
 
75
- if (shift) prunedElements.reverse();
76
- const index = prunedElements.findIndex(el => el === el.ownerDocument.activeElement);
89
+ prunedElements.push(el);
90
+ });
91
+ const index = prunedElements.findIndex(el => el === previousElement);
77
92
  const nextElement = getNextElement(index, shift, prunedElements, focusTrap);
78
93
  const shiftKeyInit = {
79
94
  key: 'Shift',
package/dist/utils.js CHANGED
@@ -118,7 +118,7 @@ function supportsMaxLength(element) {
118
118
 
119
119
  function getSelectionRange(element) {
120
120
  if (isContentEditable(element)) {
121
- const range = document.getSelection().getRangeAt(0);
121
+ const range = element.ownerDocument.getSelection().getRangeAt(0);
122
122
  return {
123
123
  selectionStart: range.startOffset,
124
124
  selectionEnd: range.endOffset
@@ -211,12 +211,12 @@ function setSelectionRangeIfNecessary(element, newSelectionStart, newSelectionEn
211
211
 
212
212
  if (selectionStart !== newSelectionStart || selectionEnd !== newSelectionStart) {
213
213
  if (isContentEditable(element)) {
214
- const range = document.createRange();
214
+ const range = element.ownerDocument.createRange();
215
215
  range.selectNodeContents(element);
216
216
  range.setStart(element.firstChild, newSelectionStart);
217
217
  range.setEnd(element.firstChild, newSelectionEnd);
218
- document.getSelection().removeAllRanges();
219
- document.getSelection().addRange(range);
218
+ element.ownerDocument.getSelection().removeAllRanges();
219
+ element.ownerDocument.getSelection().addRange(range);
220
220
  } else {
221
221
  element.setSelectionRange(newSelectionStart, newSelectionEnd);
222
222
  }
@@ -233,7 +233,7 @@ function isFocusable(element) {
233
233
  const CLICKABLE_INPUT_TYPES = ['button', 'color', 'file', 'image', 'reset', 'submit'];
234
234
 
235
235
  function isClickable(element) {
236
- return element.tagName === 'BUTTON' || element instanceof HTMLInputElement && CLICKABLE_INPUT_TYPES.includes(element.type);
236
+ return element.tagName === 'BUTTON' || element instanceof element.ownerDocument.defaultView.HTMLInputElement && CLICKABLE_INPUT_TYPES.includes(element.type);
237
237
  }
238
238
 
239
239
  function eventWrapper(cb) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testing-library/user-event",
3
- "version": "12.1.2",
3
+ "version": "12.1.6",
4
4
  "description": "Fire events the same way the user does",
5
5
  "main": "dist/index.js",
6
6
  "typings": "typings/index.d.ts",
@@ -61,7 +61,8 @@ declare const userEvent: {
61
61
  tab: (userOpts?: ITabUserOptions) => void
62
62
  paste: (
63
63
  element: TargetElement,
64
- init?: {},
64
+ text: string,
65
+ init?: MouseEventInit,
65
66
  pasteOptions?: {
66
67
  initialSelectionStart?: number
67
68
  initialSelectionEnd?: number