@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.
- package/dist/index.js.map +1 -1
- package/dist/src/assets/arrow-left-icon.js +12 -12
- package/dist/src/assets/arrow-left-icon.js.map +1 -1
- package/dist/src/assets/ia-logo-icon.js +27 -27
- package/dist/src/assets/ia-logo-icon.js.map +1 -1
- package/dist/src/modal-config.js.map +1 -1
- package/dist/src/modal-manager-host-bridge-interface.js.map +1 -1
- package/dist/src/modal-manager-host-bridge.js.map +1 -1
- package/dist/src/modal-manager-interface.js.map +1 -1
- package/dist/src/modal-manager-mode.js.map +1 -1
- package/dist/src/modal-manager.d.ts +1 -1
- package/dist/src/modal-manager.js +4 -2
- package/dist/src/modal-manager.js.map +1 -1
- package/dist/src/modal-template.js +220 -220
- package/dist/src/modal-template.js.map +1 -1
- package/dist/src/shoelace/active-elements.js.map +1 -1
- package/dist/src/shoelace/modal.js.map +1 -1
- package/dist/src/shoelace/tabbable.js.map +1 -1
- package/dist/test/modal-config.test.js.map +1 -1
- package/dist/test/modal-manager.test.js +41 -6
- package/dist/test/modal-manager.test.js.map +1 -1
- package/dist/test/modal-template.test.js +22 -22
- package/dist/test/modal-template.test.js.map +1 -1
- package/dist/vite.config.js.map +1 -1
- package/index.ts +7 -7
- package/package.json +1 -1
- package/src/assets/arrow-left-icon.ts +15 -15
- package/src/assets/ia-logo-icon.ts +30 -30
- package/src/modal-config.ts +133 -133
- package/src/modal-manager-host-bridge-interface.ts +13 -13
- package/src/modal-manager-host-bridge.ts +82 -82
- package/src/modal-manager-interface.ts +30 -30
- package/src/modal-manager-mode.ts +10 -10
- package/src/modal-manager.ts +5 -3
- package/src/modal-template.ts +343 -343
- package/src/shoelace/active-elements.ts +33 -33
- package/src/shoelace/modal.ts +166 -166
- package/src/shoelace/tabbable.ts +223 -223
- package/test/modal-config.test.ts +77 -77
- package/test/modal-manager.test.ts +52 -6
- package/test/modal-template.test.ts +206 -206
- package/vite.config.ts +23 -23
package/src/shoelace/tabbable.ts
CHANGED
|
@@ -1,223 +1,223 @@
|
|
|
1
|
-
/* istanbul ignore file */
|
|
2
|
-
// Cached compute style calls. This is specifically for browsers that dont support `checkVisibility()`.
|
|
3
|
-
// computedStyle calls are "live" so they only need to be retrieved once for an element.
|
|
4
|
-
const computedStyleMap = new WeakMap<Element, CSSStyleDeclaration>();
|
|
5
|
-
|
|
6
|
-
function getCachedComputedStyle(el: HTMLElement): CSSStyleDeclaration {
|
|
7
|
-
let computedStyle: undefined | CSSStyleDeclaration = computedStyleMap.get(el);
|
|
8
|
-
|
|
9
|
-
if (!computedStyle) {
|
|
10
|
-
computedStyle = window.getComputedStyle(el, null);
|
|
11
|
-
computedStyleMap.set(el, computedStyle);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return computedStyle;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function isVisible(el: HTMLElement): boolean {
|
|
18
|
-
// This is the fastest check, but isn't supported in Safari.
|
|
19
|
-
if ('checkVisibility' in el && typeof el['checkVisibility'] === 'function') {
|
|
20
|
-
// Opacity is focusable, visibility is not.
|
|
21
|
-
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
22
|
-
return (el as any)['checkVisibility']({
|
|
23
|
-
checkOpacity: false,
|
|
24
|
-
checkVisibilityCSS: true,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Fallback "polyfill" for "checkVisibility"
|
|
29
|
-
const computedStyle = getCachedComputedStyle(el as HTMLElement);
|
|
30
|
-
|
|
31
|
-
return (
|
|
32
|
-
computedStyle.visibility !== 'hidden' && computedStyle.display !== 'none'
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// While this behavior isn't standard in Safari / Chrome yet, I think it's the most reasonable
|
|
37
|
-
// way of handling tabbable overflow areas. Browser sniffing seems gross, and it's the most
|
|
38
|
-
// accessible way of handling overflow areas. [Konnor]
|
|
39
|
-
function isOverflowingAndTabbable(el: HTMLElement): boolean {
|
|
40
|
-
const computedStyle = getCachedComputedStyle(el);
|
|
41
|
-
|
|
42
|
-
const { overflowY, overflowX } = computedStyle;
|
|
43
|
-
|
|
44
|
-
if (overflowY === 'scroll' || overflowX === 'scroll') {
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (overflowY !== 'auto' || overflowX !== 'auto') {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Always overflow === "auto" by this point
|
|
53
|
-
const isOverflowingY = el.scrollHeight > el.clientHeight;
|
|
54
|
-
|
|
55
|
-
if (isOverflowingY && overflowY === 'auto') {
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const isOverflowingX = el.scrollWidth > el.clientWidth;
|
|
60
|
-
|
|
61
|
-
if (isOverflowingX && overflowX === 'auto') {
|
|
62
|
-
return true;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** Determines if the specified element is tabbable using heuristics inspired by https://github.com/focus-trap/tabbable */
|
|
69
|
-
function isTabbable(el: HTMLElement) {
|
|
70
|
-
const tag = el.tagName.toLowerCase();
|
|
71
|
-
|
|
72
|
-
const tabindex = Number(el.getAttribute('tabindex'));
|
|
73
|
-
const hasTabindex = el.hasAttribute('tabindex');
|
|
74
|
-
|
|
75
|
-
// elements with a tabindex attribute that is either NaN or <= -1 are not tabbable
|
|
76
|
-
if (hasTabindex && (isNaN(tabindex) || tabindex <= -1)) {
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Elements with a disabled attribute are not tabbable
|
|
81
|
-
if (el.hasAttribute('disabled')) {
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// If any parents have "inert", we aren't "tabbable"
|
|
86
|
-
if (el.closest('[inert]')) {
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Radios without a checked attribute are not tabbable
|
|
91
|
-
if (
|
|
92
|
-
tag === 'input' &&
|
|
93
|
-
el.getAttribute('type') === 'radio' &&
|
|
94
|
-
!el.hasAttribute('checked')
|
|
95
|
-
) {
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (!isVisible(el)) {
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Audio and video elements with the controls attribute are tabbable
|
|
104
|
-
if ((tag === 'audio' || tag === 'video') && el.hasAttribute('controls')) {
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Elements with a tabindex other than -1 are tabbable
|
|
109
|
-
if (el.hasAttribute('tabindex')) {
|
|
110
|
-
return true;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Elements with a contenteditable attribute are tabbable
|
|
114
|
-
if (
|
|
115
|
-
el.hasAttribute('contenteditable') &&
|
|
116
|
-
el.getAttribute('contenteditable') !== 'false'
|
|
117
|
-
) {
|
|
118
|
-
return true;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// At this point, the following elements are considered tabbable
|
|
122
|
-
const isNativelyTabbable = [
|
|
123
|
-
'button',
|
|
124
|
-
'input',
|
|
125
|
-
'select',
|
|
126
|
-
'textarea',
|
|
127
|
-
'a',
|
|
128
|
-
'audio',
|
|
129
|
-
'video',
|
|
130
|
-
'summary',
|
|
131
|
-
'iframe',
|
|
132
|
-
].includes(tag);
|
|
133
|
-
|
|
134
|
-
if (isNativelyTabbable) {
|
|
135
|
-
return true;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// We save the overflow checks for last, because they're the most expensive
|
|
139
|
-
return isOverflowingAndTabbable(el);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Returns the first and last bounding elements that are tabbable. This is more performant than checking every single
|
|
144
|
-
* element because it short-circuits after finding the first and last ones.
|
|
145
|
-
*/
|
|
146
|
-
export function getTabbableBoundary(root: HTMLElement | ShadowRoot) {
|
|
147
|
-
const tabbableElements = getTabbableElements(root);
|
|
148
|
-
|
|
149
|
-
// Find the first and last tabbable elements
|
|
150
|
-
const start = tabbableElements[0] ?? null;
|
|
151
|
-
const end = tabbableElements[tabbableElements.length - 1] ?? null;
|
|
152
|
-
|
|
153
|
-
return { start, end };
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* This looks funky. Basically a slot's children will always be picked up *if* they're within the `root` element.
|
|
158
|
-
* However, there is an edge case when, if the `root` is wrapped by another shadow DOM, it won't grab the children.
|
|
159
|
-
* This fixes that fun edge case.
|
|
160
|
-
*/
|
|
161
|
-
function getSlottedChildrenOutsideRootElement(
|
|
162
|
-
slotElement: HTMLSlotElement,
|
|
163
|
-
root: HTMLElement | ShadowRoot
|
|
164
|
-
) {
|
|
165
|
-
return (
|
|
166
|
-
(slotElement.getRootNode({ composed: true }) as ShadowRoot | null)?.host !==
|
|
167
|
-
root
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export function getTabbableElements(root: HTMLElement | ShadowRoot) {
|
|
172
|
-
const walkedEls = new WeakMap();
|
|
173
|
-
const tabbableElements: HTMLElement[] = [];
|
|
174
|
-
|
|
175
|
-
function walk(el: HTMLElement | ShadowRoot) {
|
|
176
|
-
if (el instanceof Element) {
|
|
177
|
-
// if the element has "inert" we can just no-op it.
|
|
178
|
-
if (el.hasAttribute('inert') || el.closest('[inert]')) {
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (walkedEls.has(el)) {
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
walkedEls.set(el, true);
|
|
186
|
-
|
|
187
|
-
if (!tabbableElements.includes(el) && isTabbable(el)) {
|
|
188
|
-
tabbableElements.push(el);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
if (
|
|
192
|
-
el instanceof HTMLSlotElement &&
|
|
193
|
-
getSlottedChildrenOutsideRootElement(el, root)
|
|
194
|
-
) {
|
|
195
|
-
el.assignedElements({ flatten: true }).forEach(
|
|
196
|
-
(assignedEl: Element) => {
|
|
197
|
-
walk(assignedEl as HTMLElement | ShadowRoot);
|
|
198
|
-
}
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (el.shadowRoot !== null && el.shadowRoot.mode === 'open') {
|
|
203
|
-
walk(el.shadowRoot);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
for (const e of Array.from(el.children) as HTMLElement[]) {
|
|
208
|
-
walk(e);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// Collect all elements including the root
|
|
213
|
-
walk(root);
|
|
214
|
-
|
|
215
|
-
// Is this worth having? Most sorts will always add increased overhead. And positive tabindexes shouldn't really be used.
|
|
216
|
-
// So is it worth being right? Or fast?
|
|
217
|
-
return tabbableElements.sort((a, b) => {
|
|
218
|
-
// Make sure we sort by tabindex.
|
|
219
|
-
const aTabindex = Number(a.getAttribute('tabindex')) || 0;
|
|
220
|
-
const bTabindex = Number(b.getAttribute('tabindex')) || 0;
|
|
221
|
-
return bTabindex - aTabindex;
|
|
222
|
-
});
|
|
223
|
-
}
|
|
1
|
+
/* istanbul ignore file */
|
|
2
|
+
// Cached compute style calls. This is specifically for browsers that dont support `checkVisibility()`.
|
|
3
|
+
// computedStyle calls are "live" so they only need to be retrieved once for an element.
|
|
4
|
+
const computedStyleMap = new WeakMap<Element, CSSStyleDeclaration>();
|
|
5
|
+
|
|
6
|
+
function getCachedComputedStyle(el: HTMLElement): CSSStyleDeclaration {
|
|
7
|
+
let computedStyle: undefined | CSSStyleDeclaration = computedStyleMap.get(el);
|
|
8
|
+
|
|
9
|
+
if (!computedStyle) {
|
|
10
|
+
computedStyle = window.getComputedStyle(el, null);
|
|
11
|
+
computedStyleMap.set(el, computedStyle);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return computedStyle;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function isVisible(el: HTMLElement): boolean {
|
|
18
|
+
// This is the fastest check, but isn't supported in Safari.
|
|
19
|
+
if ('checkVisibility' in el && typeof el['checkVisibility'] === 'function') {
|
|
20
|
+
// Opacity is focusable, visibility is not.
|
|
21
|
+
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
22
|
+
return (el as any)['checkVisibility']({
|
|
23
|
+
checkOpacity: false,
|
|
24
|
+
checkVisibilityCSS: true,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Fallback "polyfill" for "checkVisibility"
|
|
29
|
+
const computedStyle = getCachedComputedStyle(el as HTMLElement);
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
computedStyle.visibility !== 'hidden' && computedStyle.display !== 'none'
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// While this behavior isn't standard in Safari / Chrome yet, I think it's the most reasonable
|
|
37
|
+
// way of handling tabbable overflow areas. Browser sniffing seems gross, and it's the most
|
|
38
|
+
// accessible way of handling overflow areas. [Konnor]
|
|
39
|
+
function isOverflowingAndTabbable(el: HTMLElement): boolean {
|
|
40
|
+
const computedStyle = getCachedComputedStyle(el);
|
|
41
|
+
|
|
42
|
+
const { overflowY, overflowX } = computedStyle;
|
|
43
|
+
|
|
44
|
+
if (overflowY === 'scroll' || overflowX === 'scroll') {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (overflowY !== 'auto' || overflowX !== 'auto') {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Always overflow === "auto" by this point
|
|
53
|
+
const isOverflowingY = el.scrollHeight > el.clientHeight;
|
|
54
|
+
|
|
55
|
+
if (isOverflowingY && overflowY === 'auto') {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const isOverflowingX = el.scrollWidth > el.clientWidth;
|
|
60
|
+
|
|
61
|
+
if (isOverflowingX && overflowX === 'auto') {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Determines if the specified element is tabbable using heuristics inspired by https://github.com/focus-trap/tabbable */
|
|
69
|
+
function isTabbable(el: HTMLElement) {
|
|
70
|
+
const tag = el.tagName.toLowerCase();
|
|
71
|
+
|
|
72
|
+
const tabindex = Number(el.getAttribute('tabindex'));
|
|
73
|
+
const hasTabindex = el.hasAttribute('tabindex');
|
|
74
|
+
|
|
75
|
+
// elements with a tabindex attribute that is either NaN or <= -1 are not tabbable
|
|
76
|
+
if (hasTabindex && (isNaN(tabindex) || tabindex <= -1)) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Elements with a disabled attribute are not tabbable
|
|
81
|
+
if (el.hasAttribute('disabled')) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// If any parents have "inert", we aren't "tabbable"
|
|
86
|
+
if (el.closest('[inert]')) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Radios without a checked attribute are not tabbable
|
|
91
|
+
if (
|
|
92
|
+
tag === 'input' &&
|
|
93
|
+
el.getAttribute('type') === 'radio' &&
|
|
94
|
+
!el.hasAttribute('checked')
|
|
95
|
+
) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (!isVisible(el)) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Audio and video elements with the controls attribute are tabbable
|
|
104
|
+
if ((tag === 'audio' || tag === 'video') && el.hasAttribute('controls')) {
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Elements with a tabindex other than -1 are tabbable
|
|
109
|
+
if (el.hasAttribute('tabindex')) {
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Elements with a contenteditable attribute are tabbable
|
|
114
|
+
if (
|
|
115
|
+
el.hasAttribute('contenteditable') &&
|
|
116
|
+
el.getAttribute('contenteditable') !== 'false'
|
|
117
|
+
) {
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// At this point, the following elements are considered tabbable
|
|
122
|
+
const isNativelyTabbable = [
|
|
123
|
+
'button',
|
|
124
|
+
'input',
|
|
125
|
+
'select',
|
|
126
|
+
'textarea',
|
|
127
|
+
'a',
|
|
128
|
+
'audio',
|
|
129
|
+
'video',
|
|
130
|
+
'summary',
|
|
131
|
+
'iframe',
|
|
132
|
+
].includes(tag);
|
|
133
|
+
|
|
134
|
+
if (isNativelyTabbable) {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// We save the overflow checks for last, because they're the most expensive
|
|
139
|
+
return isOverflowingAndTabbable(el);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Returns the first and last bounding elements that are tabbable. This is more performant than checking every single
|
|
144
|
+
* element because it short-circuits after finding the first and last ones.
|
|
145
|
+
*/
|
|
146
|
+
export function getTabbableBoundary(root: HTMLElement | ShadowRoot) {
|
|
147
|
+
const tabbableElements = getTabbableElements(root);
|
|
148
|
+
|
|
149
|
+
// Find the first and last tabbable elements
|
|
150
|
+
const start = tabbableElements[0] ?? null;
|
|
151
|
+
const end = tabbableElements[tabbableElements.length - 1] ?? null;
|
|
152
|
+
|
|
153
|
+
return { start, end };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* This looks funky. Basically a slot's children will always be picked up *if* they're within the `root` element.
|
|
158
|
+
* However, there is an edge case when, if the `root` is wrapped by another shadow DOM, it won't grab the children.
|
|
159
|
+
* This fixes that fun edge case.
|
|
160
|
+
*/
|
|
161
|
+
function getSlottedChildrenOutsideRootElement(
|
|
162
|
+
slotElement: HTMLSlotElement,
|
|
163
|
+
root: HTMLElement | ShadowRoot
|
|
164
|
+
) {
|
|
165
|
+
return (
|
|
166
|
+
(slotElement.getRootNode({ composed: true }) as ShadowRoot | null)?.host !==
|
|
167
|
+
root
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function getTabbableElements(root: HTMLElement | ShadowRoot) {
|
|
172
|
+
const walkedEls = new WeakMap();
|
|
173
|
+
const tabbableElements: HTMLElement[] = [];
|
|
174
|
+
|
|
175
|
+
function walk(el: HTMLElement | ShadowRoot) {
|
|
176
|
+
if (el instanceof Element) {
|
|
177
|
+
// if the element has "inert" we can just no-op it.
|
|
178
|
+
if (el.hasAttribute('inert') || el.closest('[inert]')) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (walkedEls.has(el)) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
walkedEls.set(el, true);
|
|
186
|
+
|
|
187
|
+
if (!tabbableElements.includes(el) && isTabbable(el)) {
|
|
188
|
+
tabbableElements.push(el);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (
|
|
192
|
+
el instanceof HTMLSlotElement &&
|
|
193
|
+
getSlottedChildrenOutsideRootElement(el, root)
|
|
194
|
+
) {
|
|
195
|
+
el.assignedElements({ flatten: true }).forEach(
|
|
196
|
+
(assignedEl: Element) => {
|
|
197
|
+
walk(assignedEl as HTMLElement | ShadowRoot);
|
|
198
|
+
}
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (el.shadowRoot !== null && el.shadowRoot.mode === 'open') {
|
|
203
|
+
walk(el.shadowRoot);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
for (const e of Array.from(el.children) as HTMLElement[]) {
|
|
208
|
+
walk(e);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Collect all elements including the root
|
|
213
|
+
walk(root);
|
|
214
|
+
|
|
215
|
+
// Is this worth having? Most sorts will always add increased overhead. And positive tabindexes shouldn't really be used.
|
|
216
|
+
// So is it worth being right? Or fast?
|
|
217
|
+
return tabbableElements.sort((a, b) => {
|
|
218
|
+
// Make sure we sort by tabindex.
|
|
219
|
+
const aTabindex = Number(a.getAttribute('tabindex')) || 0;
|
|
220
|
+
const bTabindex = Number(b.getAttribute('tabindex')) || 0;
|
|
221
|
+
return bTabindex - aTabindex;
|
|
222
|
+
});
|
|
223
|
+
}
|
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
import { expect } from '@open-wc/testing';
|
|
2
|
-
import { html } from 'lit';
|
|
3
|
-
|
|
4
|
-
import { ModalConfig } from '../src/modal-config';
|
|
5
|
-
|
|
6
|
-
describe('Modal Config', () => {
|
|
7
|
-
it('can be instantiated properly', async () => {
|
|
8
|
-
const config = new ModalConfig();
|
|
9
|
-
const title = html`Foo`;
|
|
10
|
-
config.title = title;
|
|
11
|
-
config.headerColor = 'green';
|
|
12
|
-
|
|
13
|
-
expect(config.title).to.equal(title);
|
|
14
|
-
expect(config.headerColor).to.equal('green');
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('can be instantiated properly with constructor', async () => {
|
|
18
|
-
const title = html`Foo`;
|
|
19
|
-
const subtitle = html`Bar`;
|
|
20
|
-
const headline = html`Baz`;
|
|
21
|
-
const message = html`Boop`;
|
|
22
|
-
|
|
23
|
-
const headerColor = 'blue';
|
|
24
|
-
const showProcessingIndicator = true;
|
|
25
|
-
const processingImageMode = 'processing';
|
|
26
|
-
const showCloseButton = false;
|
|
27
|
-
const showLeftNavButton = false;
|
|
28
|
-
const leftNavButtonText = 'Previous';
|
|
29
|
-
const showHeaderLogo = false;
|
|
30
|
-
const closeOnBackdropClick = false;
|
|
31
|
-
|
|
32
|
-
const config = new ModalConfig({
|
|
33
|
-
title: title,
|
|
34
|
-
subtitle: subtitle,
|
|
35
|
-
headline: headline,
|
|
36
|
-
message: message,
|
|
37
|
-
headerColor: headerColor,
|
|
38
|
-
showProcessingIndicator: showProcessingIndicator,
|
|
39
|
-
processingImageMode: processingImageMode,
|
|
40
|
-
showCloseButton: showCloseButton,
|
|
41
|
-
showLeftNavButton: showLeftNavButton,
|
|
42
|
-
leftNavButtonText: leftNavButtonText,
|
|
43
|
-
showHeaderLogo: showHeaderLogo,
|
|
44
|
-
closeOnBackdropClick: closeOnBackdropClick,
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
expect(config.title).to.equal(title);
|
|
48
|
-
expect(config.subtitle).to.equal(subtitle);
|
|
49
|
-
expect(config.headline).to.equal(headline);
|
|
50
|
-
expect(config.message).to.equal(message);
|
|
51
|
-
|
|
52
|
-
expect(config.headerColor).to.equal(headerColor);
|
|
53
|
-
expect(config.showProcessingIndicator).to.equal(showProcessingIndicator);
|
|
54
|
-
expect(config.processingImageMode).to.equal(processingImageMode);
|
|
55
|
-
expect(config.showCloseButton).to.equal(showCloseButton);
|
|
56
|
-
expect(config.showLeftNavButton).to.equal(showLeftNavButton);
|
|
57
|
-
expect(config.leftNavButtonText).to.equal(leftNavButtonText);
|
|
58
|
-
expect(config.showHeaderLogo).to.equal(showHeaderLogo);
|
|
59
|
-
expect(config.closeOnBackdropClick).to.equal(closeOnBackdropClick);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('instantiates properly with defaults', async () => {
|
|
63
|
-
const config = new ModalConfig();
|
|
64
|
-
expect(config.title).to.equal(undefined);
|
|
65
|
-
expect(config.subtitle).to.equal(undefined);
|
|
66
|
-
expect(config.headline).to.equal(undefined);
|
|
67
|
-
expect(config.message).to.equal(undefined);
|
|
68
|
-
expect(config.headerColor).to.equal('#55A183');
|
|
69
|
-
expect(config.showProcessingIndicator).to.equal(false);
|
|
70
|
-
expect(config.processingImageMode).to.equal('complete');
|
|
71
|
-
expect(config.showCloseButton).to.equal(true);
|
|
72
|
-
expect(config.showLeftNavButton).to.equal(false);
|
|
73
|
-
expect(config.leftNavButtonText).to.equal('');
|
|
74
|
-
expect(config.showHeaderLogo).to.equal(true);
|
|
75
|
-
expect(config.closeOnBackdropClick).to.equal(true);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
1
|
+
import { expect } from '@open-wc/testing';
|
|
2
|
+
import { html } from 'lit';
|
|
3
|
+
|
|
4
|
+
import { ModalConfig } from '../src/modal-config';
|
|
5
|
+
|
|
6
|
+
describe('Modal Config', () => {
|
|
7
|
+
it('can be instantiated properly', async () => {
|
|
8
|
+
const config = new ModalConfig();
|
|
9
|
+
const title = html`Foo`;
|
|
10
|
+
config.title = title;
|
|
11
|
+
config.headerColor = 'green';
|
|
12
|
+
|
|
13
|
+
expect(config.title).to.equal(title);
|
|
14
|
+
expect(config.headerColor).to.equal('green');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('can be instantiated properly with constructor', async () => {
|
|
18
|
+
const title = html`Foo`;
|
|
19
|
+
const subtitle = html`Bar`;
|
|
20
|
+
const headline = html`Baz`;
|
|
21
|
+
const message = html`Boop`;
|
|
22
|
+
|
|
23
|
+
const headerColor = 'blue';
|
|
24
|
+
const showProcessingIndicator = true;
|
|
25
|
+
const processingImageMode = 'processing';
|
|
26
|
+
const showCloseButton = false;
|
|
27
|
+
const showLeftNavButton = false;
|
|
28
|
+
const leftNavButtonText = 'Previous';
|
|
29
|
+
const showHeaderLogo = false;
|
|
30
|
+
const closeOnBackdropClick = false;
|
|
31
|
+
|
|
32
|
+
const config = new ModalConfig({
|
|
33
|
+
title: title,
|
|
34
|
+
subtitle: subtitle,
|
|
35
|
+
headline: headline,
|
|
36
|
+
message: message,
|
|
37
|
+
headerColor: headerColor,
|
|
38
|
+
showProcessingIndicator: showProcessingIndicator,
|
|
39
|
+
processingImageMode: processingImageMode,
|
|
40
|
+
showCloseButton: showCloseButton,
|
|
41
|
+
showLeftNavButton: showLeftNavButton,
|
|
42
|
+
leftNavButtonText: leftNavButtonText,
|
|
43
|
+
showHeaderLogo: showHeaderLogo,
|
|
44
|
+
closeOnBackdropClick: closeOnBackdropClick,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
expect(config.title).to.equal(title);
|
|
48
|
+
expect(config.subtitle).to.equal(subtitle);
|
|
49
|
+
expect(config.headline).to.equal(headline);
|
|
50
|
+
expect(config.message).to.equal(message);
|
|
51
|
+
|
|
52
|
+
expect(config.headerColor).to.equal(headerColor);
|
|
53
|
+
expect(config.showProcessingIndicator).to.equal(showProcessingIndicator);
|
|
54
|
+
expect(config.processingImageMode).to.equal(processingImageMode);
|
|
55
|
+
expect(config.showCloseButton).to.equal(showCloseButton);
|
|
56
|
+
expect(config.showLeftNavButton).to.equal(showLeftNavButton);
|
|
57
|
+
expect(config.leftNavButtonText).to.equal(leftNavButtonText);
|
|
58
|
+
expect(config.showHeaderLogo).to.equal(showHeaderLogo);
|
|
59
|
+
expect(config.closeOnBackdropClick).to.equal(closeOnBackdropClick);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('instantiates properly with defaults', async () => {
|
|
63
|
+
const config = new ModalConfig();
|
|
64
|
+
expect(config.title).to.equal(undefined);
|
|
65
|
+
expect(config.subtitle).to.equal(undefined);
|
|
66
|
+
expect(config.headline).to.equal(undefined);
|
|
67
|
+
expect(config.message).to.equal(undefined);
|
|
68
|
+
expect(config.headerColor).to.equal('#55A183');
|
|
69
|
+
expect(config.showProcessingIndicator).to.equal(false);
|
|
70
|
+
expect(config.processingImageMode).to.equal('complete');
|
|
71
|
+
expect(config.showCloseButton).to.equal(true);
|
|
72
|
+
expect(config.showLeftNavButton).to.equal(false);
|
|
73
|
+
expect(config.leftNavButtonText).to.equal('');
|
|
74
|
+
expect(config.showHeaderLogo).to.equal(true);
|
|
75
|
+
expect(config.closeOnBackdropClick).to.equal(true);
|
|
76
|
+
});
|
|
77
|
+
});
|