@internetarchive/modal-manager 2.0.4-alpha-webdev7960.0 → 2.0.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.
Files changed (42) hide show
  1. package/dist/index.js.map +1 -1
  2. package/dist/src/assets/arrow-left-icon.js +12 -12
  3. package/dist/src/assets/arrow-left-icon.js.map +1 -1
  4. package/dist/src/assets/ia-logo-icon.js +27 -27
  5. package/dist/src/assets/ia-logo-icon.js.map +1 -1
  6. package/dist/src/modal-config.js.map +1 -1
  7. package/dist/src/modal-manager-host-bridge-interface.js.map +1 -1
  8. package/dist/src/modal-manager-host-bridge.js.map +1 -1
  9. package/dist/src/modal-manager-interface.js.map +1 -1
  10. package/dist/src/modal-manager-mode.js.map +1 -1
  11. package/dist/src/modal-manager.d.ts +1 -1
  12. package/dist/src/modal-manager.js +4 -2
  13. package/dist/src/modal-manager.js.map +1 -1
  14. package/dist/src/modal-template.js +220 -220
  15. package/dist/src/modal-template.js.map +1 -1
  16. package/dist/src/shoelace/active-elements.js.map +1 -1
  17. package/dist/src/shoelace/modal.js.map +1 -1
  18. package/dist/src/shoelace/tabbable.js.map +1 -1
  19. package/dist/test/modal-config.test.js.map +1 -1
  20. package/dist/test/modal-manager.test.js +41 -6
  21. package/dist/test/modal-manager.test.js.map +1 -1
  22. package/dist/test/modal-template.test.js +22 -22
  23. package/dist/test/modal-template.test.js.map +1 -1
  24. package/dist/vite.config.js.map +1 -1
  25. package/index.ts +7 -7
  26. package/package.json +1 -1
  27. package/src/assets/arrow-left-icon.ts +15 -15
  28. package/src/assets/ia-logo-icon.ts +30 -30
  29. package/src/modal-config.ts +133 -133
  30. package/src/modal-manager-host-bridge-interface.ts +13 -13
  31. package/src/modal-manager-host-bridge.ts +82 -82
  32. package/src/modal-manager-interface.ts +30 -30
  33. package/src/modal-manager-mode.ts +10 -10
  34. package/src/modal-manager.ts +5 -3
  35. package/src/modal-template.ts +343 -343
  36. package/src/shoelace/active-elements.ts +33 -33
  37. package/src/shoelace/modal.ts +166 -166
  38. package/src/shoelace/tabbable.ts +223 -223
  39. package/test/modal-config.test.ts +77 -77
  40. package/test/modal-manager.test.ts +52 -6
  41. package/test/modal-template.test.ts +206 -206
  42. package/vite.config.ts +23 -23
@@ -1,4 +1,10 @@
1
- import { fixture, expect, oneEvent, elementUpdated } from '@open-wc/testing';
1
+ import {
2
+ fixture,
3
+ expect,
4
+ oneEvent,
5
+ elementUpdated,
6
+ nextFrame,
7
+ } from '@open-wc/testing';
2
8
  import { TemplateResult, html } from 'lit';
3
9
 
4
10
  import '../src/modal-manager';
@@ -322,16 +328,14 @@ describe('Modal Manager', () => {
322
328
  const closeButton = modal?.shadowRoot?.querySelector(
323
329
  '.close-button'
324
330
  ) as HTMLElement;
325
- const activeElement = modal?.shadowRoot?.activeElement as HTMLElement;
326
-
327
- expect(activeElement).to.equal(closeButton);
331
+ expect(modal?.shadowRoot?.activeElement).to.equal(closeButton);
328
332
 
329
333
  // Tab again
330
334
  el.dispatchEvent(tabEvent);
331
335
  await elementUpdated(el);
332
336
 
333
337
  // Should be only one tabbable element
334
- expect(activeElement).to.equal(closeButton);
338
+ expect(modal?.shadowRoot?.activeElement).to.equal(closeButton);
335
339
 
336
340
  // Shift + Tab
337
341
  const shiftTabEvent = new KeyboardEvent('keydown', {
@@ -342,6 +346,48 @@ describe('Modal Manager', () => {
342
346
  await elementUpdated(el);
343
347
 
344
348
  // Should be only one tabbable element
345
- expect(activeElement).to.equal(closeButton);
349
+ expect(modal?.shadowRoot?.activeElement).to.equal(closeButton);
350
+ });
351
+
352
+ it('returns keyboard focus to the triggering element on close', async () => {
353
+ const config = new ModalConfig();
354
+ const el = (await fixture(html`
355
+ <div>
356
+ <button>Another button</button>
357
+ <button
358
+ id="open-modal-btn"
359
+ @click=${() => {
360
+ const modal = el.querySelector('modal-manager') as ModalManager;
361
+ modal.showModal({ config });
362
+ }}
363
+ >
364
+ Open modal
365
+ </button>
366
+ <modal-manager></modal-manager>
367
+ </div>
368
+ `)) as HTMLDivElement;
369
+
370
+ const openBtn = el.querySelector('#open-modal-btn') as HTMLButtonElement;
371
+ const modal = el.querySelector('modal-manager') as ModalManager;
372
+
373
+ // Focus is initially on the Open button
374
+ openBtn.focus();
375
+ expect(document.activeElement).to.equal(openBtn);
376
+
377
+ // Focus enters the modal when it is opened
378
+ openBtn.click();
379
+ await nextFrame();
380
+ expect(document.activeElement).to.equal(modal);
381
+
382
+ // With the modal already open, simulate showing different content.
383
+ // This step is to ensure that even if showModal is called multiple times, we still
384
+ // maintain the originally-focused element (subsequent calls do not overwrite it).
385
+ modal.showModal({ config: new ModalConfig() });
386
+ await nextFrame();
387
+
388
+ // Focus returns to the Open button when the modal closes
389
+ modal.closeModal();
390
+ await modal.updateComplete;
391
+ expect(document.activeElement).to.equal(openBtn);
346
392
  });
347
393
  });
@@ -1,206 +1,206 @@
1
- import { fixture, expect, oneEvent } from '@open-wc/testing';
2
- import { html } from 'lit';
3
- import '../src/modal-template';
4
- import { ModalConfig } from '../src/modal-config';
5
-
6
- describe('Modal Template', () => {
7
- it('has correct default configuration', async () => {
8
- const el = await fixture(html` <modal-template></modal-template> `);
9
-
10
- const processingLogo = el.shadowRoot?.querySelector('.processing-logo');
11
- const headline = el.shadowRoot?.querySelector('.headline');
12
- const message = el.shadowRoot?.querySelector('.message');
13
- const title = el.shadowRoot?.querySelector('h1.title') as HTMLElement;
14
-
15
- expect(headline).to.not.exist;
16
- expect(message).to.not.exist;
17
- expect(title).to.not.exist;
18
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
19
- expect('hidden' in processingLogo!.classList);
20
- });
21
-
22
- it('does not show the title if one not provided', async () => {
23
- const config = new ModalConfig();
24
- config.title = undefined;
25
-
26
- const el = await fixture(html`
27
- <modal-template .config=${config}></modal-template>
28
- `);
29
-
30
- const title = el.shadowRoot?.querySelector('h1.title');
31
- expect(title).to.not.exist;
32
- });
33
-
34
- it('emits closeButtonPressed event when close button is pressed', async () => {
35
- const el = await fixture(html` <modal-template></modal-template> `);
36
-
37
- const closeButton = el.shadowRoot?.querySelector('.close-button');
38
- const clickEvent = new MouseEvent('click');
39
-
40
- setTimeout(() => {
41
- closeButton?.dispatchEvent(clickEvent);
42
- });
43
- const response = await oneEvent(el, 'closeButtonPressed', false);
44
- expect(response).to.exist;
45
- });
46
-
47
- it('emits closeButtonPressed event when close button gets spacebar pressed', async () => {
48
- const el = await fixture(html` <modal-template></modal-template> `);
49
-
50
- const closeButton = el.shadowRoot?.querySelector('.close-button');
51
- const clickEvent = new KeyboardEvent('keydown', { key: ' ' });
52
-
53
- setTimeout(() => {
54
- closeButton?.dispatchEvent(clickEvent);
55
- });
56
- const response = await oneEvent(el, 'closeButtonPressed', false);
57
- expect(response).to.exist;
58
- });
59
-
60
- it('emits leftNavButtonPressed event when left nav button is pressed', async () => {
61
- const config = new ModalConfig();
62
- config.showLeftNavButton = true;
63
- const el = await fixture(html`
64
- <modal-template .config=${config}></modal-template>
65
- `);
66
-
67
- const leftNavButton = el.shadowRoot?.querySelector('.back-button');
68
- const clickEvent = new MouseEvent('click');
69
-
70
- setTimeout(() => {
71
- leftNavButton?.dispatchEvent(clickEvent);
72
- });
73
- const response = await oneEvent(el, 'leftNavButtonPressed', false);
74
- expect(response).to.exist;
75
- });
76
-
77
- it('emits leftNavButtonPressed event when left nav button gets spacebar pressed', async () => {
78
- const config = new ModalConfig();
79
- config.showLeftNavButton = true;
80
- const el = await fixture(html`
81
- <modal-template .config=${config}></modal-template>
82
- `);
83
-
84
- const leftNavButton = el.shadowRoot?.querySelector('.back-button');
85
- const clickEvent = new KeyboardEvent('keydown', { key: ' ' });
86
-
87
- setTimeout(() => {
88
- leftNavButton?.dispatchEvent(clickEvent);
89
- });
90
- const response = await oneEvent(el, 'leftNavButtonPressed', false);
91
- expect(response).to.exist;
92
- });
93
-
94
- it('shows the processing indicator if configured to', async () => {
95
- const config = new ModalConfig();
96
- config.showProcessingIndicator = true;
97
-
98
- const el = await fixture(html`
99
- <modal-template .config=${config}></modal-template>
100
- `);
101
-
102
- const processingLogo = el.shadowRoot?.querySelector('.processing-logo');
103
- const classList = processingLogo?.classList ?? [];
104
- expect('hidden' in classList).to.equal(false);
105
- });
106
-
107
- it('shows the left nav button if configured to', async () => {
108
- const config = new ModalConfig();
109
- config.showLeftNavButton = true;
110
- const el = await fixture(html`
111
- <modal-template .config=${config}></modal-template>
112
- `);
113
-
114
- const leftNavButton = el.shadowRoot?.querySelector('.back-button');
115
- expect(leftNavButton).to.exist;
116
- });
117
-
118
- it('hides the left nav button if configured to', async () => {
119
- const config = new ModalConfig();
120
- config.showCloseButton = false;
121
- const el = await fixture(html`
122
- <modal-template .config=${config}></modal-template>
123
- `);
124
-
125
- const closeButton = el.shadowRoot?.querySelector('.close-button');
126
- expect(closeButton).to.not.exist;
127
- });
128
-
129
- it('uses custom text for the left nav button if configured to', async () => {
130
- const config = new ModalConfig();
131
- config.showLeftNavButton = true;
132
- config.leftNavButtonText = 'Previous';
133
- const el = await fixture(html`
134
- <modal-template .config=${config}></modal-template>
135
- `);
136
-
137
- const leftNavButton = el.shadowRoot?.querySelector('.back-button');
138
-
139
- expect(leftNavButton).to.exist;
140
- expect(leftNavButton?.innerHTML).to.contain('Previous');
141
- });
142
-
143
- it('does not use any text for the left nav button if not configured to', async () => {
144
- const config = new ModalConfig();
145
- config.showLeftNavButton = true;
146
-
147
- const el = await fixture(html`
148
- <modal-template .config=${config}></modal-template>
149
- `);
150
-
151
- const leftNavButton = el.shadowRoot?.querySelector('.back-button');
152
- expect(leftNavButton?.innerHTML).not.to.contain('Previous');
153
- });
154
-
155
- it('shows the close button if configured to', async () => {
156
- const config = new ModalConfig();
157
- config.showCloseButton = true;
158
- const el = await fixture(html`
159
- <modal-template .config=${config}></modal-template>
160
- `);
161
-
162
- const closeButton = el.shadowRoot?.querySelector('.close-button');
163
- expect(closeButton).to.exist;
164
- });
165
-
166
- it('hides the close button if configured to', async () => {
167
- const config = new ModalConfig();
168
- config.showCloseButton = false;
169
- const el = await fixture(html`
170
- <modal-template .config=${config}></modal-template>
171
- `);
172
-
173
- const closeButton = el.shadowRoot?.querySelector('.close-button');
174
- expect(closeButton).to.not.exist;
175
- });
176
-
177
- it('shows the properties from the config', async () => {
178
- const config = new ModalConfig();
179
- config.title = html`Boop`;
180
- config.subtitle = html`Bop`;
181
- config.headline = html`Foo`;
182
- config.message = html`Bar`;
183
-
184
- const el = await fixture(html`
185
- <modal-template .config=${config}></modal-template>
186
- `);
187
-
188
- const title = el.shadowRoot?.querySelector('h1');
189
- const subtitle = el.shadowRoot?.querySelector('h2');
190
-
191
- const headline = el.shadowRoot?.querySelector('.headline');
192
- const message = el.shadowRoot?.querySelector('.message');
193
-
194
- expect(title).to.exist;
195
- expect(title?.innerText).to.equal('Boop');
196
-
197
- expect(subtitle).to.exist;
198
- expect(subtitle?.innerText).to.equal('Bop');
199
-
200
- expect(headline).to.exist;
201
- expect(headline?.textContent).to.equal('Foo');
202
-
203
- expect(message).to.exist;
204
- expect(message?.textContent).to.equal('Bar');
205
- });
206
- });
1
+ import { fixture, expect, oneEvent } from '@open-wc/testing';
2
+ import { html } from 'lit';
3
+ import '../src/modal-template';
4
+ import { ModalConfig } from '../src/modal-config';
5
+
6
+ describe('Modal Template', () => {
7
+ it('has correct default configuration', async () => {
8
+ const el = await fixture(html` <modal-template></modal-template> `);
9
+
10
+ const processingLogo = el.shadowRoot?.querySelector('.processing-logo');
11
+ const headline = el.shadowRoot?.querySelector('.headline');
12
+ const message = el.shadowRoot?.querySelector('.message');
13
+ const title = el.shadowRoot?.querySelector('h1.title') as HTMLElement;
14
+
15
+ expect(headline).to.not.exist;
16
+ expect(message).to.not.exist;
17
+ expect(title).to.not.exist;
18
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
19
+ expect('hidden' in processingLogo!.classList);
20
+ });
21
+
22
+ it('does not show the title if one not provided', async () => {
23
+ const config = new ModalConfig();
24
+ config.title = undefined;
25
+
26
+ const el = await fixture(html`
27
+ <modal-template .config=${config}></modal-template>
28
+ `);
29
+
30
+ const title = el.shadowRoot?.querySelector('h1.title');
31
+ expect(title).to.not.exist;
32
+ });
33
+
34
+ it('emits closeButtonPressed event when close button is pressed', async () => {
35
+ const el = await fixture(html` <modal-template></modal-template> `);
36
+
37
+ const closeButton = el.shadowRoot?.querySelector('.close-button');
38
+ const clickEvent = new MouseEvent('click');
39
+
40
+ setTimeout(() => {
41
+ closeButton?.dispatchEvent(clickEvent);
42
+ });
43
+ const response = await oneEvent(el, 'closeButtonPressed', false);
44
+ expect(response).to.exist;
45
+ });
46
+
47
+ it('emits closeButtonPressed event when close button gets spacebar pressed', async () => {
48
+ const el = await fixture(html` <modal-template></modal-template> `);
49
+
50
+ const closeButton = el.shadowRoot?.querySelector('.close-button');
51
+ const clickEvent = new KeyboardEvent('keydown', { key: ' ' });
52
+
53
+ setTimeout(() => {
54
+ closeButton?.dispatchEvent(clickEvent);
55
+ });
56
+ const response = await oneEvent(el, 'closeButtonPressed', false);
57
+ expect(response).to.exist;
58
+ });
59
+
60
+ it('emits leftNavButtonPressed event when left nav button is pressed', async () => {
61
+ const config = new ModalConfig();
62
+ config.showLeftNavButton = true;
63
+ const el = await fixture(html`
64
+ <modal-template .config=${config}></modal-template>
65
+ `);
66
+
67
+ const leftNavButton = el.shadowRoot?.querySelector('.back-button');
68
+ const clickEvent = new MouseEvent('click');
69
+
70
+ setTimeout(() => {
71
+ leftNavButton?.dispatchEvent(clickEvent);
72
+ });
73
+ const response = await oneEvent(el, 'leftNavButtonPressed', false);
74
+ expect(response).to.exist;
75
+ });
76
+
77
+ it('emits leftNavButtonPressed event when left nav button gets spacebar pressed', async () => {
78
+ const config = new ModalConfig();
79
+ config.showLeftNavButton = true;
80
+ const el = await fixture(html`
81
+ <modal-template .config=${config}></modal-template>
82
+ `);
83
+
84
+ const leftNavButton = el.shadowRoot?.querySelector('.back-button');
85
+ const clickEvent = new KeyboardEvent('keydown', { key: ' ' });
86
+
87
+ setTimeout(() => {
88
+ leftNavButton?.dispatchEvent(clickEvent);
89
+ });
90
+ const response = await oneEvent(el, 'leftNavButtonPressed', false);
91
+ expect(response).to.exist;
92
+ });
93
+
94
+ it('shows the processing indicator if configured to', async () => {
95
+ const config = new ModalConfig();
96
+ config.showProcessingIndicator = true;
97
+
98
+ const el = await fixture(html`
99
+ <modal-template .config=${config}></modal-template>
100
+ `);
101
+
102
+ const processingLogo = el.shadowRoot?.querySelector('.processing-logo');
103
+ const classList = processingLogo?.classList ?? [];
104
+ expect('hidden' in classList).to.equal(false);
105
+ });
106
+
107
+ it('shows the left nav button if configured to', async () => {
108
+ const config = new ModalConfig();
109
+ config.showLeftNavButton = true;
110
+ const el = await fixture(html`
111
+ <modal-template .config=${config}></modal-template>
112
+ `);
113
+
114
+ const leftNavButton = el.shadowRoot?.querySelector('.back-button');
115
+ expect(leftNavButton).to.exist;
116
+ });
117
+
118
+ it('hides the left nav button if configured to', async () => {
119
+ const config = new ModalConfig();
120
+ config.showCloseButton = false;
121
+ const el = await fixture(html`
122
+ <modal-template .config=${config}></modal-template>
123
+ `);
124
+
125
+ const closeButton = el.shadowRoot?.querySelector('.close-button');
126
+ expect(closeButton).to.not.exist;
127
+ });
128
+
129
+ it('uses custom text for the left nav button if configured to', async () => {
130
+ const config = new ModalConfig();
131
+ config.showLeftNavButton = true;
132
+ config.leftNavButtonText = 'Previous';
133
+ const el = await fixture(html`
134
+ <modal-template .config=${config}></modal-template>
135
+ `);
136
+
137
+ const leftNavButton = el.shadowRoot?.querySelector('.back-button');
138
+
139
+ expect(leftNavButton).to.exist;
140
+ expect(leftNavButton?.innerHTML).to.contain('Previous');
141
+ });
142
+
143
+ it('does not use any text for the left nav button if not configured to', async () => {
144
+ const config = new ModalConfig();
145
+ config.showLeftNavButton = true;
146
+
147
+ const el = await fixture(html`
148
+ <modal-template .config=${config}></modal-template>
149
+ `);
150
+
151
+ const leftNavButton = el.shadowRoot?.querySelector('.back-button');
152
+ expect(leftNavButton?.innerHTML).not.to.contain('Previous');
153
+ });
154
+
155
+ it('shows the close button if configured to', async () => {
156
+ const config = new ModalConfig();
157
+ config.showCloseButton = true;
158
+ const el = await fixture(html`
159
+ <modal-template .config=${config}></modal-template>
160
+ `);
161
+
162
+ const closeButton = el.shadowRoot?.querySelector('.close-button');
163
+ expect(closeButton).to.exist;
164
+ });
165
+
166
+ it('hides the close button if configured to', async () => {
167
+ const config = new ModalConfig();
168
+ config.showCloseButton = false;
169
+ const el = await fixture(html`
170
+ <modal-template .config=${config}></modal-template>
171
+ `);
172
+
173
+ const closeButton = el.shadowRoot?.querySelector('.close-button');
174
+ expect(closeButton).to.not.exist;
175
+ });
176
+
177
+ it('shows the properties from the config', async () => {
178
+ const config = new ModalConfig();
179
+ config.title = html`Boop`;
180
+ config.subtitle = html`Bop`;
181
+ config.headline = html`Foo`;
182
+ config.message = html`Bar`;
183
+
184
+ const el = await fixture(html`
185
+ <modal-template .config=${config}></modal-template>
186
+ `);
187
+
188
+ const title = el.shadowRoot?.querySelector('h1');
189
+ const subtitle = el.shadowRoot?.querySelector('h2');
190
+
191
+ const headline = el.shadowRoot?.querySelector('.headline');
192
+ const message = el.shadowRoot?.querySelector('.message');
193
+
194
+ expect(title).to.exist;
195
+ expect(title?.innerText).to.equal('Boop');
196
+
197
+ expect(subtitle).to.exist;
198
+ expect(subtitle?.innerText).to.equal('Bop');
199
+
200
+ expect(headline).to.exist;
201
+ expect(headline?.textContent).to.equal('Foo');
202
+
203
+ expect(message).to.exist;
204
+ expect(message?.textContent).to.equal('Bar');
205
+ });
206
+ });
package/vite.config.ts CHANGED
@@ -1,23 +1,23 @@
1
- import { defineConfig } from 'vite';
2
- import { resolve } from 'path';
3
-
4
- // https://vitejs.dev/config/
5
- export default defineConfig({
6
- base: '',
7
- assetsInclude: ['**/*.jpg'],
8
- build: {
9
- outDir: 'ghpages',
10
- manifest: true,
11
- rollupOptions: {
12
- input: {
13
- main: resolve(__dirname, 'index.html'),
14
- },
15
- },
16
- },
17
- server: {
18
- host: true,
19
- port: 8080,
20
- open: true,
21
- cors: true,
22
- },
23
- });
1
+ import { defineConfig } from 'vite';
2
+ import { resolve } from 'path';
3
+
4
+ // https://vitejs.dev/config/
5
+ export default defineConfig({
6
+ base: '',
7
+ assetsInclude: ['**/*.jpg'],
8
+ build: {
9
+ outDir: 'ghpages',
10
+ manifest: true,
11
+ rollupOptions: {
12
+ input: {
13
+ main: resolve(__dirname, 'index.html'),
14
+ },
15
+ },
16
+ },
17
+ server: {
18
+ host: true,
19
+ port: 8080,
20
+ open: true,
21
+ cors: true,
22
+ },
23
+ });