@instructure/ui-a11y-utils 10.19.2-snapshot-3 → 10.19.2-snapshot-4

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