@testing-library/user-event 14.6.9 → 14.6.11

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.
@@ -3,6 +3,7 @@
3
3
  var dispatchEvent = require('../event/dispatchEvent.js');
4
4
  var isElementType = require('../utils/misc/isElementType.js');
5
5
  require('../utils/dataTransfer/Clipboard.js');
6
+ var getActiveElement = require('../utils/focus/getActiveElement.js');
6
7
  var UI = require('./UI.js');
7
8
  require('@testing-library/dom');
8
9
  var interceptor = require('./interceptor.js');
@@ -13,7 +14,9 @@ function prepareDocument(document) {
13
14
  return;
14
15
  }
15
16
  document.addEventListener('focus', (e)=>{
16
- const el = e.target;
17
+ var _e_composedPath_;
18
+ // Focus on elements in a shadow tree is retargeted to the shadow host.
19
+ const el = (_e_composedPath_ = e.composedPath()[0]) !== null && _e_composedPath_ !== void 0 ? _e_composedPath_ : e.target;
17
20
  prepareElement(el);
18
21
  }, {
19
22
  capture: true,
@@ -21,12 +24,14 @@ function prepareDocument(document) {
21
24
  });
22
25
  // Our test environment defaults to `document.body` as `activeElement`.
23
26
  // In other environments this might be `null` when preparing.
27
+ const activeElement = getActiveElement.getActiveElement(document);
24
28
  // istanbul ignore else
25
- if (document.activeElement) {
26
- prepareElement(document.activeElement);
29
+ if (activeElement) {
30
+ prepareElement(activeElement);
27
31
  }
28
32
  document.addEventListener('blur', (e)=>{
29
- const el = e.target;
33
+ var _e_composedPath_;
34
+ const el = (_e_composedPath_ = e.composedPath()[0]) !== null && _e_composedPath_ !== void 0 ? _e_composedPath_ : e.target;
30
35
  const initialValue = UI.getInitialValue(el);
31
36
  if (initialValue !== undefined) {
32
37
  if (el.value !== initialValue) {
@@ -18,7 +18,7 @@ registry.behavior.keypress = (event, target, instance)=>{
18
18
  const submit = form === null || form === void 0 ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]');
19
19
  if (submit) {
20
20
  return ()=>instance.dispatchUIEvent(submit, 'click');
21
- } else if (form && SubmitSingleInputOnEnter.includes(target.type) && form.querySelectorAll('input').length === 1) {
21
+ } else if (form && SubmitSingleInputOnEnter.includes(target.type) && Array.from(form.querySelectorAll('input')).filter((el)=>BlockImplicitSubmission.includes(el.type)).length === 1) {
22
22
  return ()=>instance.dispatchUIEvent(form, 'submit');
23
23
  } else {
24
24
  return;
@@ -39,6 +39,21 @@ const ClickInputOnEnter = [
39
39
  'reset',
40
40
  'submit'
41
41
  ];
42
+ // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#field-that-blocks-implicit-submission
43
+ const BlockImplicitSubmission = [
44
+ 'date',
45
+ 'datetime-local',
46
+ 'email',
47
+ 'month',
48
+ 'number',
49
+ 'password',
50
+ 'search',
51
+ 'tel',
52
+ 'text',
53
+ 'time',
54
+ 'url',
55
+ 'week'
56
+ ];
42
57
  const SubmitSingleInputOnEnter = [
43
58
  'email',
44
59
  'month',
@@ -1,6 +1,7 @@
1
1
  import { dispatchDOMEvent } from '../event/dispatchEvent.js';
2
2
  import { isElementType } from '../utils/misc/isElementType.js';
3
3
  import '../utils/dataTransfer/Clipboard.js';
4
+ import { getActiveElement } from '../utils/focus/getActiveElement.js';
4
5
  import { getInitialValue, clearInitialValue } from './UI.js';
5
6
  import '@testing-library/dom';
6
7
  import { prepareValueInterceptor, prepareSelectionInterceptor, prepareRangeTextInterceptor } from './interceptor.js';
@@ -11,7 +12,9 @@ function prepareDocument(document) {
11
12
  return;
12
13
  }
13
14
  document.addEventListener('focus', (e)=>{
14
- const el = e.target;
15
+ var _e_composedPath_;
16
+ // Focus on elements in a shadow tree is retargeted to the shadow host.
17
+ const el = (_e_composedPath_ = e.composedPath()[0]) !== null && _e_composedPath_ !== void 0 ? _e_composedPath_ : e.target;
15
18
  prepareElement(el);
16
19
  }, {
17
20
  capture: true,
@@ -19,12 +22,14 @@ function prepareDocument(document) {
19
22
  });
20
23
  // Our test environment defaults to `document.body` as `activeElement`.
21
24
  // In other environments this might be `null` when preparing.
25
+ const activeElement = getActiveElement(document);
22
26
  // istanbul ignore else
23
- if (document.activeElement) {
24
- prepareElement(document.activeElement);
27
+ if (activeElement) {
28
+ prepareElement(activeElement);
25
29
  }
26
30
  document.addEventListener('blur', (e)=>{
27
- const el = e.target;
31
+ var _e_composedPath_;
32
+ const el = (_e_composedPath_ = e.composedPath()[0]) !== null && _e_composedPath_ !== void 0 ? _e_composedPath_ : e.target;
28
33
  const initialValue = getInitialValue(el);
29
34
  if (initialValue !== undefined) {
30
35
  if (el.value !== initialValue) {
@@ -16,7 +16,7 @@ behavior.keypress = (event, target, instance)=>{
16
16
  const submit = form === null || form === void 0 ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]');
17
17
  if (submit) {
18
18
  return ()=>instance.dispatchUIEvent(submit, 'click');
19
- } else if (form && SubmitSingleInputOnEnter.includes(target.type) && form.querySelectorAll('input').length === 1) {
19
+ } else if (form && SubmitSingleInputOnEnter.includes(target.type) && Array.from(form.querySelectorAll('input')).filter((el)=>BlockImplicitSubmission.includes(el.type)).length === 1) {
20
20
  return ()=>instance.dispatchUIEvent(form, 'submit');
21
21
  } else {
22
22
  return;
@@ -37,6 +37,21 @@ const ClickInputOnEnter = [
37
37
  'reset',
38
38
  'submit'
39
39
  ];
40
+ // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#field-that-blocks-implicit-submission
41
+ const BlockImplicitSubmission = [
42
+ 'date',
43
+ 'datetime-local',
44
+ 'email',
45
+ 'month',
46
+ 'number',
47
+ 'password',
48
+ 'search',
49
+ 'tel',
50
+ 'text',
51
+ 'time',
52
+ 'url',
53
+ 'week'
54
+ ];
40
55
  const SubmitSingleInputOnEnter = [
41
56
  'email',
42
57
  'month',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testing-library/user-event",
3
- "version": "14.6.9",
3
+ "version": "14.6.11",
4
4
  "description": "Fire events the same way the user does",
5
5
  "keywords": [
6
6
  "react-testing-library",