@testing-library/user-event 12.1.6 → 12.1.10

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-60-orange.svg?style=flat-square)](#contributors-)
26
+ [![All Contributors](https://img.shields.io/badge/all_contributors-64-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]
@@ -589,6 +589,12 @@ Thanks goes to these people ([emoji key][emojis]):
589
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
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
+ <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>
592
598
  </tr>
593
599
  </table>
594
600
 
@@ -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
@@ -526,42 +526,44 @@ function handleEnter({
526
526
  });
527
527
 
528
528
  if (keyDownDefaultNotPrevented) {
529
- _dom.fireEvent.keyPress(currentElement(), {
529
+ const keyPressDefaultNotPrevented = _dom.fireEvent.keyPress(currentElement(), {
530
530
  key,
531
531
  keyCode,
532
532
  charCode: keyCode,
533
533
  ...eventOverrides
534
534
  });
535
535
 
536
- if ((0, _utils.isClickable)(currentElement())) {
537
- _dom.fireEvent.click(currentElement(), { ...eventOverrides
538
- });
539
- }
540
- }
536
+ if (keyPressDefaultNotPrevented) {
537
+ if ((0, _utils.isClickable)(currentElement())) {
538
+ _dom.fireEvent.click(currentElement(), { ...eventOverrides
539
+ });
540
+ }
541
541
 
542
- if (currentElement().tagName === 'TEXTAREA') {
543
- const {
544
- newValue,
545
- newSelectionStart
546
- } = (0, _utils.calculateNewValue)('\n', currentElement());
542
+ if (currentElement().tagName === 'TEXTAREA') {
543
+ const {
544
+ newValue,
545
+ newSelectionStart
546
+ } = (0, _utils.calculateNewValue)('\n', currentElement());
547
547
 
548
- _dom.fireEvent.input(currentElement(), {
549
- target: {
550
- value: newValue
551
- },
552
- inputType: 'insertLineBreak',
553
- ...eventOverrides
554
- });
548
+ _dom.fireEvent.input(currentElement(), {
549
+ target: {
550
+ value: newValue
551
+ },
552
+ inputType: 'insertLineBreak',
553
+ ...eventOverrides
554
+ });
555
555
 
556
- setSelectionRange({
557
- currentElement,
558
- newValue,
559
- newSelectionStart
560
- });
561
- }
556
+ setSelectionRange({
557
+ currentElement,
558
+ newValue,
559
+ newSelectionStart
560
+ });
561
+ }
562
562
 
563
- if (currentElement().tagName === 'INPUT' && currentElement().form && (currentElement().form.querySelectorAll('input').length === 1 || currentElement().form.querySelector('input[type="submit"]') || currentElement().form.querySelector('button[type="submit"]'))) {
564
- _dom.fireEvent.submit(currentElement().form);
563
+ if (currentElement().tagName === 'INPUT' && currentElement().form && (currentElement().form.querySelectorAll('input').length === 1 || currentElement().form.querySelector('input[type="submit"]') || currentElement().form.querySelector('button[type="submit"]'))) {
564
+ _dom.fireEvent.submit(currentElement().form);
565
+ }
566
+ }
565
567
  }
566
568
 
567
569
  _dom.fireEvent.keyUp(currentElement(), {
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.6",
3
+ "version": "12.1.10",
4
4
  "description": "Fire events the same way the user does",
5
5
  "main": "dist/index.js",
6
6
  "typings": "typings/index.d.ts",