@jskit-ai/shell-web 0.2.38 → 0.2.40
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/CHANGELOG.md +4 -0
- package/README.md +16 -0
- package/fixtures/adaptive-shell/src/NotesPage.vue +104 -0
- package/fixtures/adaptive-shell/src/PendingActionsPage.vue +51 -0
- package/fixtures/adaptive-shell/src/PendingDialogPage.vue +57 -0
- package/fixtures/adaptive-shell/src/main.js +6 -0
- package/package.json +4 -2
- package/src/client/components/ShellErrorHost.vue +2 -0
- package/src/client/components/ShellLayout.vue +13 -2
- package/src/client/components/ShellNavigationItem.vue +55 -26
- package/src/client/components/ShellPageAction.vue +18 -3
- package/src/client/components/ShellPageActionsTarget.vue +1 -1
- package/src/client/components/ShellPrimaryAction.vue +13 -2
- package/src/client/composables/useShellInertBehindDialog.js +196 -0
- package/src/client/directives/vPending.js +111 -0
- package/src/client/index.js +1 -0
- package/src/client/support/navigationPresentation.js +8 -0
- package/src/client/support/pageActions.js +1 -0
- package/test/adaptiveShell.browser.test.js +95 -0
- package/test/inertBehindDialog.browser.test.js +262 -0
- package/test/pendingAction.browser.test.js +182 -0
- package/test/vPending.test.js +151 -0
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
+
import { computed } from "vue";
|
|
2
3
|
import { useShellWindowSizeClass } from "../composables/useShellWindowSizeClass.js";
|
|
4
|
+
import { vPending } from "../directives/vPending.js";
|
|
3
5
|
import { useJskitText } from "../i18n.js";
|
|
4
6
|
import ShellPageAction from "./ShellPageAction.vue";
|
|
5
7
|
import ShellPageActions from "./ShellPageActions.vue";
|
|
@@ -9,7 +11,8 @@ import ShellPageActions from "./ShellPageActions.vue";
|
|
|
9
11
|
// ones. It goes to `to`, or runs its click handler (a "New" that opens a dialog). Its layout order puts the FAB inside
|
|
10
12
|
// the shell's navigation bar, so it sits above the bar instead of over it, and it takes layout room (`layout`), so the
|
|
11
13
|
// shell's snackbar shows above it and the screen's last card scrolls clear of it. Attributes and the click handler land on
|
|
12
|
-
// the FAB, or on the bar's button.
|
|
14
|
+
// the FAB, or on the bar's button. While its action runs (`pending`, or `loading` with a progress indicator) it keeps
|
|
15
|
+
// keyboard focus and ignores activation, as ShellPageAction does.
|
|
13
16
|
defineOptions({ inheritAttrs: false });
|
|
14
17
|
|
|
15
18
|
const props = defineProps({
|
|
@@ -30,6 +33,11 @@ const props = defineProps({
|
|
|
30
33
|
type: Boolean,
|
|
31
34
|
default: false
|
|
32
35
|
},
|
|
36
|
+
// The action is running: give it a pending label, such as "Sending…".
|
|
37
|
+
pending: {
|
|
38
|
+
type: Boolean,
|
|
39
|
+
default: false
|
|
40
|
+
},
|
|
33
41
|
loading: {
|
|
34
42
|
type: Boolean,
|
|
35
43
|
default: false
|
|
@@ -37,11 +45,13 @@ const props = defineProps({
|
|
|
37
45
|
});
|
|
38
46
|
const { text } = useJskitText();
|
|
39
47
|
const { isCompact, isMedium } = useShellWindowSizeClass();
|
|
48
|
+
const pending = computed(() => props.pending || props.loading);
|
|
40
49
|
</script>
|
|
41
50
|
|
|
42
51
|
<template>
|
|
43
52
|
<v-fab
|
|
44
53
|
v-if="isCompact || isMedium"
|
|
54
|
+
v-pending="pending"
|
|
45
55
|
v-bind="$attrs"
|
|
46
56
|
class="shell-primary-action"
|
|
47
57
|
app
|
|
@@ -52,7 +62,7 @@ const { isCompact, isMedium } = useShellWindowSizeClass();
|
|
|
52
62
|
:prepend-icon="props.icon"
|
|
53
63
|
:text="text(props.label)"
|
|
54
64
|
:to="props.to"
|
|
55
|
-
:disabled="props.disabled"
|
|
65
|
+
:disabled="props.disabled && !pending"
|
|
56
66
|
:loading="props.loading"
|
|
57
67
|
/>
|
|
58
68
|
<ShellPageActions v-else>
|
|
@@ -63,6 +73,7 @@ const { isCompact, isMedium } = useShellWindowSizeClass();
|
|
|
63
73
|
:label="props.label"
|
|
64
74
|
:to="props.to"
|
|
65
75
|
:disabled="props.disabled"
|
|
76
|
+
:pending="props.pending"
|
|
66
77
|
:loading="props.loading"
|
|
67
78
|
/>
|
|
68
79
|
</ShellPageActions>
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { onBeforeUnmount, onMounted } from "vue";
|
|
2
|
+
import { useRoute } from "vue-router";
|
|
3
|
+
|
|
4
|
+
// An open modal dialog: a Vuetify overlay that declares itself modal, as every `v-dialog` and `v-bottom-sheet` does
|
|
5
|
+
// (a bottom sheet is a dialog), JSKIT's own and an app's, while it is active.
|
|
6
|
+
const OPEN_MODAL_DIALOG = ".v-overlay.v-overlay--active[aria-modal='true']";
|
|
7
|
+
// A part of the page, as `ShellLayout` marks each: the app bar, the rail, the drawer, main, the navigation bar and the
|
|
8
|
+
// side sheet.
|
|
9
|
+
const SHELL_PAGE = "[data-shell-page]";
|
|
10
|
+
// What can open, close or reorder a dialog, or add a part of the page: a Vuetify overlay and a page part.
|
|
11
|
+
const WATCHED = `.v-overlay, ${SHELL_PAGE}`;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Vuetify stacks each overlay it opens 10 above the one opened before (its inline z-index); at one z-index the later
|
|
15
|
+
* in the document is on top.
|
|
16
|
+
* @param {HTMLElement} first
|
|
17
|
+
* @param {HTMLElement} second
|
|
18
|
+
*/
|
|
19
|
+
function stackOrder(first, second) {
|
|
20
|
+
const difference = (Number.parseInt(first.style.zIndex, 10) || 0) - (Number.parseInt(second.style.zIndex, 10) || 0);
|
|
21
|
+
if (difference !== 0) {
|
|
22
|
+
return difference;
|
|
23
|
+
}
|
|
24
|
+
return first.compareDocumentPosition(second) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Whether a batch of mutations can have opened, closed or reordered a dialog, or replaced a part of the page: an
|
|
29
|
+
* overlay's class changed (Vuetify marks an open one `v-overlay--active`), or an overlay or a page part came or went.
|
|
30
|
+
* Every other change on the page, such as a ripple or a field's focus class, is left at that.
|
|
31
|
+
* @param {MutationRecord[]} records
|
|
32
|
+
*/
|
|
33
|
+
function concernsDialogs(records) {
|
|
34
|
+
for (const record of records) {
|
|
35
|
+
if (record.type === "attributes") {
|
|
36
|
+
if (/** @type {Element} */ (record.target).classList.contains("v-overlay")) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
for (const nodes of [record.addedNodes, record.removedNodes]) {
|
|
42
|
+
for (const node of nodes) {
|
|
43
|
+
if (node instanceof Element && (node.matches(WATCHED) || node.querySelector(WATCHED))) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Makes the page behind an open modal dialog inert, as the WAI-ARIA dialog pattern does and as the dialog's scrim
|
|
54
|
+
* already does for the pointer: while a `v-dialog` or `v-bottom-sheet` is open, every part of the page `ShellLayout`
|
|
55
|
+
* marks with `data-shell-page` (the app bar, the rail, the drawer, main with its FAB, the navigation bar and the side
|
|
56
|
+
* sheet) is `inert`, so a keyboard, assistive technology and accessibility checks such as axe skip it. Vuetify's
|
|
57
|
+
* overlay layer, where it teleports dialogs, menus, tooltips and snackbars, is never made inert, so a menu or select
|
|
58
|
+
* opened in the dialog works and a snackbar is announced; of two dialogs open at once, the lower is inert under the
|
|
59
|
+
* upper. A dialog attached inside a part of the page (`attach`, `contained`) stays local to it and leaves the page
|
|
60
|
+
* alone.
|
|
61
|
+
*
|
|
62
|
+
* It watches the document for Vuetify's overlays, so it sees every dialog, whoever renders it, without a dialog
|
|
63
|
+
* component of its own. The page is live again as soon as the render that closes or unmounts its dialog ends, before
|
|
64
|
+
* code that waits for it (`await nextTick()`) gives focus back. Focus then returns to the element that opened the
|
|
65
|
+
* dialog when it has nowhere else to be: Vuetify's overlay gives focus to its activator during that render, while the
|
|
66
|
+
* page is still inert, and a dialog opened from `v-model`, with no activator, gets none. It does not when the dialog
|
|
67
|
+
* closed by leaving its page, where the shell's navigation places focus.
|
|
68
|
+
*/
|
|
69
|
+
function useShellInertBehindDialog() {
|
|
70
|
+
const route = useRoute();
|
|
71
|
+
/** @type {Map<HTMLElement, { opener: HTMLElement | null, path: string }>} each open dialog, its opener and page */
|
|
72
|
+
const open = new Map();
|
|
73
|
+
/** @type {Set<HTMLElement>} the dialogs this made inert under the one on top */
|
|
74
|
+
const inertDialogs = new Set();
|
|
75
|
+
/** @type {EventTarget | null} */
|
|
76
|
+
let focused = null;
|
|
77
|
+
/** @type {EventTarget | null} */
|
|
78
|
+
let focusedBefore = null;
|
|
79
|
+
/** @type {MutationObserver | null} */
|
|
80
|
+
let observer = null;
|
|
81
|
+
|
|
82
|
+
/** @param {FocusEvent} event */
|
|
83
|
+
function trackFocus(event) {
|
|
84
|
+
if (event.target !== focused) {
|
|
85
|
+
focusedBefore = focused;
|
|
86
|
+
focused = event.target;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The element that opened `dialog`: the one with focus as it opens, or the one before when the dialog has already
|
|
92
|
+
* taken focus (a field that focuses itself as it mounts). None when focus was nowhere.
|
|
93
|
+
* @param {HTMLElement} dialog
|
|
94
|
+
*/
|
|
95
|
+
function openerOf(dialog) {
|
|
96
|
+
const active = document.activeElement;
|
|
97
|
+
const element = active && dialog.contains(active) ? focusedBefore : active;
|
|
98
|
+
if (!(element instanceof HTMLElement) || element === document.body || !element.isConnected || dialog.contains(element)) {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
return element;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** @param {boolean} inert */
|
|
105
|
+
function setPageInert(inert) {
|
|
106
|
+
for (const part of document.querySelectorAll(SHELL_PAGE)) {
|
|
107
|
+
if (part instanceof HTMLElement && part.inert !== inert) {
|
|
108
|
+
part.inert = inert;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* After dialogs close, focus their opener (the top dialog's first) when focus is lost: on the page body, in a closed
|
|
115
|
+
* dialog or in an inert part. An opener that is gone, inert, or on a page the dialogs left is passed over.
|
|
116
|
+
* @param {HTMLElement[]} closed The dialogs that closed, the top one first.
|
|
117
|
+
*/
|
|
118
|
+
function returnFocus(closed) {
|
|
119
|
+
const active = document.activeElement;
|
|
120
|
+
const lost = !active ||
|
|
121
|
+
active === document.body ||
|
|
122
|
+
Boolean(active.closest("[inert]")) ||
|
|
123
|
+
closed.some((dialog) => dialog.contains(active));
|
|
124
|
+
if (!lost) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
for (const { opener, path } of closed.map((dialog) => open.get(dialog))) {
|
|
128
|
+
if (path !== route.path || !opener?.isConnected || opener.closest("[inert]")) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
opener.focus({ preventScroll: true });
|
|
132
|
+
if (document.activeElement === opener) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function update() {
|
|
139
|
+
const dialogs = [...document.querySelectorAll(OPEN_MODAL_DIALOG)]
|
|
140
|
+
.filter((dialog) => dialog instanceof HTMLElement && !dialog.closest(SHELL_PAGE))
|
|
141
|
+
.sort(stackOrder);
|
|
142
|
+
// A dialog's opener is read before anything turns inert, which takes focus from it.
|
|
143
|
+
for (const dialog of dialogs) {
|
|
144
|
+
if (!open.has(dialog)) {
|
|
145
|
+
open.set(dialog, { opener: openerOf(dialog), path: route.path });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const top = dialogs.at(-1);
|
|
149
|
+
const lower = new Set(dialogs.filter((dialog) => dialog !== top && !dialog.contains(top)));
|
|
150
|
+
for (const dialog of inertDialogs) {
|
|
151
|
+
if (!lower.has(dialog)) {
|
|
152
|
+
dialog.inert = false;
|
|
153
|
+
inertDialogs.delete(dialog);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
for (const dialog of lower) {
|
|
157
|
+
if (!dialog.inert) {
|
|
158
|
+
dialog.inert = true;
|
|
159
|
+
inertDialogs.add(dialog);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const closed = [...open.keys()].filter((dialog) => !dialogs.includes(dialog)).sort(stackOrder).reverse();
|
|
163
|
+
setPageInert(dialogs.length > 0);
|
|
164
|
+
if (closed.length > 0) {
|
|
165
|
+
returnFocus(closed);
|
|
166
|
+
for (const dialog of closed) {
|
|
167
|
+
open.delete(dialog);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
onMounted(() => {
|
|
173
|
+
document.addEventListener("focusin", trackFocus, true);
|
|
174
|
+
observer = new MutationObserver((records) => {
|
|
175
|
+
if (concernsDialogs(records)) {
|
|
176
|
+
update();
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
observer.observe(document.body, { subtree: true, childList: true, attributes: true, attributeFilter: ["class"] });
|
|
180
|
+
update();
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
onBeforeUnmount(() => {
|
|
184
|
+
document.removeEventListener("focusin", trackFocus, true);
|
|
185
|
+
observer?.disconnect();
|
|
186
|
+
observer = null;
|
|
187
|
+
for (const dialog of inertDialogs) {
|
|
188
|
+
dialog.inert = false;
|
|
189
|
+
}
|
|
190
|
+
inertDialogs.clear();
|
|
191
|
+
open.clear();
|
|
192
|
+
setPageInert(false);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export { useShellInertBehindDialog };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// `v-pending="running"`: a command button that keeps keyboard focus while its action runs. A focused button that
|
|
2
|
+
// becomes `disabled` loses focus (Chromium moves it to the page body), so a keyboard or screen-reader user who pressed
|
|
3
|
+
// Save, Send or "Load more" lands back at the top of the page. While `running` is true the button stays enabled and
|
|
4
|
+
// focusable instead: it reads as unavailable (`aria-disabled="true"`) and ignores activation, so a second click, Enter
|
|
5
|
+
// or Space, or a form's implicit submission through it, does nothing until the action settles. When it settles with
|
|
6
|
+
// focus still on the button, focus moves to the first field the action's refusal marked (a Vuetify field showing an
|
|
7
|
+
// error, or a control with `aria-invalid="true"`): in the button's form, else its dialog, else the page. Without one,
|
|
8
|
+
// focus stays on the button.
|
|
9
|
+
//
|
|
10
|
+
// Put it on the button (`v-btn`, `button`), or on a component that wraps one (`v-fab`, or a live action's `v-checkbox`
|
|
11
|
+
// or `v-switch`): the control is the element itself when it is a button, a link, a checkbox or a radio, or else the
|
|
12
|
+
// first one inside it. Use it in place of `:disabled` for the pending state; `disabled` stays for an action that cannot
|
|
13
|
+
// run at all. Give the button a pending label ("Saving…").
|
|
14
|
+
|
|
15
|
+
const CONTROL =
|
|
16
|
+
"button, a[href], input[type='submit'], input[type='button'], input[type='checkbox'], input[type='radio'], [role='button']";
|
|
17
|
+
const MARKED_FIELD = ".v-input--error, [aria-invalid='true']";
|
|
18
|
+
// A control that can take focus. A marked radio group may start with a disabled choice (the current one), and a select
|
|
19
|
+
// keeps its value in a hidden input, so the first enabled, visible control is the one focused.
|
|
20
|
+
const FOCUSABLE =
|
|
21
|
+
"input:not([type='hidden'], :disabled), textarea:not(:disabled), select:not(:disabled), button:not(:disabled), " +
|
|
22
|
+
"[tabindex]:not([tabindex='-1'])";
|
|
23
|
+
const DIALOG = ".v-overlay__content, [role='dialog'], [role='alertdialog'], dialog";
|
|
24
|
+
const STATE = Symbol("jskit.shell-web.pending");
|
|
25
|
+
|
|
26
|
+
/** @param {Element} element */
|
|
27
|
+
function controlOf(element) {
|
|
28
|
+
return element.matches(CONTROL) ? element : element.querySelector(CONTROL) || element;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Capturing on the button (or its wrapper), so its own click handlers, a router link's navigation and a submit
|
|
33
|
+
* button's form submission never see the activation.
|
|
34
|
+
* @param {Event} event
|
|
35
|
+
*/
|
|
36
|
+
function ignoreWhilePending(event) {
|
|
37
|
+
if (event.currentTarget[STATE]?.pending) {
|
|
38
|
+
event.preventDefault();
|
|
39
|
+
event.stopImmediatePropagation();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** @param {Element} control */
|
|
44
|
+
function firstMarkedField(control) {
|
|
45
|
+
const scope = control.form || control.closest(DIALOG) || control.ownerDocument;
|
|
46
|
+
for (const marked of scope.querySelectorAll(MARKED_FIELD)) {
|
|
47
|
+
const field = marked.matches(FOCUSABLE) ? marked : marked.querySelector(FOCUSABLE);
|
|
48
|
+
if (field && field.getClientRects().length > 0) {
|
|
49
|
+
return field;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @param {Element} element
|
|
57
|
+
* @param {boolean} pending
|
|
58
|
+
*/
|
|
59
|
+
function mark(element, pending) {
|
|
60
|
+
const state = element[STATE];
|
|
61
|
+
const control = controlOf(element);
|
|
62
|
+
state.pending = pending;
|
|
63
|
+
if (pending) {
|
|
64
|
+
control.setAttribute("aria-disabled", "true");
|
|
65
|
+
state.marked = control;
|
|
66
|
+
} else if (state.marked) {
|
|
67
|
+
state.marked.removeAttribute("aria-disabled");
|
|
68
|
+
state.marked = null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The action settled with focus on its button: once the refusal's field errors have drawn, the first marked field
|
|
74
|
+
* takes focus. A later move of focus by the person, or the button going away, leaves focus alone.
|
|
75
|
+
* @param {Element} element
|
|
76
|
+
*/
|
|
77
|
+
function settle(element) {
|
|
78
|
+
const state = element[STATE];
|
|
79
|
+
clearTimeout(state.settling);
|
|
80
|
+
state.settling = setTimeout(() => {
|
|
81
|
+
state.settling = 0;
|
|
82
|
+
if (state.pending || !element.contains(element.ownerDocument.activeElement)) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
firstMarkedField(controlOf(element))?.focus();
|
|
86
|
+
}, 0);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** @type {import("vue").ObjectDirective<HTMLElement, boolean | undefined>} */
|
|
90
|
+
const vPending = {
|
|
91
|
+
mounted(element, binding) {
|
|
92
|
+
element[STATE] = { pending: false, marked: null, settling: 0 };
|
|
93
|
+
element.addEventListener("click", ignoreWhilePending, true);
|
|
94
|
+
mark(element, Boolean(binding.value));
|
|
95
|
+
},
|
|
96
|
+
updated(element, binding) {
|
|
97
|
+
const pending = Boolean(binding.value);
|
|
98
|
+
const wasPending = element[STATE].pending;
|
|
99
|
+
mark(element, pending);
|
|
100
|
+
if (wasPending && !pending && element.contains(element.ownerDocument.activeElement)) {
|
|
101
|
+
settle(element);
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
beforeUnmount(element) {
|
|
105
|
+
clearTimeout(element[STATE]?.settling);
|
|
106
|
+
element.removeEventListener("click", ignoreWhilePending, true);
|
|
107
|
+
delete element[STATE];
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export { vPending };
|
package/src/client/index.js
CHANGED
|
@@ -23,6 +23,7 @@ export { useShellLayoutState } from "./composables/useShellLayoutState.js";
|
|
|
23
23
|
export { useShellPageTitle } from "./composables/useShellPageTitle.js";
|
|
24
24
|
export { useShellPageClose } from "./composables/useShellPageClose.js";
|
|
25
25
|
export { useShellWindowSizeClass } from "./composables/useShellWindowSizeClass.js";
|
|
26
|
+
export { vPending } from "./directives/vPending.js";
|
|
26
27
|
export { useShellNavigation } from "./navigation/useShellNavigation.js";
|
|
27
28
|
export { leaveApp, reloadAppPage } from "./navigation/documentNavigation.js";
|
|
28
29
|
export { useShellLayoutStore } from "./stores/useShellLayoutStore.js";
|
|
@@ -12,6 +12,12 @@ const NO_SHELL_PAGE_ACTIONS_TARGET = "";
|
|
|
12
12
|
/** Vuetify's icon options, which hold the theme's aliases (Vuetify provides them under this global symbol). */
|
|
13
13
|
const VUETIFY_ICONS_KEY = Symbol.for("vuetify:icons");
|
|
14
14
|
const NO_VUETIFY_ICONS = Object.freeze({ aliases: Object.freeze({}) });
|
|
15
|
+
/**
|
|
16
|
+
* The list a Vuetify v-list provides to what it holds (under this global symbol); in one, Vuetify gives a link item
|
|
17
|
+
* the role "link". Outside a list, as in the navigation bar, there is none.
|
|
18
|
+
*/
|
|
19
|
+
const VUETIFY_LIST_KEY = Symbol.for("vuetify:list");
|
|
20
|
+
const NO_VUETIFY_LIST = null;
|
|
15
21
|
|
|
16
22
|
/**
|
|
17
23
|
* The filled form of a navigation icon alias for the active destination: Material 3 shows the active destination's
|
|
@@ -32,9 +38,11 @@ export {
|
|
|
32
38
|
NO_SHELL_NAVIGATION_PRESENTATION,
|
|
33
39
|
NO_SHELL_PAGE_ACTIONS_TARGET,
|
|
34
40
|
NO_VUETIFY_ICONS,
|
|
41
|
+
NO_VUETIFY_LIST,
|
|
35
42
|
SHELL_NAVIGATION_PRESENTATION_KEY,
|
|
36
43
|
SHELL_PAGE_ACTIONS_ID,
|
|
37
44
|
SHELL_PAGE_ACTIONS_TARGET_KEY,
|
|
38
45
|
VUETIFY_ICONS_KEY,
|
|
46
|
+
VUETIFY_LIST_KEY,
|
|
39
47
|
filledIconAlias
|
|
40
48
|
};
|
|
@@ -375,6 +375,101 @@ test("the rail and the drawer run the window's full height beside the top app ba
|
|
|
375
375
|
await page.close();
|
|
376
376
|
});
|
|
377
377
|
|
|
378
|
+
// What a navigation list holds as assistive technology sees it, as axe reads it: the roles of its children, where a
|
|
379
|
+
// child with no role of its own (a div) or a presentational one hands its children to the list; and for each
|
|
380
|
+
// destination, the links in its list item and where it sits in the list.
|
|
381
|
+
function readNavigationList(list) {
|
|
382
|
+
return list.evaluate((element) => {
|
|
383
|
+
const implicitRole = (node) => ({ A: node.hasAttribute("href") ? "link" : "", HR: "separator", LI: "listitem" })[node.tagName] || "";
|
|
384
|
+
const owned = [];
|
|
385
|
+
const own = (node) => {
|
|
386
|
+
const role = node.getAttribute("role") || implicitRole(node);
|
|
387
|
+
if (!role || role === "presentation" || role === "none") {
|
|
388
|
+
for (const child of node.children) own(child);
|
|
389
|
+
} else {
|
|
390
|
+
owned.push(role);
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
for (const child of element.children) own(child);
|
|
394
|
+
const top = element.getBoundingClientRect().top;
|
|
395
|
+
return {
|
|
396
|
+
role: element.getAttribute("role"),
|
|
397
|
+
owned,
|
|
398
|
+
destinations: [...element.querySelectorAll(".v-list-item")].map((item) => ({
|
|
399
|
+
links: [...(item.closest("[role=listitem]")?.querySelectorAll("[role=link]") || [])].map((link) => link.textContent.trim()),
|
|
400
|
+
top: Math.round(item.getBoundingClientRect().top - top),
|
|
401
|
+
height: Math.round(item.getBoundingClientRect().height)
|
|
402
|
+
})),
|
|
403
|
+
dividers: [...element.querySelectorAll("hr")].map((hr) => ({
|
|
404
|
+
role: hr.getAttribute("role"),
|
|
405
|
+
orientation: hr.getAttribute("aria-orientation")
|
|
406
|
+
}))
|
|
407
|
+
};
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// axe's aria-required-children (WCAG 1.3.1 Info and Relationships): a list holds only list items. Vuetify makes a
|
|
412
|
+
// navigation item in a v-list the link itself and the drawer's divider an hr, a separator, so the drawer's and the
|
|
413
|
+
// rail's lists held links and a separator. Each destination is a list item holding its link, the divider is
|
|
414
|
+
// presentational, and the destinations sit where they did: 4dp apart in the drawer and the rail, the divider 8dp from
|
|
415
|
+
// each group. The navigation bar is no list, so its destinations are not list items.
|
|
416
|
+
test("the drawer's, the rail's and a section's navigation lists hold only list items, each with its link: WCAG 1.3.1 (axe aria-required-children)", {
|
|
417
|
+
skip: RUN_BROWSER_TEST ? false : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1",
|
|
418
|
+
timeout: 120_000
|
|
419
|
+
}, async (t) => {
|
|
420
|
+
const { vite, browser } = await startFixture(t);
|
|
421
|
+
const home = ["Home", "Settings", "Contacts", "Suppliers", "Bookings", "Help and support"];
|
|
422
|
+
const drawerList = "[data-testid=jskit-shell-drawer] .shell-layout__drawer-list";
|
|
423
|
+
// Each destination's top in its list, as drawn before the list items: in the drawer 4dp apart, Help and support
|
|
424
|
+
// past the 1dp divider 8dp from each group; in the rail 4dp apart; in a phone's drawer after the hidden divider;
|
|
425
|
+
// in a settings section's list under its 8dp padding.
|
|
426
|
+
const drawerTops = [0, 60, 120, 180, 240, 313];
|
|
427
|
+
const railTops = [0, 60, 120, 180, 240, 300];
|
|
428
|
+
const cases = [
|
|
429
|
+
{ at: "expanded drawer", width: 1280, height: 900, path: "/home", list: drawerList, labels: home, tops: drawerTops, dividers: 1 },
|
|
430
|
+
{ at: "expanded rail", width: 1280, height: 900, path: "/home", toggle: true, list: drawerList, labels: home, tops: railTops, dividers: 1 },
|
|
431
|
+
{
|
|
432
|
+
at: "medium rail",
|
|
433
|
+
width: 768,
|
|
434
|
+
height: 1024,
|
|
435
|
+
path: "/home",
|
|
436
|
+
list: "[data-testid=jskit-shell-rail] .shell-layout__rail-list",
|
|
437
|
+
labels: home,
|
|
438
|
+
tops: railTops,
|
|
439
|
+
dividers: 0
|
|
440
|
+
},
|
|
441
|
+
{ at: "medium drawer", width: 768, height: 1024, path: "/home", toggle: true, list: drawerList, labels: home, tops: drawerTops, dividers: 1 },
|
|
442
|
+
{ at: "compact drawer", width: 390, height: 844, path: "/home", toggle: true, list: drawerList, labels: ["Help and support"], tops: [4], dividers: 1 },
|
|
443
|
+
{ at: "settings section", width: 1280, height: 900, path: "/home/settings", list: ".v-main .v-list--nav", labels: ["General"], tops: [8], dividers: 0 }
|
|
444
|
+
];
|
|
445
|
+
for (const { at, width, height, path: pagePath, toggle, list, labels, tops, dividers } of cases) {
|
|
446
|
+
const page = await browser.newPage({ baseURL: vite.baseURL, viewport: { width, height }, reducedMotion: "reduce" });
|
|
447
|
+
await page.goto(pagePath);
|
|
448
|
+
if (toggle) await page.locator("[data-testid=jskit-shell-nav-toggle]:visible").first().click();
|
|
449
|
+
const navigation = page.locator(list);
|
|
450
|
+
await expect(navigation.locator(".v-list-item").first(), at).toBeVisible();
|
|
451
|
+
// The drawer settles from opening or collapsing before the destinations are read.
|
|
452
|
+
await expect.poll(async () => (await readNavigationList(navigation)).destinations.map(({ top }) => top), { message: at })
|
|
453
|
+
.toEqual(tops);
|
|
454
|
+
const read = await readNavigationList(navigation);
|
|
455
|
+
assert.equal(read.role, "list", `${at}: a list`);
|
|
456
|
+
assert.deepEqual(read.owned, labels.map(() => "listitem"), `${at}: what the list holds`);
|
|
457
|
+
assert.deepEqual(read.destinations.map(({ links }) => links), labels.map((label) => [label]), `${at}: each list item's link`);
|
|
458
|
+
assert.ok(read.destinations.every((destination) => destination.height >= 56), `${at}: 56dp destinations`);
|
|
459
|
+
assert.deepEqual(read.dividers, Array.from({ length: dividers }, () => ({ role: "presentation", orientation: null })), `${at}: the divider`);
|
|
460
|
+
for (const label of labels) {
|
|
461
|
+
const item = navigation.getByRole("listitem").filter({ has: page.getByRole("link", { name: label, exact: true }) });
|
|
462
|
+
await expect(item, `${at}: ${label}`).toHaveCount(1);
|
|
463
|
+
}
|
|
464
|
+
if (width < 600) {
|
|
465
|
+
const bar = page.getByTestId("jskit-shell-bottom-nav");
|
|
466
|
+
await expect(bar.getByRole("link").first(), `${at}: the navigation bar`).toBeVisible();
|
|
467
|
+
await expect(bar.locator("[role=list], [role=listitem]"), `${at}: no list in the navigation bar`).toHaveCount(0);
|
|
468
|
+
}
|
|
469
|
+
await page.close();
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
|
|
378
473
|
test("shell-web preserves the active form across responsive changes", {
|
|
379
474
|
skip: RUN_BROWSER_TEST ? false : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1",
|
|
380
475
|
timeout: 90_000
|