@instructure/ui-a11y-utils 9.2.1-snapshot-4 → 9.2.1-snapshot-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.
@@ -0,0 +1,202 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ var _react = _interopRequireDefault(require("react"));
5
+ var _react2 = require("@testing-library/react");
6
+ require("@testing-library/jest-dom");
7
+ var _ScreenReaderFocusRegion = require("../ScreenReaderFocusRegion");
8
+ var _div, _div2;
9
+ /*
10
+ * The MIT License (MIT)
11
+ *
12
+ * Copyright (c) 2015 - present Instructure, Inc.
13
+ *
14
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
15
+ * of this software and associated documentation files (the "Software"), to deal
16
+ * in the Software without restriction, including without limitation the rights
17
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
+ * copies of the Software, and to permit persons to whom the Software is
19
+ * furnished to do so, subject to the following conditions:
20
+ *
21
+ * The above copyright notice and this permission notice shall be included in all
22
+ * copies or substantial portions of the Software.
23
+ *
24
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
+ * SOFTWARE.
31
+ */
32
+ describe('ScreenReaderFocusRegion', () => {
33
+ const element = _div || (_div = /*#__PURE__*/_react.default.createElement("div", {
34
+ "data-testid": "parent",
35
+ role: "main",
36
+ "aria-label": "test app",
37
+ id: "test-parent3"
38
+ }, /*#__PURE__*/_react.default.createElement("div", {
39
+ "data-testid": "ignore",
40
+ role: "alert"
41
+ }, /*#__PURE__*/_react.default.createElement("span", null, "test alert")), /*#__PURE__*/_react.default.createElement("div", {
42
+ "data-testid": "child"
43
+ }, /*#__PURE__*/_react.default.createElement("div", {
44
+ "data-testid": "descendant"
45
+ }, "foo"), /*#__PURE__*/_react.default.createElement("div", {
46
+ "data-testid": "descendant"
47
+ }, /*#__PURE__*/_react.default.createElement("div", {
48
+ "data-testid": "descendant"
49
+ }, "bar"))), /*#__PURE__*/_react.default.createElement("div", {
50
+ "data-testid": "parent",
51
+ "aria-hidden": "true",
52
+ id: "test-parent2"
53
+ }, /*#__PURE__*/_react.default.createElement("div", {
54
+ "data-testid": "child"
55
+ }), /*#__PURE__*/_react.default.createElement("div", {
56
+ role: "dialog",
57
+ "aria-label": "some content",
58
+ "data-testid": "parent",
59
+ id: "test-parent1"
60
+ }, /*#__PURE__*/_react.default.createElement("div", {
61
+ "data-testid": "content"
62
+ }, /*#__PURE__*/_react.default.createElement("div", null, "Hello world"), /*#__PURE__*/_react.default.createElement("button", null, "click me"), /*#__PURE__*/_react.default.createElement("button", null, "or click me")), /*#__PURE__*/_react.default.createElement("span", {
63
+ "data-testid": "child"
64
+ }, /*#__PURE__*/_react.default.createElement("ul", {
65
+ "data-testid": "descendant"
66
+ }, /*#__PURE__*/_react.default.createElement("li", {
67
+ "data-testid": "descendant"
68
+ }, "item 1"), /*#__PURE__*/_react.default.createElement("li", {
69
+ "data-testid": "descendant"
70
+ }, "item 2"), /*#__PURE__*/_react.default.createElement("li", {
71
+ "data-testid": "descendant"
72
+ }, "item 3"))))), /*#__PURE__*/_react.default.createElement("div", {
73
+ "data-testid": "child-initial-hidden",
74
+ "aria-hidden": "true"
75
+ }, /*#__PURE__*/_react.default.createElement("div", {
76
+ "data-testid": "descendant"
77
+ }, "foo"), /*#__PURE__*/_react.default.createElement("div", {
78
+ "data-testid": "descendant"
79
+ }, "bar"))));
80
+ it('should accept a function for liveRegion', async () => {
81
+ (0, _react2.render)(element);
82
+ const ignore = _react2.screen.getByTestId('ignore');
83
+ const content = _react2.screen.getByTestId('content');
84
+ const screenReaderFocusRegion = new _ScreenReaderFocusRegion.ScreenReaderFocusRegion(content, {
85
+ liveRegion: () => ignore,
86
+ shouldContainFocus: true
87
+ });
88
+ screenReaderFocusRegion.activate();
89
+ await (0, _react2.waitFor)(() => {
90
+ expect(ignore).not.toHaveAttribute('aria-hidden');
91
+ });
92
+ });
93
+ it("should apply aria-hidden to all children of content's parent nodes unless they are live regions", async () => {
94
+ (0, _react2.render)(element);
95
+ const ignore = _react2.screen.getByTestId('ignore');
96
+ const content = _react2.screen.getByTestId('content');
97
+ const children = _react2.screen.getAllByTestId('child');
98
+ const screenReaderFocusRegion = new _ScreenReaderFocusRegion.ScreenReaderFocusRegion(content, {
99
+ liveRegion: ignore,
100
+ shouldContainFocus: true
101
+ });
102
+ screenReaderFocusRegion.activate();
103
+ children.forEach(node => {
104
+ expect(node).toHaveAttribute('aria-hidden');
105
+ });
106
+ expect(ignore).not.toHaveAttribute('aria-hidden');
107
+ });
108
+ it("should mute designated attributes for content's parent nodes", async () => {
109
+ (0, _react2.render)(element);
110
+ const content = _react2.screen.getByTestId('content');
111
+ const parents = _react2.screen.getAllByTestId('parent');
112
+ const screenReaderFocusRegion = new _ScreenReaderFocusRegion.ScreenReaderFocusRegion(content);
113
+ screenReaderFocusRegion.activate();
114
+ parents.forEach(node => {
115
+ expect(node).not.toHaveAttribute('aria-hidden');
116
+ expect(node).not.toHaveAttribute('aria-label');
117
+ expect(node).not.toHaveAttribute('role');
118
+ });
119
+ });
120
+ it('should not apply aria-hidden to descendants', async () => {
121
+ (0, _react2.render)(element);
122
+ const content = _react2.screen.getByTestId('content');
123
+ const descendants = _react2.screen.getAllByTestId('descendant');
124
+ const screenReaderFocusRegion = new _ScreenReaderFocusRegion.ScreenReaderFocusRegion(content);
125
+ screenReaderFocusRegion.activate();
126
+ descendants.forEach(node => {
127
+ expect(node).not.toHaveAttribute('aria-hidden');
128
+ });
129
+ });
130
+ it('should not apply aria-hidden to dynamically added descendants of content', async () => {
131
+ (0, _react2.render)(element);
132
+ const content = _react2.screen.getByTestId('content');
133
+ const screenReaderFocusRegion = new _ScreenReaderFocusRegion.ScreenReaderFocusRegion(content);
134
+ screenReaderFocusRegion.activate();
135
+ const desc = document.createElement('div');
136
+ content.appendChild(desc);
137
+ screenReaderFocusRegion.handleDOMMutation([{
138
+ addedNodes: [desc],
139
+ removedNodes: []
140
+ }]);
141
+ Array.from(content.childNodes).forEach(node => {
142
+ expect(node).not.toHaveAttribute('aria-hidden');
143
+ });
144
+ });
145
+ it('should remove aria-hidden from children unless they had aria-hidden before', async () => {
146
+ (0, _react2.render)(element);
147
+ const content = _react2.screen.getByTestId('content');
148
+ const screenReaderFocusRegion = new _ScreenReaderFocusRegion.ScreenReaderFocusRegion(content);
149
+ const childNodes = _react2.screen.getAllByTestId('child');
150
+ const exception = _react2.screen.getByTestId('child-initial-hidden');
151
+ screenReaderFocusRegion.activate();
152
+ screenReaderFocusRegion.deactivate();
153
+ childNodes.forEach(node => {
154
+ expect(node).not.toHaveAttribute('aria-hidden');
155
+ });
156
+ expect(exception).toHaveAttribute('aria-hidden');
157
+ });
158
+ it('should properly restore and unmute parent attributes', async () => {
159
+ (0, _react2.render)(element);
160
+ const content = _react2.screen.getByTestId('content');
161
+ const screenReaderFocusRegion = new _ScreenReaderFocusRegion.ScreenReaderFocusRegion(content);
162
+ const parentNodes = _react2.screen.getAllByTestId('parent');
163
+ const attrsMap = {};
164
+ parentNodes.forEach(node => {
165
+ attrsMap[node.getAttribute('id')] = [...node.attributes];
166
+ });
167
+ screenReaderFocusRegion.activate();
168
+ screenReaderFocusRegion.deactivate();
169
+ parentNodes.forEach(node => {
170
+ const preNodeAttrs = attrsMap[node.getAttribute('id')];
171
+ const postNodeAttrs = [...node.attributes];
172
+
173
+ // both should have same number of attributes
174
+ expect(preNodeAttrs.length).toEqual(postNodeAttrs.length);
175
+ preNodeAttrs.forEach(preNodeAttribute => {
176
+ const matchingAttribute = postNodeAttrs.filter(postNodeAttribute => preNodeAttribute.name === postNodeAttribute.name)[0];
177
+ expect(matchingAttribute.value).toEqual(preNodeAttribute.value);
178
+ });
179
+ });
180
+ });
181
+ it('should not apply aria-hidden to elements that have aria-live attributes', async () => {
182
+ (0, _react2.render)(_div2 || (_div2 = /*#__PURE__*/_react.default.createElement("div", {
183
+ "data-testid": "main",
184
+ role: "main",
185
+ "aria-label": "test app"
186
+ }, /*#__PURE__*/_react.default.createElement("div", {
187
+ "data-testid": "live",
188
+ "aria-live": "assertive"
189
+ }), /*#__PURE__*/_react.default.createElement("div", {
190
+ "data-testid": "regular"
191
+ }), /*#__PURE__*/_react.default.createElement("div", {
192
+ "data-testid": "content"
193
+ }))));
194
+ const content = _react2.screen.getByTestId('content');
195
+ const screenReaderFocusRegion = new _ScreenReaderFocusRegion.ScreenReaderFocusRegion(content);
196
+ screenReaderFocusRegion.activate();
197
+ const liveRegion = _react2.screen.getByTestId('live');
198
+ const regularRegion = _react2.screen.getByTestId('regular');
199
+ expect(liveRegion).not.toHaveAttribute('aria-hidden');
200
+ expect(regularRegion).toHaveAttribute('aria-hidden');
201
+ });
202
+ });
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ var _react = _interopRequireDefault(require("react"));
5
+ require("@testing-library/jest-dom");
6
+ var _ScreenReaderContent2 = require("@instructure/ui-a11y-content/lib/ScreenReaderContent");
7
+ var _hasVisibleChildren = require("../hasVisibleChildren");
8
+ var _ScreenReaderContent, _div;
9
+ /*
10
+ * The MIT License (MIT)
11
+ *
12
+ * Copyright (c) 2015 - present Instructure, Inc.
13
+ *
14
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
15
+ * of this software and associated documentation files (the "Software"), to deal
16
+ * in the Software without restriction, including without limitation the rights
17
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
+ * copies of the Software, and to permit persons to whom the Software is
19
+ * furnished to do so, subject to the following conditions:
20
+ *
21
+ * The above copyright notice and this permission notice shall be included in all
22
+ * copies or substantial portions of the Software.
23
+ *
24
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
+ * SOFTWARE.
31
+ */
32
+ describe('hasVisibleChildren', () => {
33
+ it('should not count ScreenReaderContent as visible content', async () => {
34
+ expect((0, _hasVisibleChildren.hasVisibleChildren)(_ScreenReaderContent || (_ScreenReaderContent = /*#__PURE__*/_react.default.createElement(_ScreenReaderContent2.ScreenReaderContent, null, "Foo")))).toBe(false);
35
+ });
36
+ it('should count everything else as visible', async () => {
37
+ expect((0, _hasVisibleChildren.hasVisibleChildren)(_div || (_div = /*#__PURE__*/_react.default.createElement("div", null, "Foo")))).toBe(true);
38
+ });
39
+ });
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ var _react = _interopRequireDefault(require("react"));
5
+ var _react2 = require("@testing-library/react");
6
+ var _vitest = require("vitest");
7
+ require("@testing-library/jest-dom");
8
+ var _scopeTab = require("../scopeTab");
9
+ var _div, _div2, _div3;
10
+ /*
11
+ * The MIT License (MIT)
12
+ *
13
+ * Copyright (c) 2015 - present Instructure, Inc.
14
+ *
15
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
16
+ * of this software and associated documentation files (the "Software"), to deal
17
+ * in the Software without restriction, including without limitation the rights
18
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19
+ * copies of the Software, and to permit persons to whom the Software is
20
+ * furnished to do so, subject to the following conditions:
21
+ *
22
+ * The above copyright notice and this permission notice shall be included in all
23
+ * copies or substantial portions of the Software.
24
+ *
25
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
+ * SOFTWARE.
32
+ */
33
+ const MOCK_EVENT = new KeyboardEvent('mockEvent', {
34
+ shiftKey: false
35
+ });
36
+ MOCK_EVENT.preventDefault = () => {};
37
+ describe('scopeTab', () => {
38
+ it('should scope tab within container', async () => {
39
+ (0, _react2.render)(_div || (_div = /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("div", {
40
+ "data-testid": "container"
41
+ }, /*#__PURE__*/_react.default.createElement("input", {
42
+ "data-testid": "first"
43
+ }), /*#__PURE__*/_react.default.createElement("input", {
44
+ "data-testid": "second"
45
+ })))));
46
+ const container = _react2.screen.getByTestId('container');
47
+ const first = _react2.screen.getByTestId('first');
48
+ const second = _react2.screen.getByTestId('second');
49
+ second.focus();
50
+ await (0, _react2.waitFor)(() => {
51
+ expect(document.activeElement).toBe(second);
52
+ });
53
+ (0, _scopeTab.scopeTab)(container, MOCK_EVENT);
54
+ await (0, _react2.waitFor)(() => {
55
+ expect(document.activeElement).toBe(first);
56
+ });
57
+ });
58
+ it('should not attempt scoping when no tabbable children', async () => {
59
+ (0, _react2.render)(_div2 || (_div2 = /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("div", {
60
+ "data-testid": "container"
61
+ }, "Hello"), /*#__PURE__*/_react.default.createElement("input", null))));
62
+ const input = _react2.screen.getByRole('textbox');
63
+ const container = _react2.screen.getByTestId('container');
64
+ input.focus();
65
+ (0, _scopeTab.scopeTab)(container, MOCK_EVENT);
66
+ await (0, _react2.waitFor)(() => {
67
+ expect(document.activeElement).toBe(input);
68
+ });
69
+ });
70
+ it('should execute callback when provided instead of default behavior', async () => {
71
+ const cb = _vitest.vi.fn();
72
+ (0, _react2.render)(_div3 || (_div3 = /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("div", {
73
+ "data-testid": "container"
74
+ }, /*#__PURE__*/_react.default.createElement("input", null)))));
75
+ const input = _react2.screen.getByRole('textbox');
76
+ const container = _react2.screen.getByTestId('container');
77
+ input.focus();
78
+ (0, _scopeTab.scopeTab)(container, MOCK_EVENT, cb);
79
+ await (0, _react2.waitFor)(() => {
80
+ expect(cb).toHaveBeenCalled();
81
+ });
82
+ });
83
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-a11y-utils",
3
- "version": "9.2.1-snapshot-4",
3
+ "version": "9.2.1-snapshot-6",
4
4
  "description": "A collection of utilities for managing focus and screen reader behavior",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -23,18 +23,20 @@
23
23
  "license": "MIT",
24
24
  "dependencies": {
25
25
  "@babel/runtime": "^7.24.5",
26
- "@instructure/console": "9.2.1-snapshot-4",
27
- "@instructure/shared-types": "9.2.1-snapshot-4",
28
- "@instructure/ui-a11y-content": "9.2.1-snapshot-4",
29
- "@instructure/ui-dom-utils": "9.2.1-snapshot-4",
30
- "@instructure/ui-react-utils": "9.2.1-snapshot-4",
31
- "@instructure/uid": "9.2.1-snapshot-4",
26
+ "@instructure/console": "9.2.1-snapshot-6",
27
+ "@instructure/shared-types": "9.2.1-snapshot-6",
28
+ "@instructure/ui-a11y-content": "9.2.1-snapshot-6",
29
+ "@instructure/ui-dom-utils": "9.2.1-snapshot-6",
30
+ "@instructure/ui-react-utils": "9.2.1-snapshot-6",
31
+ "@instructure/uid": "9.2.1-snapshot-6",
32
32
  "keycode": "^2.2.1"
33
33
  },
34
34
  "devDependencies": {
35
- "@instructure/ui-babel-preset": "9.2.1-snapshot-4",
36
- "@instructure/ui-color-utils": "9.2.1-snapshot-4",
37
- "@instructure/ui-test-utils": "9.2.1-snapshot-4"
35
+ "@instructure/ui-babel-preset": "9.2.1-snapshot-6",
36
+ "@instructure/ui-color-utils": "9.2.1-snapshot-6",
37
+ "@testing-library/jest-dom": "^6.4.5",
38
+ "@testing-library/react": "^15.0.7",
39
+ "vitest": "^1.6.0"
38
40
  },
39
41
  "peerDependencies": {
40
42
  "react": ">=16.8 <=18"
@@ -0,0 +1,152 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ import React from 'react'
25
+ import { render, screen, waitFor } from '@testing-library/react'
26
+ import '@testing-library/jest-dom'
27
+
28
+ import { FocusRegionManager } from '../FocusRegionManager'
29
+
30
+
31
+ describe('FocusRegionManager', () => {
32
+ beforeEach(async () => {
33
+ FocusRegionManager.clearEntries()
34
+ })
35
+
36
+ it('should focus the first tabbable element when focused', async () => {
37
+ render(
38
+ <div data-test-parent role="main" aria-label="test app" id="test-parent3">
39
+ <div data-test-ignore role="alert">
40
+ <span>test alert</span>
41
+ </div>
42
+ <div data-test-child>
43
+ <div data-test-descendant></div>
44
+ <div data-test-descendant>
45
+ <div data-test-descendant>
46
+ <button data-testid="button">click me</button>
47
+ </div>
48
+ </div>
49
+ </div>
50
+ <div data-test-parent aria-hidden="true" id="test-parent2">
51
+ <div data-test-child></div>
52
+ <div
53
+ role="dialog"
54
+ aria-label="some content"
55
+ data-test-parent
56
+ id="test-parent1"
57
+ >
58
+ <div data-testid="content">
59
+ <div>Hello world</div>
60
+ <button data-testid="first-tabbable">click me</button>
61
+ <button>or click me</button>
62
+ </div>
63
+ <span data-test-child>
64
+ <ul data-test-descendant>
65
+ <li data-test-descendant>item 1</li>
66
+ <li data-test-descendant>item 2</li>
67
+ <li data-test-descendant>item 3</li>
68
+ </ul>
69
+ </span>
70
+ </div>
71
+ </div>
72
+ <div data-test-child aria-hidden="true">
73
+ <div data-test-descendant></div>
74
+ <div data-test-descendant></div>
75
+ </div>
76
+ <iframe id="frame" title="frame"></iframe>
77
+ </div>
78
+ )
79
+
80
+ const button = screen.getByTestId('button')
81
+ const content = screen.getByTestId('content')
82
+ const firstTabbable = screen.getByTestId('first-tabbable')
83
+
84
+ button.focus()
85
+
86
+ expect(document.activeElement).toBe(button)
87
+
88
+ FocusRegionManager.focusRegion(content)
89
+
90
+ await waitFor(() => {
91
+ expect(document.activeElement).toBe(firstTabbable)
92
+ })
93
+ })
94
+
95
+ it('should return focus when blurred', async () => {
96
+ render(
97
+ <div data-test-parent role="main" aria-label="test app" id="test-parent3">
98
+ <div data-test-ignore role="alert">
99
+ <span>test alert</span>
100
+ </div>
101
+ <div data-test-child>
102
+ <div data-test-descendant></div>
103
+ <div data-test-descendant>
104
+ <div data-test-descendant>
105
+ <button data-testid="button">click me</button>
106
+ </div>
107
+ </div>
108
+ </div>
109
+ <div data-test-parent aria-hidden="true" id="test-parent2">
110
+ <div data-test-child></div>
111
+ <div
112
+ role="dialog"
113
+ aria-label="some content"
114
+ data-test-parent
115
+ id="test-parent1"
116
+ >
117
+ <div data-testid="content">
118
+ <div>Hello world</div>
119
+ <button data-test-first-tabbable>click me</button>
120
+ <button>or click me</button>
121
+ </div>
122
+ <span data-test-child>
123
+ <ul data-test-descendant>
124
+ <li data-test-descendant>item 1</li>
125
+ <li data-test-descendant>item 2</li>
126
+ <li data-test-descendant>item 3</li>
127
+ </ul>
128
+ </span>
129
+ </div>
130
+ </div>
131
+ <div data-test-child aria-hidden="true">
132
+ <div data-test-descendant></div>
133
+ <div data-test-descendant></div>
134
+ </div>
135
+ <iframe id="frame" title="frame"></iframe>
136
+ </div>
137
+ )
138
+ const button = screen.getByTestId('button')
139
+ const content = screen.getByTestId('content')
140
+
141
+ button.focus()
142
+
143
+ expect(document.activeElement).toBe(button)
144
+
145
+ FocusRegionManager.focusRegion(content)
146
+ FocusRegionManager.blurRegion(content)
147
+
148
+ await waitFor(() => {
149
+ expect(document.activeElement).toBe(button)
150
+ })
151
+ })
152
+ })