@stackoverflow/stacks 2.8.2 → 2.8.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/README.md +2 -1
- package/dist/css/stacks.css +28 -18
- package/dist/css/stacks.min.css +1 -1
- package/dist/js/stacks.js +30 -23
- package/dist/js/stacks.min.js +1 -1
- package/lib/components/modal/modal.ts +34 -25
- package/lib/components/notice/notice.less +6 -4
- package/package.json +1 -1
|
@@ -225,13 +225,14 @@ export class ModalController extends Stacks.StacksController {
|
|
|
225
225
|
this.modalTarget.addEventListener(
|
|
226
226
|
"s-modal:shown",
|
|
227
227
|
() => {
|
|
228
|
-
const initialFocus =
|
|
229
|
-
this.firstVisible(this.initialFocusTargets) ??
|
|
230
|
-
this.firstVisible(this.getAllTabbables());
|
|
231
|
-
|
|
232
228
|
// Only set focus if focus is not already set on an element within the modal
|
|
233
229
|
if (!this.modalTarget.contains(document.activeElement)) {
|
|
234
|
-
initialFocus
|
|
230
|
+
const initialFocus =
|
|
231
|
+
this.firstVisible(this.initialFocusTargets) ??
|
|
232
|
+
this.firstVisible(this.getAllTabbables()) ??
|
|
233
|
+
this.modalTarget; //If there's nothing else, focus the modal itself
|
|
234
|
+
|
|
235
|
+
initialFocus.focus();
|
|
235
236
|
}
|
|
236
237
|
},
|
|
237
238
|
{ once: true }
|
|
@@ -242,9 +243,21 @@ export class ModalController extends Stacks.StacksController {
|
|
|
242
243
|
* Returns keyboard focus to the modal if it has left or is about to leave.
|
|
243
244
|
*/
|
|
244
245
|
private keepFocusWithinModal(e: KeyboardEvent) {
|
|
245
|
-
|
|
246
|
+
if (e.key !== "Tab") {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
//Tab key was pressed, figure out what to focus next
|
|
251
|
+
const tabbables = this.getAllTabbables();
|
|
252
|
+
if (tabbables.length === 0) {
|
|
253
|
+
// Nothing focusable found in the modal. Stop the user from tabbing to something outside the modal
|
|
254
|
+
e.preventDefault();
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// If somehow the user has tabbed out of the modal, push them to the first item.
|
|
246
259
|
if (!this.modalTarget.contains(<Element>e.target)) {
|
|
247
|
-
const focusTarget = this.firstVisible(
|
|
260
|
+
const focusTarget = this.firstVisible(tabbables);
|
|
248
261
|
if (focusTarget) {
|
|
249
262
|
e.preventDefault();
|
|
250
263
|
focusTarget.focus();
|
|
@@ -253,24 +266,20 @@ export class ModalController extends Stacks.StacksController {
|
|
|
253
266
|
return;
|
|
254
267
|
}
|
|
255
268
|
|
|
256
|
-
//
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
} else if (!e.shiftKey && e.target === lastTabbable) {
|
|
271
|
-
e.preventDefault();
|
|
272
|
-
firstTabbable.focus();
|
|
273
|
-
}
|
|
269
|
+
// Keep focusable cycling within the modal by looping through elements within the modal
|
|
270
|
+
const firstTabbable = this.firstVisible(tabbables);
|
|
271
|
+
const lastTabbable = this.lastVisible(tabbables);
|
|
272
|
+
|
|
273
|
+
if (firstTabbable && lastTabbable) {
|
|
274
|
+
if (firstTabbable === lastTabbable) {
|
|
275
|
+
e.preventDefault();
|
|
276
|
+
firstTabbable.focus();
|
|
277
|
+
} else if (e.shiftKey && e.target === firstTabbable) {
|
|
278
|
+
e.preventDefault();
|
|
279
|
+
lastTabbable.focus();
|
|
280
|
+
} else if (!e.shiftKey && e.target === lastTabbable) {
|
|
281
|
+
e.preventDefault();
|
|
282
|
+
firstTabbable.focus();
|
|
274
283
|
}
|
|
275
284
|
}
|
|
276
285
|
}
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
--_no-btn-fc: ~"var(--@{colorName}-500)";
|
|
17
17
|
--_no-code-bc: ~"var(--@{colorName}-300)";
|
|
18
18
|
--_no-code-bg: ~"var(--@{colorName}-200)";
|
|
19
|
+
|
|
20
|
+
.highcontrast-mode({
|
|
21
|
+
--_no-bc: ~"var(--@{colorName}-400)";
|
|
22
|
+
});
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
& when (@modifier = important) {
|
|
@@ -54,10 +58,6 @@
|
|
|
54
58
|
--_no-code-fc: var(--_no-fc);
|
|
55
59
|
|
|
56
60
|
// CONTEXTUAL STYLES
|
|
57
|
-
.dark-mode({
|
|
58
|
-
--_no-bc: var(--_no-bg);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
61
|
.highcontrast-mode({
|
|
62
62
|
&,
|
|
63
63
|
&.@{baseClass}__danger,
|
|
@@ -74,6 +74,8 @@
|
|
|
74
74
|
--_no-code-fc: var(--white);
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
+
|
|
78
|
+
--_no-bc: var(--black-400);
|
|
77
79
|
});
|
|
78
80
|
|
|
79
81
|
// MODIFIERS
|