@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,30 +1,30 @@
1
- import { html } from 'lit';
2
-
3
- export default html`
4
- <svg
5
- class="ia-logo"
6
- viewBox="0 0 27 30"
7
- xmlns="http://www.w3.org/2000/svg"
8
- aria-labelledby="logoTitleID logoDescID"
9
- >
10
- <title id="logoTitleID">Internet Archive logo</title>
11
- <desc id="logoDescID">
12
- A line drawing of the Internet Archive headquarters building façade.
13
- </desc>
14
- <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
15
- <mask id="mask-2" class="fill-color">
16
- <path
17
- d="M26.6666667,28.6046512 L26.6666667,30 L0,30 L0.000283687943,28.6046512 L26.6666667,28.6046512 Z M25.6140351,26.5116279 L25.6140351,28.255814 L1.05263158,28.255814 L1.05263158,26.5116279 L25.6140351,26.5116279 Z M3.62469203,7.6744186 L3.91746909,7.82153285 L4.0639977,10.1739544 L4.21052632,13.9963932 L4.21052632,17.6725617 L4.0639977,22.255044 L4.03962296,25.3421929 L3.62469203,25.4651163 L2.16024641,25.4651163 L1.72094074,25.3421929 L1.55031755,22.255044 L1.40350877,17.6970339 L1.40350877,14.0211467 L1.55031755,10.1739544 L1.68423854,7.80887484 L1.98962322,7.6744186 L3.62469203,7.6744186 Z M24.6774869,7.6744186 L24.9706026,7.82153285 L25.1168803,10.1739544 L25.2631579,13.9963932 L25.2631579,17.6725617 L25.1168803,22.255044 L25.0927809,25.3421929 L24.6774869,25.4651163 L23.2130291,25.4651163 L22.7736357,25.3421929 L22.602418,22.255044 L22.4561404,17.6970339 L22.4561404,14.0211467 L22.602418,10.1739544 L22.7369262,7.80887484 L23.0420916,7.6744186 L24.6774869,7.6744186 Z M9.94042303,7.6744186 L10.2332293,7.82153285 L10.3797725,10.1739544 L10.5263158,13.9963932 L10.5263158,17.6725617 L10.3797725,22.255044 L10.3556756,25.3421929 L9.94042303,25.4651163 L8.47583122,25.4651163 L8.0362015,25.3421929 L7.86556129,22.255044 L7.71929825,17.6970339 L7.71929825,14.0211467 L7.86556129,10.1739544 L8.00005604,7.80887484 L8.30491081,7.6744186 L9.94042303,7.6744186 Z M18.0105985,7.6744186 L18.3034047,7.82153285 L18.449948,10.1739544 L18.5964912,13.9963932 L18.5964912,17.6725617 L18.449948,22.255044 L18.425851,25.3421929 L18.0105985,25.4651163 L16.5460067,25.4651163 L16.1066571,25.3421929 L15.9357367,22.255044 L15.7894737,17.6970339 L15.7894737,14.0211467 L15.9357367,10.1739544 L16.0702315,7.80887484 L16.3753664,7.6744186 L18.0105985,7.6744186 Z M25.6140351,4.53488372 L25.6140351,6.97674419 L1.05263158,6.97674419 L1.05263158,4.53488372 L25.6140351,4.53488372 Z M13.0806755,0 L25.9649123,2.93331338 L25.4484139,3.8372093 L0.771925248,3.8372093 L0,3.1041615 L13.0806755,0 Z"
18
- id="path-1"
19
- ></path>
20
- </mask>
21
- <use class="fill-color" xlink:href="#path-1"></use>
22
- <g mask="url(#mask-2)" class="fill-color">
23
- <path
24
- d="M0,0 L26.6666667,0 L26.6666667,30 L0,30 L0,0 Z"
25
- id="swatch"
26
- ></path>
27
- </g>
28
- </g>
29
- </svg>
30
- `;
1
+ import { html } from 'lit';
2
+
3
+ export default html`
4
+ <svg
5
+ class="ia-logo"
6
+ viewBox="0 0 27 30"
7
+ xmlns="http://www.w3.org/2000/svg"
8
+ aria-labelledby="logoTitleID logoDescID"
9
+ >
10
+ <title id="logoTitleID">Internet Archive logo</title>
11
+ <desc id="logoDescID">
12
+ A line drawing of the Internet Archive headquarters building façade.
13
+ </desc>
14
+ <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
15
+ <mask id="mask-2" class="fill-color">
16
+ <path
17
+ d="M26.6666667,28.6046512 L26.6666667,30 L0,30 L0.000283687943,28.6046512 L26.6666667,28.6046512 Z M25.6140351,26.5116279 L25.6140351,28.255814 L1.05263158,28.255814 L1.05263158,26.5116279 L25.6140351,26.5116279 Z M3.62469203,7.6744186 L3.91746909,7.82153285 L4.0639977,10.1739544 L4.21052632,13.9963932 L4.21052632,17.6725617 L4.0639977,22.255044 L4.03962296,25.3421929 L3.62469203,25.4651163 L2.16024641,25.4651163 L1.72094074,25.3421929 L1.55031755,22.255044 L1.40350877,17.6970339 L1.40350877,14.0211467 L1.55031755,10.1739544 L1.68423854,7.80887484 L1.98962322,7.6744186 L3.62469203,7.6744186 Z M24.6774869,7.6744186 L24.9706026,7.82153285 L25.1168803,10.1739544 L25.2631579,13.9963932 L25.2631579,17.6725617 L25.1168803,22.255044 L25.0927809,25.3421929 L24.6774869,25.4651163 L23.2130291,25.4651163 L22.7736357,25.3421929 L22.602418,22.255044 L22.4561404,17.6970339 L22.4561404,14.0211467 L22.602418,10.1739544 L22.7369262,7.80887484 L23.0420916,7.6744186 L24.6774869,7.6744186 Z M9.94042303,7.6744186 L10.2332293,7.82153285 L10.3797725,10.1739544 L10.5263158,13.9963932 L10.5263158,17.6725617 L10.3797725,22.255044 L10.3556756,25.3421929 L9.94042303,25.4651163 L8.47583122,25.4651163 L8.0362015,25.3421929 L7.86556129,22.255044 L7.71929825,17.6970339 L7.71929825,14.0211467 L7.86556129,10.1739544 L8.00005604,7.80887484 L8.30491081,7.6744186 L9.94042303,7.6744186 Z M18.0105985,7.6744186 L18.3034047,7.82153285 L18.449948,10.1739544 L18.5964912,13.9963932 L18.5964912,17.6725617 L18.449948,22.255044 L18.425851,25.3421929 L18.0105985,25.4651163 L16.5460067,25.4651163 L16.1066571,25.3421929 L15.9357367,22.255044 L15.7894737,17.6970339 L15.7894737,14.0211467 L15.9357367,10.1739544 L16.0702315,7.80887484 L16.3753664,7.6744186 L18.0105985,7.6744186 Z M25.6140351,4.53488372 L25.6140351,6.97674419 L1.05263158,6.97674419 L1.05263158,4.53488372 L25.6140351,4.53488372 Z M13.0806755,0 L25.9649123,2.93331338 L25.4484139,3.8372093 L0.771925248,3.8372093 L0,3.1041615 L13.0806755,0 Z"
18
+ id="path-1"
19
+ ></path>
20
+ </mask>
21
+ <use class="fill-color" xlink:href="#path-1"></use>
22
+ <g mask="url(#mask-2)" class="fill-color">
23
+ <path
24
+ d="M0,0 L26.6666667,0 L26.6666667,30 L0,30 L0,0 Z"
25
+ id="swatch"
26
+ ></path>
27
+ </g>
28
+ </g>
29
+ </svg>
30
+ `;
@@ -1,133 +1,133 @@
1
- import { TemplateResult } from 'lit';
2
-
3
- /**
4
- * Configuration to show a modal
5
- *
6
- * @export
7
- * @class ModalConfig
8
- */
9
- export class ModalConfig {
10
- /**
11
- * The title that shows in the header
12
- *
13
- * @type {(TemplateResult | undefined)}
14
- * @memberof ModalConfig
15
- */
16
- title?: TemplateResult;
17
-
18
- /**
19
- * The subtitle shown in the header under the title
20
- *
21
- * @type {(TemplateResult | undefined)}
22
- * @memberof ModalConfig
23
- */
24
- subtitle?: TemplateResult;
25
-
26
- /**
27
- * The headline shown at the top of the content section
28
- *
29
- * @type {(TemplateResult | undefined)}
30
- * @memberof ModalConfig
31
- */
32
- headline?: TemplateResult;
33
-
34
- /**
35
- * The text shown below the headline in the content section
36
- *
37
- * @type {(TemplateResult | undefined)}
38
- * @memberof ModalConfig
39
- */
40
- message?: TemplateResult;
41
-
42
- /**
43
- * The background color of the header
44
- *
45
- * @memberof ModalConfig
46
- */
47
- headerColor: string;
48
-
49
- /**
50
- * The background color of the body
51
- *
52
- * @memberof ModalConfig
53
- */
54
- bodyColor: string;
55
-
56
- /**
57
- * Show or hide the processing indicator
58
- *
59
- * @memberof ModalConfig
60
- */
61
- showProcessingIndicator: boolean;
62
-
63
- /**
64
- * Set the processing image mode, currently `processing` or `complete`
65
- *
66
- * @memberof ModalConfig
67
- */
68
- processingImageMode: 'processing' | 'complete';
69
-
70
- /**
71
- * Show the close button
72
- *
73
- * @memberof ModalConfig
74
- */
75
- showCloseButton: boolean;
76
-
77
- /**
78
- * Show the left nav button
79
- *
80
- * @memberof ModalConfig
81
- */
82
- showLeftNavButton: boolean;
83
-
84
- /**
85
- * Left nav button text
86
- */
87
- leftNavButtonText: string;
88
-
89
- /**
90
- * Show the close button
91
- *
92
- * @memberof ModalConfig
93
- */
94
- showHeaderLogo: boolean;
95
-
96
- /**
97
- * Close the modal if the user taps on the background
98
- *
99
- * @memberof ModalConfig
100
- */
101
- closeOnBackdropClick: boolean;
102
-
103
- constructor(options?: {
104
- title?: TemplateResult;
105
- subtitle?: TemplateResult;
106
- headline?: TemplateResult;
107
- message?: TemplateResult;
108
- headerColor?: string;
109
- bodyColor?: string;
110
- showProcessingIndicator?: boolean;
111
- processingImageMode?: 'processing' | 'complete';
112
- showCloseButton?: boolean;
113
- showLeftNavButton?: boolean;
114
- leftNavButtonText?: string;
115
- showHeaderLogo?: boolean;
116
- closeOnBackdropClick?: boolean;
117
- }) {
118
- this.title = options?.title;
119
- this.subtitle = options?.subtitle;
120
- this.headline = options?.headline;
121
- this.message = options?.message;
122
-
123
- this.headerColor = options?.headerColor ?? '#55A183';
124
- this.bodyColor = options?.bodyColor ?? '#fbfbfd';
125
- this.showProcessingIndicator = options?.showProcessingIndicator ?? false;
126
- this.processingImageMode = options?.processingImageMode ?? 'complete';
127
- this.showCloseButton = options?.showCloseButton ?? true;
128
- this.showLeftNavButton = options?.showLeftNavButton ?? false;
129
- this.leftNavButtonText = options?.leftNavButtonText ?? '';
130
- this.showHeaderLogo = options?.showHeaderLogo ?? true;
131
- this.closeOnBackdropClick = options?.closeOnBackdropClick ?? true;
132
- }
133
- }
1
+ import { TemplateResult } from 'lit';
2
+
3
+ /**
4
+ * Configuration to show a modal
5
+ *
6
+ * @export
7
+ * @class ModalConfig
8
+ */
9
+ export class ModalConfig {
10
+ /**
11
+ * The title that shows in the header
12
+ *
13
+ * @type {(TemplateResult | undefined)}
14
+ * @memberof ModalConfig
15
+ */
16
+ title?: TemplateResult;
17
+
18
+ /**
19
+ * The subtitle shown in the header under the title
20
+ *
21
+ * @type {(TemplateResult | undefined)}
22
+ * @memberof ModalConfig
23
+ */
24
+ subtitle?: TemplateResult;
25
+
26
+ /**
27
+ * The headline shown at the top of the content section
28
+ *
29
+ * @type {(TemplateResult | undefined)}
30
+ * @memberof ModalConfig
31
+ */
32
+ headline?: TemplateResult;
33
+
34
+ /**
35
+ * The text shown below the headline in the content section
36
+ *
37
+ * @type {(TemplateResult | undefined)}
38
+ * @memberof ModalConfig
39
+ */
40
+ message?: TemplateResult;
41
+
42
+ /**
43
+ * The background color of the header
44
+ *
45
+ * @memberof ModalConfig
46
+ */
47
+ headerColor: string;
48
+
49
+ /**
50
+ * The background color of the body
51
+ *
52
+ * @memberof ModalConfig
53
+ */
54
+ bodyColor: string;
55
+
56
+ /**
57
+ * Show or hide the processing indicator
58
+ *
59
+ * @memberof ModalConfig
60
+ */
61
+ showProcessingIndicator: boolean;
62
+
63
+ /**
64
+ * Set the processing image mode, currently `processing` or `complete`
65
+ *
66
+ * @memberof ModalConfig
67
+ */
68
+ processingImageMode: 'processing' | 'complete';
69
+
70
+ /**
71
+ * Show the close button
72
+ *
73
+ * @memberof ModalConfig
74
+ */
75
+ showCloseButton: boolean;
76
+
77
+ /**
78
+ * Show the left nav button
79
+ *
80
+ * @memberof ModalConfig
81
+ */
82
+ showLeftNavButton: boolean;
83
+
84
+ /**
85
+ * Left nav button text
86
+ */
87
+ leftNavButtonText: string;
88
+
89
+ /**
90
+ * Show the close button
91
+ *
92
+ * @memberof ModalConfig
93
+ */
94
+ showHeaderLogo: boolean;
95
+
96
+ /**
97
+ * Close the modal if the user taps on the background
98
+ *
99
+ * @memberof ModalConfig
100
+ */
101
+ closeOnBackdropClick: boolean;
102
+
103
+ constructor(options?: {
104
+ title?: TemplateResult;
105
+ subtitle?: TemplateResult;
106
+ headline?: TemplateResult;
107
+ message?: TemplateResult;
108
+ headerColor?: string;
109
+ bodyColor?: string;
110
+ showProcessingIndicator?: boolean;
111
+ processingImageMode?: 'processing' | 'complete';
112
+ showCloseButton?: boolean;
113
+ showLeftNavButton?: boolean;
114
+ leftNavButtonText?: string;
115
+ showHeaderLogo?: boolean;
116
+ closeOnBackdropClick?: boolean;
117
+ }) {
118
+ this.title = options?.title;
119
+ this.subtitle = options?.subtitle;
120
+ this.headline = options?.headline;
121
+ this.message = options?.message;
122
+
123
+ this.headerColor = options?.headerColor ?? '#55A183';
124
+ this.bodyColor = options?.bodyColor ?? '#fbfbfd';
125
+ this.showProcessingIndicator = options?.showProcessingIndicator ?? false;
126
+ this.processingImageMode = options?.processingImageMode ?? 'complete';
127
+ this.showCloseButton = options?.showCloseButton ?? true;
128
+ this.showLeftNavButton = options?.showLeftNavButton ?? false;
129
+ this.leftNavButtonText = options?.leftNavButtonText ?? '';
130
+ this.showHeaderLogo = options?.showHeaderLogo ?? true;
131
+ this.closeOnBackdropClick = options?.closeOnBackdropClick ?? true;
132
+ }
133
+ }
@@ -1,13 +1,13 @@
1
- import { ModalManagerMode } from './modal-manager-mode';
2
-
3
- /**
4
- * The ModalManagerHostBridgeInterface is a delegate interface for
5
- * the host to implement environment-specific changes when the modal
6
- * is open or closed.
7
- *
8
- * A default implementation is provided, but can be overridden if
9
- * it does not work for the environment.
10
- */
11
- export interface ModalManagerHostBridgeInterface {
12
- handleModeChange(mode: ModalManagerMode): void;
13
- }
1
+ import { ModalManagerMode } from './modal-manager-mode';
2
+
3
+ /**
4
+ * The ModalManagerHostBridgeInterface is a delegate interface for
5
+ * the host to implement environment-specific changes when the modal
6
+ * is open or closed.
7
+ *
8
+ * A default implementation is provided, but can be overridden if
9
+ * it does not work for the environment.
10
+ */
11
+ export interface ModalManagerHostBridgeInterface {
12
+ handleModeChange(mode: ModalManagerMode): void;
13
+ }
@@ -1,82 +1,82 @@
1
- import { throttle } from 'throttle-debounce';
2
-
3
- import { ModalManagerHostBridgeInterface } from './modal-manager-host-bridge-interface';
4
- import { ModalManagerInterface } from './modal-manager-interface';
5
- import { ModalManagerMode } from './modal-manager-mode';
6
-
7
- /**
8
- * The `ModalManagerHostBridge` is a bridge between the `ModalManager` and the
9
- * host that sets up environment-specific changes when the modal opens and closes.
10
- *
11
- * For instance, when the modal opens, this adds a class to the `<body>` tag for styling
12
- * and adds a `resize` listener to fix a Safari shadow root issue.
13
- *
14
- * Consumers can create their own `ModalManagerHostBridgeInterface` classes and pass
15
- * them into the `ModalManager` if this one does not work for their environment.
16
- *
17
- * @export
18
- * @class ModalManagerHostBridge
19
- * @implements {ModalManagerHostBridgeInterface}
20
- */
21
- export class ModalManagerHostBridge implements ModalManagerHostBridgeInterface {
22
- private modalManager: ModalManagerInterface;
23
-
24
- constructor(modalManager: ModalManagerInterface) {
25
- this.modalManager = modalManager;
26
- }
27
-
28
- /**
29
- * Handle the mode change
30
- *
31
- * @private
32
- * @memberof ModalManager
33
- */
34
- handleModeChange(mode: ModalManagerMode): void {
35
- switch (mode) {
36
- case ModalManagerMode.Open:
37
- this.startResizeListener();
38
- this.stopDocumentScroll();
39
- break;
40
- case ModalManagerMode.Closed:
41
- this.stopResizeListener();
42
- this.resumeDocumentScroll();
43
- break;
44
- }
45
- }
46
-
47
- private windowResizeThrottler: throttle<() => void> = throttle(
48
- 100,
49
- this.updateModalContainerHeight,
50
- { noLeading: false, noTrailing: false }
51
- ).bind(this);
52
-
53
- // This is a workaround for Safari. Safari does not update shadowRoot elements calculated
54
- // based on the viewport size (ie. `calc(100vh - 10px)`). It does an initial calculation correctly,
55
- // but resizing the window does not cause the calculation to update. Firefox and Chrome both handle
56
- // this correctly.
57
- // It doesn't matter what css variable you set, it is just forcing Safari to do an update.
58
- // Also note that the value has to change on each update for Safari to do the update,
59
- // ie. you can't just set a static value.
60
- private updateModalContainerHeight(): void {
61
- this.modalManager.style.setProperty(
62
- '--containerHeight',
63
- `${window.innerHeight}px`
64
- );
65
- }
66
-
67
- private stopDocumentScroll(): void {
68
- document.body.classList.add('modal-manager-open');
69
- }
70
-
71
- private resumeDocumentScroll(): void {
72
- document.body.classList.remove('modal-manager-open');
73
- }
74
-
75
- private startResizeListener(): void {
76
- window.addEventListener('resize', this.windowResizeThrottler);
77
- }
78
-
79
- private stopResizeListener(): void {
80
- window.removeEventListener('resize', this.windowResizeThrottler);
81
- }
82
- }
1
+ import { throttle } from 'throttle-debounce';
2
+
3
+ import { ModalManagerHostBridgeInterface } from './modal-manager-host-bridge-interface';
4
+ import { ModalManagerInterface } from './modal-manager-interface';
5
+ import { ModalManagerMode } from './modal-manager-mode';
6
+
7
+ /**
8
+ * The `ModalManagerHostBridge` is a bridge between the `ModalManager` and the
9
+ * host that sets up environment-specific changes when the modal opens and closes.
10
+ *
11
+ * For instance, when the modal opens, this adds a class to the `<body>` tag for styling
12
+ * and adds a `resize` listener to fix a Safari shadow root issue.
13
+ *
14
+ * Consumers can create their own `ModalManagerHostBridgeInterface` classes and pass
15
+ * them into the `ModalManager` if this one does not work for their environment.
16
+ *
17
+ * @export
18
+ * @class ModalManagerHostBridge
19
+ * @implements {ModalManagerHostBridgeInterface}
20
+ */
21
+ export class ModalManagerHostBridge implements ModalManagerHostBridgeInterface {
22
+ private modalManager: ModalManagerInterface;
23
+
24
+ constructor(modalManager: ModalManagerInterface) {
25
+ this.modalManager = modalManager;
26
+ }
27
+
28
+ /**
29
+ * Handle the mode change
30
+ *
31
+ * @private
32
+ * @memberof ModalManager
33
+ */
34
+ handleModeChange(mode: ModalManagerMode): void {
35
+ switch (mode) {
36
+ case ModalManagerMode.Open:
37
+ this.startResizeListener();
38
+ this.stopDocumentScroll();
39
+ break;
40
+ case ModalManagerMode.Closed:
41
+ this.stopResizeListener();
42
+ this.resumeDocumentScroll();
43
+ break;
44
+ }
45
+ }
46
+
47
+ private windowResizeThrottler: throttle<() => void> = throttle(
48
+ 100,
49
+ this.updateModalContainerHeight,
50
+ { noLeading: false, noTrailing: false }
51
+ ).bind(this);
52
+
53
+ // This is a workaround for Safari. Safari does not update shadowRoot elements calculated
54
+ // based on the viewport size (ie. `calc(100vh - 10px)`). It does an initial calculation correctly,
55
+ // but resizing the window does not cause the calculation to update. Firefox and Chrome both handle
56
+ // this correctly.
57
+ // It doesn't matter what css variable you set, it is just forcing Safari to do an update.
58
+ // Also note that the value has to change on each update for Safari to do the update,
59
+ // ie. you can't just set a static value.
60
+ private updateModalContainerHeight(): void {
61
+ this.modalManager.style.setProperty(
62
+ '--containerHeight',
63
+ `${window.innerHeight}px`
64
+ );
65
+ }
66
+
67
+ private stopDocumentScroll(): void {
68
+ document.body.classList.add('modal-manager-open');
69
+ }
70
+
71
+ private resumeDocumentScroll(): void {
72
+ document.body.classList.remove('modal-manager-open');
73
+ }
74
+
75
+ private startResizeListener(): void {
76
+ window.addEventListener('resize', this.windowResizeThrottler);
77
+ }
78
+
79
+ private stopResizeListener(): void {
80
+ window.removeEventListener('resize', this.windowResizeThrottler);
81
+ }
82
+ }
@@ -1,30 +1,30 @@
1
- import { LitElement, TemplateResult } from 'lit';
2
- import { ModalConfig } from './modal-config';
3
- import { ModalManagerMode } from './modal-manager-mode';
4
-
5
- export interface ModalManagerInterface extends LitElement {
6
- /**
7
- * Get the current modal mode.
8
- */
9
- getMode(): ModalManagerMode;
10
-
11
- /**
12
- * Show a modal from a given ModalConfig
13
- *
14
- * @param config ModalConfig
15
- * @param customModalContent TemplateResult | undefined
16
- * @param userClosedModalCallback () => void | undefined an optional callback when the modal is closed
17
- * @param userPressedLeftNavButtonCallback () => void | undefined an optional callback when the left nav button is pressed
18
- */
19
- showModal(options: {
20
- config: ModalConfig;
21
- customModalContent?: TemplateResult;
22
- userClosedModalCallback?: () => void;
23
- userPressedLeftNavButtonCallback?: () => void;
24
- }): Promise<void>;
25
-
26
- /**
27
- * Close the currently open modal
28
- */
29
- closeModal(): void;
30
- }
1
+ import { LitElement, TemplateResult } from 'lit';
2
+ import { ModalConfig } from './modal-config';
3
+ import { ModalManagerMode } from './modal-manager-mode';
4
+
5
+ export interface ModalManagerInterface extends LitElement {
6
+ /**
7
+ * Get the current modal mode.
8
+ */
9
+ getMode(): ModalManagerMode;
10
+
11
+ /**
12
+ * Show a modal from a given ModalConfig
13
+ *
14
+ * @param config ModalConfig
15
+ * @param customModalContent TemplateResult | undefined
16
+ * @param userClosedModalCallback () => void | undefined an optional callback when the modal is closed
17
+ * @param userPressedLeftNavButtonCallback () => void | undefined an optional callback when the left nav button is pressed
18
+ */
19
+ showModal(options: {
20
+ config: ModalConfig;
21
+ customModalContent?: TemplateResult;
22
+ userClosedModalCallback?: () => void;
23
+ userPressedLeftNavButtonCallback?: () => void;
24
+ }): Promise<void>;
25
+
26
+ /**
27
+ * Close the currently open modal
28
+ */
29
+ closeModal(): void;
30
+ }
@@ -1,10 +1,10 @@
1
- /**
2
- * Various modes the modal can be in
3
- *
4
- * @export
5
- * @enum {number}
6
- */
7
- export enum ModalManagerMode {
8
- Open = 'open',
9
- Closed = 'closed',
10
- }
1
+ /**
2
+ * Various modes the modal can be in
3
+ *
4
+ * @export
5
+ * @enum {number}
6
+ */
7
+ export enum ModalManagerMode {
8
+ Open = 'open',
9
+ Closed = 'closed',
10
+ }
@@ -113,7 +113,7 @@ export class ModalManager extends LitElement implements ModalManagerInterface {
113
113
  this.customModalContent = undefined;
114
114
  if (this.modalTemplate) this.modalTemplate.config = new ModalConfig();
115
115
  this.modal.deactivate();
116
-
116
+
117
117
  // Return focus to the triggering element, if possible
118
118
  (this.triggeringElement as HTMLElement)?.focus?.();
119
119
  this.triggeringElement = undefined;
@@ -184,7 +184,9 @@ export class ModalManager extends LitElement implements ModalManagerInterface {
184
184
  userClosedModalCallback?: () => void;
185
185
  userPressedLeftNavButtonCallback?: () => void;
186
186
  }): Promise<void> {
187
- this.captureTriggeringElement();
187
+ // If the dialog is being opened, make note of what element was focused beforehand
188
+ if (this.mode === ModalManagerMode.Closed) this.captureFocusedElement();
189
+
188
190
  this.closeOnBackdropClick = options.config.closeOnBackdropClick;
189
191
  this.userClosedModalCallback = options.userClosedModalCallback;
190
192
  this.userPressedLeftNavButtonCallback =
@@ -203,7 +205,7 @@ export class ModalManager extends LitElement implements ModalManagerInterface {
203
205
  * Sets the triggering element to the one that is currently focused, as deep
204
206
  * within Shadow DOM as possible.
205
207
  */
206
- private captureTriggeringElement(): void {
208
+ private captureFocusedElement(): void {
207
209
  this.triggeringElement = getDeepestActiveElement();
208
210
  }
209
211