@internetarchive/modal-manager 2.0.4 → 2.0.5-webdev-8155.1
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/.editorconfig +29 -29
- package/.github/workflows/ci.yml +40 -30
- package/.github/workflows/gh-pages-main.yml +42 -42
- package/.github/workflows/pr-preview.yml +40 -40
- package/.prettierrc +4 -0
- package/.vscode/extensions.json +10 -0
- package/.vscode/tasks.json +12 -0
- package/LICENSE +661 -661
- package/README.md +139 -139
- package/custom-elements.json +170 -170
- package/demo/app-root.ts +366 -0
- package/dist/demo/app-root.d.ts +22 -0
- package/dist/demo/app-root.js +338 -0
- package/dist/demo/app-root.js.map +1 -0
- package/dist/index.d.ts +7 -7
- package/dist/index.js +5 -5
- package/dist/src/assets/arrow-left-icon.d.ts +2 -2
- package/dist/src/assets/arrow-left-icon.js +2 -2
- package/dist/src/assets/ia-logo-icon.d.ts +2 -2
- package/dist/src/assets/ia-logo-icon.js +2 -2
- package/dist/src/modal-config.d.ts +104 -104
- package/dist/src/modal-config.js +23 -24
- package/dist/src/modal-config.js.map +1 -1
- package/dist/src/modal-manager-host-bridge-interface.d.ts +12 -12
- package/dist/src/modal-manager-host-bridge-interface.js +1 -1
- package/dist/src/modal-manager-host-bridge.d.ts +34 -34
- package/dist/src/modal-manager-host-bridge.js +62 -62
- package/dist/src/modal-manager-host-bridge.js.map +1 -1
- package/dist/src/modal-manager-interface.d.ts +27 -27
- package/dist/src/modal-manager-interface.js +1 -1
- package/dist/src/modal-manager-mode.d.ts +10 -10
- package/dist/src/modal-manager-mode.js +11 -11
- package/dist/src/modal-manager.d.ts +137 -137
- package/dist/src/modal-manager.js +243 -249
- package/dist/src/modal-manager.js.map +1 -1
- package/dist/src/modal-template.d.ts +41 -41
- package/dist/src/modal-template.js +119 -118
- package/dist/src/modal-template.js.map +1 -1
- package/dist/src/shoelace/active-elements.d.ts +15 -15
- package/dist/src/shoelace/active-elements.js +28 -27
- package/dist/src/shoelace/active-elements.js.map +1 -1
- package/dist/src/shoelace/modal.d.ts +24 -24
- package/dist/src/shoelace/modal.js +130 -131
- package/dist/src/shoelace/modal.js.map +1 -1
- package/dist/src/shoelace/tabbable.d.ts +9 -9
- package/dist/src/shoelace/tabbable.js +168 -169
- package/dist/src/shoelace/tabbable.js.map +1 -1
- package/dist/test/modal-config.test.d.ts +1 -1
- package/dist/test/modal-config.test.js +68 -69
- package/dist/test/modal-config.test.js.map +1 -1
- package/dist/test/modal-manager.test.d.ts +1 -1
- package/dist/test/modal-manager.test.js +306 -309
- package/dist/test/modal-manager.test.js.map +1 -1
- package/dist/test/modal-template.test.d.ts +1 -1
- package/dist/test/modal-template.test.js +158 -167
- package/dist/test/modal-template.test.js.map +1 -1
- package/dist/vite.config.d.ts +2 -2
- package/dist/vite.config.js +22 -22
- package/dist/vitest.config.ci.d.ts +2 -0
- package/dist/vitest.config.ci.js +24 -0
- package/dist/vitest.config.ci.js.map +1 -0
- package/docs/assets/css/main.css +2678 -2678
- package/docs/classes/_src_modal_config_.modalconfig.html +429 -429
- package/docs/classes/_src_modal_manager_.modalmanager.html +7702 -7702
- package/docs/classes/_src_modal_manager_host_bridge_.modalmanagerhostbridge.html +409 -409
- package/docs/classes/_src_modal_template_.modaltemplate.html +7096 -7096
- package/docs/enums/_src_modal_manager_mode_.modalmanagermode.html +196 -196
- package/docs/globals.html +150 -150
- package/docs/index.html +252 -252
- package/docs/interfaces/_src_modal_manager_host_bridge_interface_.modalmanagerhostbridgeinterface.html +210 -210
- package/docs/interfaces/_src_modal_manager_interface_.modalmanagerinterface.html +7095 -7095
- package/docs/modules/_index_.html +208 -208
- package/docs/modules/_src_modal_config_.html +146 -146
- package/docs/modules/_src_modal_manager_.html +146 -146
- package/docs/modules/_src_modal_manager_host_bridge_.html +146 -146
- package/docs/modules/_src_modal_manager_host_bridge_interface_.html +146 -146
- package/docs/modules/_src_modal_manager_interface_.html +146 -146
- package/docs/modules/_src_modal_manager_mode_.html +146 -146
- package/docs/modules/_src_modal_template_.html +146 -146
- package/docs/modules/_test_modal_config_test_.html +106 -106
- package/docs/modules/_test_modal_manager_test_.html +106 -106
- package/docs/modules/_test_modal_template_test_.html +106 -106
- package/eslint.config.mjs +53 -0
- package/index.html +33 -300
- package/package.json +73 -85
- package/renovate.json +7 -7
- package/src/modal-config.ts +14 -14
- package/src/modal-manager-host-bridge.ts +2 -2
- package/src/modal-manager.ts +305 -305
- package/src/modal-template.ts +4 -2
- package/src/shoelace/LICENSE.md +6 -6
- package/src/shoelace/active-elements.ts +3 -2
- package/src/shoelace/modal.ts +5 -5
- package/src/shoelace/tabbable.ts +4 -3
- package/test/modal-config.test.ts +4 -4
- package/test/modal-manager.test.ts +402 -393
- package/test/modal-template.test.ts +42 -35
- package/tsconfig.json +25 -21
- package/vitest.config.ci.ts +27 -0
- package/.eslintrc.js +0 -14
- package/karma.conf.js +0 -24
|
@@ -1,393 +1,402 @@
|
|
|
1
|
-
import {
|
|
2
|
-
fixture,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from '@open-wc/testing';
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
await
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
expect(el.customModalContent).to.equal(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
el
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
await
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
await
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
await elementUpdated(el);
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
expect(
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
await
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
await
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
await
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
el
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
await elementUpdated(el);
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
el
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
const
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
await elementUpdated(el);
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
el
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
await
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
expect(modal?.shadowRoot?.activeElement).to.equal(closeButton);
|
|
339
|
-
|
|
340
|
-
//
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
//
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
</button>
|
|
366
|
-
<
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
//
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
1
|
+
import {
|
|
2
|
+
fixture,
|
|
3
|
+
oneEvent,
|
|
4
|
+
elementUpdated,
|
|
5
|
+
nextFrame,
|
|
6
|
+
fixtureCleanup,
|
|
7
|
+
} from '@open-wc/testing-helpers';
|
|
8
|
+
import { describe, test, expect, afterEach } from 'vitest';
|
|
9
|
+
import { TemplateResult, html } from 'lit';
|
|
10
|
+
|
|
11
|
+
import '../src/modal-manager';
|
|
12
|
+
import { ModalConfig } from '../src/modal-config';
|
|
13
|
+
import { ModalManager } from '../src/modal-manager';
|
|
14
|
+
import { ModalManagerMode } from '../src/modal-manager-mode';
|
|
15
|
+
import { ModalManagerInterface } from '../src/modal-manager-interface';
|
|
16
|
+
|
|
17
|
+
import { getTabbableElements } from '../src/shoelace/tabbable';
|
|
18
|
+
|
|
19
|
+
describe('Modal Manager', () => {
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
fixtureCleanup();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('defaults to closed', async () => {
|
|
25
|
+
const el = (await fixture(html`
|
|
26
|
+
<modal-manager></modal-manager>
|
|
27
|
+
`)) as ModalManager;
|
|
28
|
+
|
|
29
|
+
expect(el.mode).to.equal('closed');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('can be closed by calling closeModal', async () => {
|
|
33
|
+
const el = (await fixture(html`
|
|
34
|
+
<modal-manager .mode=${ModalManagerMode.Open}></modal-manager>
|
|
35
|
+
`)) as ModalManager;
|
|
36
|
+
|
|
37
|
+
el.customModalContent = 'foo' as unknown as TemplateResult;
|
|
38
|
+
await elementUpdated(el);
|
|
39
|
+
|
|
40
|
+
expect(el.customModalContent).to.equal('foo');
|
|
41
|
+
el.closeModal();
|
|
42
|
+
await elementUpdated(el);
|
|
43
|
+
|
|
44
|
+
expect(el.mode).to.equal('closed');
|
|
45
|
+
expect(el.customModalContent).to.equal(undefined);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('can be closed by clicking on the backdrop', async () => {
|
|
49
|
+
const el = (await fixture(html`
|
|
50
|
+
<modal-manager .mode=${ModalManagerMode.Open}></modal-manager>
|
|
51
|
+
`)) as ModalManager;
|
|
52
|
+
|
|
53
|
+
const backdrop = el.shadowRoot?.querySelector('.backdrop');
|
|
54
|
+
const clickEvent = new MouseEvent('click');
|
|
55
|
+
|
|
56
|
+
backdrop?.dispatchEvent(clickEvent);
|
|
57
|
+
await elementUpdated(el);
|
|
58
|
+
|
|
59
|
+
expect(el.mode).to.equal('closed');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('emits a modeChanged event when opening', async () => {
|
|
63
|
+
const el = (await fixture(html`
|
|
64
|
+
<modal-manager></modal-manager>
|
|
65
|
+
`)) as ModalManager;
|
|
66
|
+
|
|
67
|
+
const config = new ModalConfig();
|
|
68
|
+
|
|
69
|
+
setTimeout(() => {
|
|
70
|
+
el.showModal({ config });
|
|
71
|
+
});
|
|
72
|
+
const response = await oneEvent(el, 'modeChanged');
|
|
73
|
+
expect(response.detail.mode).to.equal(ModalManagerMode.Open);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('emits a modeChanged event when closing', async () => {
|
|
77
|
+
const el = (await fixture(html`
|
|
78
|
+
<modal-manager></modal-manager>
|
|
79
|
+
`)) as ModalManager;
|
|
80
|
+
|
|
81
|
+
const config = new ModalConfig();
|
|
82
|
+
await el.showModal({ config });
|
|
83
|
+
await elementUpdated(el);
|
|
84
|
+
await nextFrame();
|
|
85
|
+
|
|
86
|
+
setTimeout(() => {
|
|
87
|
+
el.closeModal();
|
|
88
|
+
});
|
|
89
|
+
const response = await oneEvent(el, 'modeChanged');
|
|
90
|
+
expect(response.detail.mode).to.equal(ModalManagerMode.Closed);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('can show a modal', async () => {
|
|
94
|
+
const el = (await fixture(html`
|
|
95
|
+
<modal-manager></modal-manager>
|
|
96
|
+
`)) as ModalManager;
|
|
97
|
+
|
|
98
|
+
const config = new ModalConfig();
|
|
99
|
+
el.showModal({ config });
|
|
100
|
+
await elementUpdated(el);
|
|
101
|
+
expect(el.mode).to.equal(ModalManagerMode.Open);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('sets the --containerHeight CSS property when the window resizes', async () => {
|
|
105
|
+
const el = (await fixture(html`
|
|
106
|
+
<modal-manager></modal-manager>
|
|
107
|
+
`)) as ModalManager;
|
|
108
|
+
|
|
109
|
+
const config = new ModalConfig();
|
|
110
|
+
el.showModal({ config });
|
|
111
|
+
await elementUpdated(el);
|
|
112
|
+
const event = new Event('resize');
|
|
113
|
+
const propBefore = el.style.getPropertyValue('--containerHeight');
|
|
114
|
+
expect(propBefore).to.equal('');
|
|
115
|
+
window.dispatchEvent(event);
|
|
116
|
+
await elementUpdated(el);
|
|
117
|
+
const propAfter = el.style.getPropertyValue('--containerHeight');
|
|
118
|
+
expect(propAfter).to.not.equal('');
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test('calls the userClosedModalCallback when the user taps the backdrop', async () => {
|
|
122
|
+
const el = (await fixture(html`
|
|
123
|
+
<modal-manager></modal-manager>
|
|
124
|
+
`)) as ModalManager;
|
|
125
|
+
|
|
126
|
+
const config = new ModalConfig();
|
|
127
|
+
let callbackCalled = false;
|
|
128
|
+
const callback = (): void => {
|
|
129
|
+
callbackCalled = true;
|
|
130
|
+
};
|
|
131
|
+
el.showModal({
|
|
132
|
+
config,
|
|
133
|
+
userClosedModalCallback: callback,
|
|
134
|
+
});
|
|
135
|
+
await elementUpdated(el);
|
|
136
|
+
|
|
137
|
+
const backdrop = el.shadowRoot?.querySelector('.backdrop');
|
|
138
|
+
const clickEvent = new MouseEvent('click');
|
|
139
|
+
backdrop?.dispatchEvent(clickEvent);
|
|
140
|
+
|
|
141
|
+
await elementUpdated(el);
|
|
142
|
+
|
|
143
|
+
expect(callbackCalled).to.equal(true);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test('does not call the userClosedModalCallback when the modal just closes', async () => {
|
|
147
|
+
const el = (await fixture(html`
|
|
148
|
+
<modal-manager></modal-manager>
|
|
149
|
+
`)) as ModalManager;
|
|
150
|
+
|
|
151
|
+
const config = new ModalConfig();
|
|
152
|
+
let callbackCalled = false;
|
|
153
|
+
const callback = (): void => {
|
|
154
|
+
callbackCalled = true;
|
|
155
|
+
};
|
|
156
|
+
el.showModal({
|
|
157
|
+
config,
|
|
158
|
+
userClosedModalCallback: callback,
|
|
159
|
+
});
|
|
160
|
+
await elementUpdated(el);
|
|
161
|
+
el.closeModal();
|
|
162
|
+
await elementUpdated(el);
|
|
163
|
+
expect(callbackCalled).to.equal(false);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test('calls the userPressedLeftNavButtonCallback when the user clicks the left nav button', async () => {
|
|
167
|
+
const el = (await fixture(html`
|
|
168
|
+
<modal-manager></modal-manager>
|
|
169
|
+
`)) as ModalManager;
|
|
170
|
+
|
|
171
|
+
const config = new ModalConfig();
|
|
172
|
+
config.showLeftNavButton = true;
|
|
173
|
+
|
|
174
|
+
let callbackCalled = false;
|
|
175
|
+
const callback = (): void => {
|
|
176
|
+
callbackCalled = true;
|
|
177
|
+
};
|
|
178
|
+
el.showModal({
|
|
179
|
+
config,
|
|
180
|
+
userPressedLeftNavButtonCallback: callback,
|
|
181
|
+
});
|
|
182
|
+
await elementUpdated(el);
|
|
183
|
+
|
|
184
|
+
const modalTemplate = el.shadowRoot?.querySelector('modal-template');
|
|
185
|
+
expect(modalTemplate).to.exist;
|
|
186
|
+
|
|
187
|
+
modalTemplate?.dispatchEvent(new Event('leftNavButtonPressed'));
|
|
188
|
+
|
|
189
|
+
await elementUpdated(el);
|
|
190
|
+
|
|
191
|
+
expect(callbackCalled).to.equal(true);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
test('mode is set to closed when close button is pressed', async () => {
|
|
195
|
+
const el = (await fixture(html`
|
|
196
|
+
<modal-manager></modal-manager>
|
|
197
|
+
`)) as ModalManager;
|
|
198
|
+
|
|
199
|
+
const config = new ModalConfig();
|
|
200
|
+
el.showModal({ config });
|
|
201
|
+
await elementUpdated(el);
|
|
202
|
+
|
|
203
|
+
expect(el.mode).to.equal('open');
|
|
204
|
+
|
|
205
|
+
const modal = el.shadowRoot?.querySelector('modal-template');
|
|
206
|
+
const closeButton = modal?.shadowRoot?.querySelector('.close-button');
|
|
207
|
+
const clickEvent = new MouseEvent('click');
|
|
208
|
+
closeButton?.dispatchEvent(clickEvent);
|
|
209
|
+
|
|
210
|
+
await elementUpdated(el);
|
|
211
|
+
|
|
212
|
+
expect(el.mode).to.equal('closed');
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test('mode is set to closed when close button gets spacebar pressed', async () => {
|
|
216
|
+
const el = (await fixture(html`
|
|
217
|
+
<modal-manager></modal-manager>
|
|
218
|
+
`)) as ModalManager;
|
|
219
|
+
|
|
220
|
+
const config = new ModalConfig();
|
|
221
|
+
el.showModal({ config });
|
|
222
|
+
await elementUpdated(el);
|
|
223
|
+
|
|
224
|
+
expect(el.mode).to.equal('open');
|
|
225
|
+
|
|
226
|
+
const modal = el.shadowRoot?.querySelector('modal-template');
|
|
227
|
+
const closeButton = modal?.shadowRoot?.querySelector('.close-button');
|
|
228
|
+
|
|
229
|
+
// Close with keyboard
|
|
230
|
+
const spacebarEvent = new KeyboardEvent('keydown', { key: ' ' });
|
|
231
|
+
closeButton?.dispatchEvent(spacebarEvent);
|
|
232
|
+
|
|
233
|
+
await elementUpdated(el);
|
|
234
|
+
|
|
235
|
+
expect(el.mode).to.equal('closed');
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
test('mode remains open when close button gets non-button keypress', async () => {
|
|
239
|
+
const el = (await fixture(html`
|
|
240
|
+
<modal-manager></modal-manager>
|
|
241
|
+
`)) as ModalManager;
|
|
242
|
+
|
|
243
|
+
const config = new ModalConfig();
|
|
244
|
+
el.showModal({ config });
|
|
245
|
+
await elementUpdated(el);
|
|
246
|
+
|
|
247
|
+
expect(el.mode).to.equal('open');
|
|
248
|
+
|
|
249
|
+
const modal = el.shadowRoot?.querySelector('modal-template');
|
|
250
|
+
const closeButton = modal?.shadowRoot?.querySelector('.close-button');
|
|
251
|
+
|
|
252
|
+
// Close with keyboard
|
|
253
|
+
const keyboardEvent = new KeyboardEvent('keydown', { key: '.' });
|
|
254
|
+
closeButton?.dispatchEvent(keyboardEvent);
|
|
255
|
+
|
|
256
|
+
await elementUpdated(el);
|
|
257
|
+
|
|
258
|
+
expect(el.mode).to.equal('open');
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
test('allows the user to close by clicking on the backdrop if configured to', async () => {
|
|
262
|
+
const el = (await fixture(html`
|
|
263
|
+
<modal-manager></modal-manager>
|
|
264
|
+
`)) as ModalManager;
|
|
265
|
+
|
|
266
|
+
const config = new ModalConfig();
|
|
267
|
+
config.closeOnBackdropClick = true;
|
|
268
|
+
el.showModal({ config });
|
|
269
|
+
await elementUpdated(el);
|
|
270
|
+
|
|
271
|
+
const backdrop = el.shadowRoot?.querySelector('.backdrop');
|
|
272
|
+
const clickEvent = new MouseEvent('click');
|
|
273
|
+
backdrop?.dispatchEvent(clickEvent);
|
|
274
|
+
|
|
275
|
+
await elementUpdated(el);
|
|
276
|
+
|
|
277
|
+
expect(el.mode).to.equal('closed');
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
test("doesn't allow the user to close by clicking on the backdrop if configured to", async () => {
|
|
281
|
+
const el = (await fixture(html`
|
|
282
|
+
<modal-manager></modal-manager>
|
|
283
|
+
`)) as ModalManagerInterface;
|
|
284
|
+
|
|
285
|
+
const config = new ModalConfig();
|
|
286
|
+
config.closeOnBackdropClick = false;
|
|
287
|
+
el.showModal({ config });
|
|
288
|
+
await elementUpdated(el);
|
|
289
|
+
|
|
290
|
+
const backdrop = el.shadowRoot?.querySelector('.backdrop');
|
|
291
|
+
const clickEvent = new MouseEvent('click');
|
|
292
|
+
backdrop?.dispatchEvent(clickEvent);
|
|
293
|
+
|
|
294
|
+
await elementUpdated(el);
|
|
295
|
+
|
|
296
|
+
expect(el.getMode()).to.equal('open');
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
test('ia logo should not visible on modal', async () => {
|
|
300
|
+
const el = (await fixture(html`
|
|
301
|
+
<modal-manager></modal-manager>
|
|
302
|
+
`)) as ModalManagerInterface;
|
|
303
|
+
|
|
304
|
+
const config = new ModalConfig();
|
|
305
|
+
config.showHeaderLogo = false;
|
|
306
|
+
el.showModal({ config });
|
|
307
|
+
await elementUpdated(el);
|
|
308
|
+
|
|
309
|
+
const logoIcon = el.shadowRoot?.querySelector('.logo-icon');
|
|
310
|
+
expect(logoIcon).to.not.exist;
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
test('should trap Tab key', async () => {
|
|
314
|
+
const el = (await fixture(html`
|
|
315
|
+
<modal-manager></modal-manager>
|
|
316
|
+
`)) as ModalManager;
|
|
317
|
+
|
|
318
|
+
const config = new ModalConfig();
|
|
319
|
+
el.showModal({ config });
|
|
320
|
+
await elementUpdated(el);
|
|
321
|
+
|
|
322
|
+
expect(el.mode).to.equal('open');
|
|
323
|
+
|
|
324
|
+
// Tab once to focus
|
|
325
|
+
const tabEvent = new KeyboardEvent('keydown', { key: 'Tab' });
|
|
326
|
+
document.dispatchEvent(tabEvent);
|
|
327
|
+
await elementUpdated(el);
|
|
328
|
+
await nextFrame();
|
|
329
|
+
|
|
330
|
+
// Should be only one tabbable element
|
|
331
|
+
const modal = el.shadowRoot?.querySelector('modal-template') as HTMLElement;
|
|
332
|
+
const tabbableElements = getTabbableElements(modal);
|
|
333
|
+
expect(tabbableElements?.length).to.equal(1);
|
|
334
|
+
|
|
335
|
+
const closeButton = modal?.shadowRoot?.querySelector(
|
|
336
|
+
'.close-button',
|
|
337
|
+
) as HTMLElement;
|
|
338
|
+
expect(modal?.shadowRoot?.activeElement).to.equal(closeButton);
|
|
339
|
+
|
|
340
|
+
// Tab again
|
|
341
|
+
el.dispatchEvent(tabEvent);
|
|
342
|
+
await elementUpdated(el);
|
|
343
|
+
await nextFrame();
|
|
344
|
+
|
|
345
|
+
// Should be only one tabbable element
|
|
346
|
+
expect(modal?.shadowRoot?.activeElement).to.equal(closeButton);
|
|
347
|
+
|
|
348
|
+
// Shift + Tab
|
|
349
|
+
const shiftTabEvent = new KeyboardEvent('keydown', {
|
|
350
|
+
key: 'Tab',
|
|
351
|
+
shiftKey: true,
|
|
352
|
+
});
|
|
353
|
+
document.dispatchEvent(shiftTabEvent);
|
|
354
|
+
await elementUpdated(el);
|
|
355
|
+
await nextFrame();
|
|
356
|
+
|
|
357
|
+
// Should be only one tabbable element
|
|
358
|
+
expect(modal?.shadowRoot?.activeElement).to.equal(closeButton);
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
test('returns keyboard focus to the triggering element on close', async () => {
|
|
362
|
+
const config = new ModalConfig();
|
|
363
|
+
const el = (await fixture(html`
|
|
364
|
+
<div>
|
|
365
|
+
<button>Another button</button>
|
|
366
|
+
<button
|
|
367
|
+
id="open-modal-btn"
|
|
368
|
+
@click=${() => {
|
|
369
|
+
const modal = el.querySelector('modal-manager') as ModalManager;
|
|
370
|
+
modal.showModal({ config });
|
|
371
|
+
}}
|
|
372
|
+
>
|
|
373
|
+
Open modal
|
|
374
|
+
</button>
|
|
375
|
+
<modal-manager></modal-manager>
|
|
376
|
+
</div>
|
|
377
|
+
`)) as HTMLDivElement;
|
|
378
|
+
|
|
379
|
+
const openBtn = el.querySelector('#open-modal-btn') as HTMLButtonElement;
|
|
380
|
+
const modal = el.querySelector('modal-manager') as ModalManager;
|
|
381
|
+
|
|
382
|
+
// Focus is initially on the Open button
|
|
383
|
+
openBtn.focus();
|
|
384
|
+
expect(document.activeElement).to.equal(openBtn);
|
|
385
|
+
|
|
386
|
+
// Focus enters the modal when it is opened
|
|
387
|
+
openBtn.click();
|
|
388
|
+
await nextFrame();
|
|
389
|
+
expect(document.activeElement).to.equal(modal);
|
|
390
|
+
|
|
391
|
+
// With the modal already open, simulate showing different content.
|
|
392
|
+
// This step is to ensure that even if showModal is called multiple times, we still
|
|
393
|
+
// maintain the originally-focused element (subsequent calls do not overwrite it).
|
|
394
|
+
modal.showModal({ config: new ModalConfig() });
|
|
395
|
+
await nextFrame();
|
|
396
|
+
|
|
397
|
+
// Focus returns to the Open button when the modal closes
|
|
398
|
+
modal.closeModal();
|
|
399
|
+
await modal.updateComplete;
|
|
400
|
+
expect(document.activeElement).to.equal(openBtn);
|
|
401
|
+
});
|
|
402
|
+
});
|