@jskit-ai/shell-web 0.2.38 → 0.2.39

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 CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ - The drawer's and the rail's navigation lists hold only list items (WCAG 1.3.1, axe `aria-required-children`): in a Vuetify list, each `ShellNavigationItem` (a drawer or rail destination, and a `ShellMenuLinkItem` or `ShellSurfaceAwareMenuLinkItem` in an app's own `v-list`, such as a settings section's) is a `role="listitem"` element holding its link, and the drawer's divider between the primary and secondary destinations is `role="presentation"`. Vuetify makes a link item in a list the link itself and draws the divider as an `hr`, a separator, so these lists held links and a separator, which axe reported on every screen. The destinations stay where they were: the list item keeps the 4dp Vuetify sets between a nav list's items, and the rail still spaces its own. Outside a list, as in the navigation bar, an item is its link alone, as before, and attributes given to an item still land on its link.
6
+ - A command button keeps keyboard focus while its action runs. `ShellPageAction` and `ShellPrimaryAction` take `pending` (the action is running; give it a pending label, such as "Saving…"), and `loading` now means the same with Vuetify's progress indicator: the button stays enabled and focused, reads as unavailable (`aria-disabled="true"`) and ignores a click, Enter, Space or a form's implicit submission through it until the action settles, and it is never `disabled` meanwhile, even with `disabled` set too (as `addEdit.isSubmitDisabled` is while a save runs). Any other button, or a component that wraps one such as `v-fab`, takes the new `v-pending` directive (`@jskit-ai/shell-web/client/directives/vPending`, also `vPending` from `@jskit-ai/shell-web/client`). When the action settles with focus still on its button, focus moves to the first field its refusal marked (a Vuetify field in its error state, or one with `aria-invalid="true"`; within it, the first enabled control, so a radio group whose current choice is disabled gets its first enabled one) in the button's form, else its dialog, else the page; with none it stays on the button. Before, a running action's button was `disabled`, and Chromium moves the focus of a button that becomes disabled to the page body, so a keyboard user who pressed Save, Send or "Load more" landed back at the top of the page; a `loading` button kept focus but ran again on a second Enter. The app bar's overflow menu shows a pending action as unavailable, as it showed a loading one.
5
7
  - **Breaking:** the shell's banner names the page's environment from the `jskit-app-environment` meta tag: "Development", "Test" or "Staging", and none in production. It replaces the "Test copy" banner; its id and test id are `jskit-app-environment-banner`, and the shell runtime's key is `appEnvironmentBanner`. It is still a note that never takes a click, with the environment's sentence as its description and no label.
6
8
  - The navigation rail and the standard drawer run the window's full height beside the top app bar, as Material 3 draws them: their menu control sits in the page title's row and the first destination starts right below it. The app bar spanned the window's width and the rail or drawer started under it, adding a 56dp row of its own for the menu control, so the control sat under the title and the destinations started two rows down. They now come before the app bar in the layout (`order` -1, and -2 for the modal drawer, which still opens from the window's edge over the rail and the app bar), and their header is the app bar's 64dp. An inner page keeps its Up arrow in the app bar beside them. Compact windows are unchanged (navigation bar, modal drawer). `runAdaptiveShellSmokeCase` checks it on medium and expanded windows, and `expectNavigationBesideAppBar(navigation, expect)` is exported for a test of its own.
7
9
  - On a compact window (under 600 px), a message that shows while a dialog, a bottom sheet or a temporary navigation drawer is open sits at the top of the window, clear of the actions it reports on; it keeps that place until it closes. Elsewhere and on wider windows messages stay at the bottom start.
@@ -0,0 +1,51 @@
1
+ <script setup>
2
+ import { reactive } from "vue";
3
+ import ShellPageAction from "../../../src/client/components/ShellPageAction.vue";
4
+ import ShellPageActions from "../../../src/client/components/ShellPageActions.vue";
5
+ import ShellPrimaryAction from "../../../src/client/components/ShellPrimaryAction.vue";
6
+
7
+ // Actions whose work runs until the test settles it: a page action that is `pending`, the primary page action with
8
+ // `loading` (Vuetify's progress indicator) and the screen's primary action (a FAB on compact windows) that is `pending`.
9
+ // Each press is counted, and `globalThis.settleFixtureAction(name)` ends that action's run.
10
+ const running = reactive({ sync: false, save: false, send: false });
11
+ const presses = reactive({ sync: 0, save: 0, send: 0 });
12
+
13
+ function start(name) {
14
+ presses[name] += 1;
15
+ running[name] = true;
16
+ }
17
+
18
+ globalThis.settleFixtureAction = (name) => {
19
+ running[name] = false;
20
+ };
21
+ </script>
22
+
23
+ <template>
24
+ <section class="pa-4">
25
+ <ShellPageActions>
26
+ <ShellPageAction
27
+ icon="$refresh"
28
+ :label="running.sync ? 'Syncing…' : 'Sync'"
29
+ :pending="running.sync"
30
+ data-testid="fixture-pending-sync"
31
+ @click="start('sync')"
32
+ />
33
+ <ShellPageAction
34
+ primary
35
+ icon="$check"
36
+ label="Save"
37
+ :loading="running.save"
38
+ data-testid="fixture-pending-save"
39
+ @click="start('save')"
40
+ />
41
+ </ShellPageActions>
42
+ <ShellPrimaryAction
43
+ icon="$send"
44
+ :label="running.send ? 'Sending…' : 'Send'"
45
+ :pending="running.send"
46
+ data-testid="fixture-pending-send"
47
+ @click="start('send')"
48
+ />
49
+ <p data-testid="fixture-pending-presses">sync={{ presses.sync }} save={{ presses.save }} send={{ presses.send }}</p>
50
+ </section>
51
+ </template>
@@ -0,0 +1,57 @@
1
+ <script setup>
2
+ import { ref } from "vue";
3
+ import { vPending } from "../../../src/client/directives/vPending.js";
4
+
5
+ // A dialog's action with v-pending, in the dialog's form: Send invite runs until the test settles it, accepted
6
+ // (`globalThis.settleFixtureInvite()`) or refused with a field marked: Email (`settleFixtureInvite("Already invited.")`)
7
+ // or the Plan radio group, whose first choice, the current plan, is disabled (`settleFixtureInvite(message, "plan")`).
8
+ const dialog = ref(false);
9
+ const sending = ref(false);
10
+ const presses = ref(0);
11
+ const name = ref("");
12
+ const email = ref("");
13
+ const emailError = ref("");
14
+ const plan = ref("current");
15
+ const planError = ref("");
16
+
17
+ function invite() {
18
+ presses.value += 1;
19
+ emailError.value = "";
20
+ planError.value = "";
21
+ sending.value = true;
22
+ }
23
+
24
+ globalThis.settleFixtureInvite = (refusal = "", field = "email") => {
25
+ emailError.value = field === "email" ? refusal : "";
26
+ planError.value = field === "plan" ? refusal : "";
27
+ sending.value = false;
28
+ };
29
+ </script>
30
+
31
+ <template>
32
+ <section class="pa-4">
33
+ <v-btn variant="text" data-testid="fixture-open-invite" @click="dialog = true">Invite someone</v-btn>
34
+ <p data-testid="fixture-invite-presses">{{ presses }}</p>
35
+ <v-dialog v-model="dialog" max-width="480">
36
+ <v-card title="Invite someone">
37
+ <v-form @submit.prevent="invite">
38
+ <v-card-text>
39
+ <v-text-field v-model="name" label="Name" />
40
+ <v-text-field v-model="email" label="Email" :error-messages="emailError" />
41
+ <v-radio-group v-model="plan" label="Plan" :error-messages="planError">
42
+ <v-radio label="Current plan" value="current" disabled />
43
+ <v-radio label="Larger plan" value="larger" />
44
+ </v-radio-group>
45
+ </v-card-text>
46
+ <v-card-actions>
47
+ <v-spacer />
48
+ <v-btn variant="text" @click="dialog = false">Cancel</v-btn>
49
+ <v-btn v-pending="sending" type="submit" variant="text" data-testid="fixture-send-invite">
50
+ {{ sending ? "Sending…" : "Send invite" }}
51
+ </v-btn>
52
+ </v-card-actions>
53
+ </v-form>
54
+ </v-card>
55
+ </v-dialog>
56
+ </section>
57
+ </template>
@@ -18,6 +18,7 @@ import { adminTheme, theme } from "./theme/index.js";
18
18
  import RecordListPage from "./RecordListPage.vue";
19
19
  import RecordPage from "./RecordPage.vue";
20
20
  import FeedbackPage from "./FeedbackPage.vue";
21
+ import PendingActionsPage from "./PendingActionsPage.vue";
21
22
  import DialogFeedbackPage from "./DialogFeedbackPage.vue";
22
23
  import ReportsPage from "./ReportsPage.vue";
23
24
  import ScreenPage from "./ScreenPage.vue";
@@ -341,6 +342,9 @@ const routes = [
341
342
  { path: "/home/components", component: ComponentsPage, meta: { jskit: { title: "Components" } } },
342
343
  { path: "/home/actions", component: ActionsPage, meta: { jskit: { title: "Actions" } } },
343
344
  { path: "/home/actions/new", component: ActionsFormPage, meta: { jskit: { title: "New entry", parent: "/actions" } } },
345
+ // Actions whose work the test holds, to check they keep keyboard focus while it runs.
346
+ { path: "/home/pending", component: PendingActionsPage, meta: { jskit: { title: "Pending actions" } } },
347
+ { path: "/home/pending-dialog", component: () => import("./PendingDialogPage.vue"), meta: { jskit: { title: "Invites" } } },
344
348
  // A layout that draws its own top app bar from the shell's pieces.
345
349
  { path: "/home/studio", component: StudioPage, meta: { ownBar: true, jskit: { title: "Studio" } } },
346
350
  { path: "/home/studio/:id", component: StudioPage, meta: { ownBar: true, jskit: { parent: "/studio" } } },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/shell-web",
3
- "version": "0.2.38",
3
+ "version": "0.2.39",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "jskit test"
@@ -38,6 +38,7 @@
38
38
  "./client/composables/useShellPageTitle": "./src/client/composables/useShellPageTitle.js",
39
39
  "./client/composables/useShellPageClose": "./src/client/composables/useShellPageClose.js",
40
40
  "./client/composables/useShellWindowSizeClass": "./src/client/composables/useShellWindowSizeClass.js",
41
+ "./client/directives/vPending": "./src/client/directives/vPending.js",
41
42
  "./client/providers/ShellWebClientProvider": "./src/client/providers/ShellWebClientProvider.js",
42
43
  "./client/types": "./src/client/types.js",
43
44
  "./test/adaptiveShellSmoke": "./src/test/adaptiveShellSmoke.js",
@@ -49,7 +50,7 @@
49
50
  "@jskit-ai/architecture-inspector": "0.1.25"
50
51
  },
51
52
  "devDependencies": {
52
- "@jskit-ai/material-web": "0.1.8",
53
+ "@jskit-ai/material-web": "0.1.9",
53
54
  "@vue/compiler-sfc": "3.5.44"
54
55
  },
55
56
  "peerDependencies": {
@@ -100,6 +101,7 @@
100
101
  "@jskit-ai/shell-web/client/composables/useShellPageClose",
101
102
  "@jskit-ai/shell-web/client/composables/useShellPageTitle",
102
103
  "@jskit-ai/shell-web/client/composables/useShellWindowSizeClass",
104
+ "@jskit-ai/shell-web/client/directives/vPending",
103
105
  "@jskit-ai/shell-web/client/types"
104
106
  ],
105
107
  "exclude": [
@@ -351,7 +351,8 @@ onBeforeUnmount(() => {
351
351
  target="shell-layout:primary-menu"
352
352
  default
353
353
  />
354
- <v-divider class="shell-layout__drawer-divider" />
354
+ <!-- A list holds only list items (WCAG 1.3.1), so the divider between the two groups is presentational. -->
355
+ <v-divider class="shell-layout__drawer-divider" role="presentation" />
355
356
  <ShellOutlet target="shell-layout:secondary-menu" />
356
357
  </v-list>
357
358
  </ShellNavigationScope>
@@ -4,14 +4,20 @@ import { useLink } from "vue-router";
4
4
  import {
5
5
  NO_SHELL_NAVIGATION_PRESENTATION,
6
6
  NO_VUETIFY_ICONS,
7
+ NO_VUETIFY_LIST,
7
8
  SHELL_NAVIGATION_PRESENTATION_KEY,
8
9
  VUETIFY_ICONS_KEY,
10
+ VUETIFY_LIST_KEY,
9
11
  filledIconAlias
10
12
  } from "../support/navigationPresentation.js";
11
13
  import { activateShellNavigationLinkOnSpace } from "../support/navigationLinkKeyboard.js";
12
14
 
13
15
  // One navigation destination as Material 3 draws it where it sits: a drawer item (a 56dp pill), a rail item (icon in a
14
- // 56x32 indicator with its label below) or a list item. The active destination's icon is filled.
16
+ // 56x32 indicator with its label below) or a list item. The active destination's icon is filled. In a list (the
17
+ // drawer's, the rail's, a settings section's) it is a list item holding its link: Vuetify makes the item itself the
18
+ // link, and a list holds only list items (WCAG 1.3.1). Attributes land on the link.
19
+ defineOptions({ inheritAttrs: false });
20
+
15
21
  const props = defineProps({
16
22
  label: {
17
23
  type: String,
@@ -49,38 +55,61 @@ const active = computed(() =>
49
55
  );
50
56
  const displayIcon = computed(() => (active.value ? filledIconAlias(props.icon, iconOptions.aliases) : props.icon));
51
57
  const rail = computed(() => presentation.value === "rail");
58
+ /** @type {object | null} */
59
+ const list = inject(VUETIFY_LIST_KEY, NO_VUETIFY_LIST);
60
+ // Vuetify gives an item in a list the role "link" when it links somewhere, and "listitem" when it doesn't.
61
+ const listItem = computed(() => Boolean(list && props.href));
62
+
63
+ // What holds an item outside a list: nothing, the link stands alone.
64
+ const Unwrapped = (_props, { slots }) => slots.default();
65
+ Unwrapped.inheritAttrs = false;
52
66
  </script>
53
67
 
54
68
  <template>
55
- <v-list-item
56
- v-if="rail"
57
- class="shell-menu-link-item shell-menu-link-item--rail"
58
- :to="props.sameOrigin ? props.href : undefined"
59
- :href="props.sameOrigin ? undefined : props.href"
60
- :active="active"
61
- :disabled="props.disabled"
62
- :ripple="false"
63
- @keydown.space="activateShellNavigationLinkOnSpace"
69
+ <component
70
+ :is="listItem ? 'div' : Unwrapped"
71
+ :role="listItem ? 'listitem' : undefined"
72
+ :class="listItem ? ['shell-navigation-item', { 'shell-navigation-item--rail': rail }] : undefined"
64
73
  >
65
- <span class="shell-menu-link-item__indicator">
66
- <v-icon v-if="displayIcon" :icon="displayIcon" />
67
- </span>
68
- <span class="shell-menu-link-item__rail-label">{{ props.label }}</span>
69
- </v-list-item>
70
- <v-list-item
71
- v-else
72
- class="shell-menu-link-item"
73
- :title="props.label"
74
- :to="props.sameOrigin ? props.href : undefined"
75
- :href="props.sameOrigin ? undefined : props.href"
76
- :prepend-icon="displayIcon || undefined"
77
- :active="active"
78
- :disabled="props.disabled"
79
- @keydown.space="activateShellNavigationLinkOnSpace"
80
- />
74
+ <v-list-item
75
+ v-if="rail"
76
+ class="shell-menu-link-item shell-menu-link-item--rail"
77
+ :to="props.sameOrigin ? props.href : undefined"
78
+ :href="props.sameOrigin ? undefined : props.href"
79
+ :active="active"
80
+ :disabled="props.disabled"
81
+ :ripple="false"
82
+ v-bind="$attrs"
83
+ @keydown.space="activateShellNavigationLinkOnSpace"
84
+ >
85
+ <span class="shell-menu-link-item__indicator">
86
+ <v-icon v-if="displayIcon" :icon="displayIcon" />
87
+ </span>
88
+ <span class="shell-menu-link-item__rail-label">{{ props.label }}</span>
89
+ </v-list-item>
90
+ <v-list-item
91
+ v-else
92
+ class="shell-menu-link-item"
93
+ :title="props.label"
94
+ :to="props.sameOrigin ? props.href : undefined"
95
+ :href="props.sameOrigin ? undefined : props.href"
96
+ :prepend-icon="displayIcon || undefined"
97
+ :active="active"
98
+ :disabled="props.disabled"
99
+ v-bind="$attrs"
100
+ @keydown.space="activateShellNavigationLinkOnSpace"
101
+ />
102
+ </component>
81
103
  </template>
82
104
 
83
105
  <style scoped>
106
+ /* A nav list spaces each item but its first 4dp below the one before (Vuetify's `.v-list--nav
107
+ .v-list-item:not(:first-child)`). In its list item the item is always a first child, so the list item keeps that
108
+ spacing; the rail spaces its destinations itself. */
109
+ .v-list--nav .shell-navigation-item:not(.shell-navigation-item--rail, :first-child) {
110
+ margin-top: 4px;
111
+ }
112
+
84
113
  .shell-menu-link-item {
85
114
  --v-activated-opacity: 0;
86
115
  border-radius: 9999px;
@@ -2,6 +2,7 @@
2
2
  import { computed, inject, mergeProps, onBeforeUnmount, onMounted, ref, useAttrs, useId } from "vue";
3
3
  import { useShellWindowSizeClass } from "../composables/useShellWindowSizeClass.js";
4
4
  import { useJskitText } from "../i18n.js";
5
+ import { vPending } from "../directives/vPending.js";
5
6
  import { NO_SHELL_PAGE_ACTIONS_REGISTRY, SHELL_PAGE_ACTIONS_REGISTRY_KEY } from "../support/pageActions.js";
6
7
 
7
8
  // One page action in the top app bar. On compact windows a secondary action shows as an icon button named by its
@@ -10,6 +11,10 @@ import { NO_SHELL_PAGE_ACTIONS_REGISTRY, SHELL_PAGE_ACTIONS_REGISTRY_KEY } from
10
11
  // overflow menu, and on compact windows every action but the primary one joins it.
11
12
  // Attributes such as `type="submit"` and `form` (so an app bar Save can submit the page's form), `target`,
12
13
  // `data-testid` or `aria-*` land on the button, or on the menu item, in every form.
14
+ // While its action runs (`pending`, or `loading` with Vuetify's progress indicator in place of the label) the button
15
+ // keeps keyboard focus: it reads as unavailable and ignores activation until the action settles (v-pending), and it is
16
+ // never `disabled` meanwhile, so a `disabled` that also covers the running state (such as `addEdit.isSubmitDisabled`)
17
+ // keeps focus too.
13
18
  defineOptions({ inheritAttrs: false });
14
19
 
15
20
  const props = defineProps({
@@ -59,6 +64,11 @@ const props = defineProps({
59
64
  type: Boolean,
60
65
  default: false
61
66
  },
67
+ // The action is running: give it a pending label, such as "Saving…".
68
+ pending: {
69
+ type: Boolean,
70
+ default: false
71
+ },
62
72
  loading: {
63
73
  type: Boolean,
64
74
  default: false
@@ -72,6 +82,8 @@ const { isCompact } = useShellWindowSizeClass();
72
82
  const resolvedLabel = computed(() => text(props.label));
73
83
  const iconOnly = computed(() => Boolean(props.icon) && isCompact.value && !props.primary);
74
84
  const color = computed(() => props.color || (props.primary ? "primary" : "on-surface-variant"));
85
+ const pending = computed(() => props.pending || props.loading);
86
+ const disabled = computed(() => props.disabled && !pending.value);
75
87
  // A boolean `download` is the attribute without a file name.
76
88
  const download = computed(() => (props.download === true ? "" : props.download || undefined));
77
89
 
@@ -95,7 +107,8 @@ const entry = {
95
107
  color: props.color,
96
108
  primary: props.primary,
97
109
  overflow: props.overflow,
98
- disabled: props.disabled,
110
+ disabled: disabled.value,
111
+ pending: pending.value,
99
112
  loading: props.loading
100
113
  })),
101
114
  attrs,
@@ -123,6 +136,7 @@ onBeforeUnmount(() => {
123
136
  <template #activator="{ props: tooltipProps }">
124
137
  <v-btn
125
138
  v-bind="mergeProps(attrs, tooltipProps)"
139
+ v-pending="pending"
126
140
  class="shell-page-action"
127
141
  :icon="props.icon"
128
142
  variant="text"
@@ -131,7 +145,7 @@ onBeforeUnmount(() => {
131
145
  :replace="props.replace"
132
146
  :href="props.href"
133
147
  :download="download"
134
- :disabled="props.disabled"
148
+ :disabled="disabled"
135
149
  :loading="props.loading"
136
150
  :aria-label="resolvedLabel"
137
151
  @click="handleClick"
@@ -141,6 +155,7 @@ onBeforeUnmount(() => {
141
155
  <v-btn
142
156
  v-else
143
157
  v-bind="attrs"
158
+ v-pending="pending"
144
159
  class="shell-page-action shell-page-action--labelled"
145
160
  :variant="props.primary ? 'flat' : 'text'"
146
161
  :color="color"
@@ -149,7 +164,7 @@ onBeforeUnmount(() => {
149
164
  :replace="props.replace"
150
165
  :href="props.href"
151
166
  :download="download"
152
- :disabled="props.disabled"
167
+ :disabled="disabled"
153
168
  :loading="props.loading"
154
169
  @click="handleClick"
155
170
  >
@@ -45,7 +45,7 @@ watch(showsMenu, (shows) => {
45
45
  // A menu item's props: the action's own attributes, then its label, icon, colour, link or download, and state.
46
46
  function itemProps(entry) {
47
47
  const state = entry.state.value;
48
- const unavailable = Boolean(state.disabled || state.loading);
48
+ const unavailable = Boolean(state.disabled || state.pending);
49
49
  return mergeProps(entry.attrs, {
50
50
  title: state.label,
51
51
  prependIcon: state.icon || undefined,
@@ -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,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 };
@@ -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
  };
@@ -22,6 +22,7 @@ const FOLLOWING = 4;
22
22
  * @property {boolean} primary
23
23
  * @property {boolean} overflow
24
24
  * @property {boolean} disabled
25
+ * @property {boolean} pending Its action is running (`pending` or `loading`).
25
26
  * @property {boolean} loading
26
27
  */
27
28
 
@@ -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
@@ -0,0 +1,182 @@
1
+ import assert from "node:assert/strict";
2
+ import path from "node:path";
3
+ import process from "node:process";
4
+ import test from "node:test";
5
+ import { fileURLToPath } from "node:url";
6
+ import { expect } from "@playwright/test";
7
+ import { sharedBrowserFixture } from "../../../tooling/testUtils/browserFixture.mjs";
8
+
9
+ // A command button keeps keyboard focus while its action runs: ShellPageAction and ShellPrimaryAction with `pending`
10
+ // or `loading`, and any button with v-pending, read as unavailable, ignore a second activation and never hand focus to
11
+ // the page body, which is where a focused button that becomes `disabled` sends it in Chromium. Each test reaches the
12
+ // button with Tab, presses Enter, holds the action, then settles it.
13
+ const SKIP = process.env.JSKIT_SHELL_WEB_BROWSER_INTEGRATION === "1"
14
+ ? false
15
+ : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1 to check that pending actions keep keyboard focus";
16
+ const FIXTURE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../fixtures/adaptive-shell");
17
+ const open = sharedBrowserFixture({ fixtureRoot: FIXTURE_ROOT, configFile: "vite.config.mjs" });
18
+ const COMPACT = Object.freeze({ width: 390, height: 844 });
19
+ const EXPANDED = Object.freeze({ width: 1280, height: 900 });
20
+
21
+ async function openPage(t, viewport, url) {
22
+ const { vite, browser } = await open(t);
23
+ const page = await browser.newPage({ baseURL: vite.baseURL, viewport, reducedMotion: "reduce" });
24
+ await page.goto(url);
25
+ return page;
26
+ }
27
+
28
+ // Records, at every frame until read, each time focus is on the page body (or nowhere).
29
+ async function watchFocus(page) {
30
+ await page.evaluate(() => {
31
+ const lost = [];
32
+ let watching = true;
33
+ const sample = () => {
34
+ const active = document.activeElement;
35
+ if (!active || active === document.body || active === document.documentElement) {
36
+ lost.push(performance.now());
37
+ }
38
+ if (watching) {
39
+ requestAnimationFrame(sample);
40
+ }
41
+ };
42
+ requestAnimationFrame(sample);
43
+ globalThis.jskitPendingFocusWatch = () => {
44
+ watching = false;
45
+ return lost.length;
46
+ };
47
+ });
48
+ return () => page.evaluate(() => globalThis.jskitPendingFocusWatch());
49
+ }
50
+
51
+ // The button inside `locator` when it wraps one (a FAB), else the element itself.
52
+ function buttonOf(locator) {
53
+ return locator.locator("xpath=self::button | self::a | .//button | .//a").first();
54
+ }
55
+
56
+ // Presses Tab until `locator` has focus, as a keyboard user reaches it.
57
+ async function tabTo(page, locator, { max = 80 } = {}) {
58
+ await locator.waitFor({ state: "visible", timeout: 10_000 });
59
+ for (let presses = 0; presses <= max; presses += 1) {
60
+ if (await locator.evaluate((element) => element === document.activeElement)) {
61
+ return;
62
+ }
63
+ await page.keyboard.press("Tab");
64
+ }
65
+ throw new Error(`Tab never reached ${locator}`);
66
+ }
67
+
68
+ const presses = (page) => page.getByTestId("fixture-pending-presses");
69
+
70
+ // Tab to the action's button, press Enter, and check it while it runs: focused, unavailable, a second Enter ignored;
71
+ // then settle it and check focus stayed on it throughout.
72
+ async function checkPendingAction(page, { testId, name, running, idle }) {
73
+ const button = buttonOf(page.getByTestId(testId));
74
+ await tabTo(page, button);
75
+ const framesOnBody = await watchFocus(page);
76
+ await page.keyboard.press("Enter");
77
+ await expect(presses(page)).toContainText(`${name}=1`);
78
+ if (running) {
79
+ await expect(button).toContainText(running);
80
+ }
81
+ await expect(button).toBeFocused();
82
+ await expect(button).toHaveAttribute("aria-disabled", "true");
83
+ await expect(button).not.toHaveAttribute("disabled");
84
+ await page.keyboard.press("Enter");
85
+ await page.keyboard.press(" ");
86
+ await page.waitForTimeout(200);
87
+ await expect(presses(page)).toContainText(`${name}=1`);
88
+ await expect(button).toBeFocused();
89
+
90
+ await page.evaluate((action) => globalThis.settleFixtureAction(action), name);
91
+ if (idle) {
92
+ await expect(button).toContainText(idle);
93
+ }
94
+ await expect(button).not.toHaveAttribute("aria-disabled", "true");
95
+ await expect(button).toBeFocused();
96
+ assert.equal(await framesOnBody(), 0, `focus fell to the page body while ${name} was pending`);
97
+ }
98
+
99
+ test("page actions keep focus while they run: `pending`, and the primary one with `loading`", {
100
+ skip: SKIP,
101
+ timeout: 120_000
102
+ }, async (t) => {
103
+ const page = await openPage(t, EXPANDED, "/home/pending");
104
+ await expect(page.getByTestId("fixture-pending-sync")).toBeVisible();
105
+ await checkPendingAction(page, { testId: "fixture-pending-sync", name: "sync", running: "Syncing…", idle: "Sync" });
106
+ await checkPendingAction(page, { testId: "fixture-pending-save", name: "save" });
107
+ });
108
+
109
+ test("the screen's primary action keeps focus while it runs, as a FAB and as the bar's primary action", {
110
+ skip: SKIP,
111
+ timeout: 120_000
112
+ }, async (t) => {
113
+ for (const viewport of [COMPACT, EXPANDED]) {
114
+ const page = await openPage(t, viewport, "/home/pending");
115
+ await expect(page.getByTestId("fixture-pending-send")).toBeVisible();
116
+ await checkPendingAction(page, { testId: "fixture-pending-send", name: "send", running: "Sending…", idle: "Send" });
117
+ await page.close();
118
+ }
119
+ });
120
+
121
+ test("a dialog's v-pending action keeps focus, ignores a second press and focuses the field a refusal marks", {
122
+ skip: SKIP,
123
+ timeout: 120_000
124
+ }, async (t) => {
125
+ const page = await openPage(t, EXPANDED, "/home/pending-dialog");
126
+ await tabTo(page, page.getByTestId("fixture-open-invite"));
127
+ await page.keyboard.press("Enter");
128
+ const dialog = page.getByRole("dialog");
129
+ await expect(dialog).toBeVisible();
130
+ const send = page.getByTestId("fixture-send-invite");
131
+ await tabTo(page, send, { max: 8 });
132
+ const framesOnBody = await watchFocus(page);
133
+ await page.keyboard.press("Enter");
134
+ await expect(page.getByTestId("fixture-invite-presses")).toHaveText("1");
135
+ await expect(send).toHaveText("Sending…");
136
+ await expect(send).toBeFocused();
137
+ await expect(send).toHaveAttribute("aria-disabled", "true");
138
+ await page.keyboard.press("Enter");
139
+ await page.waitForTimeout(200);
140
+ await expect(page.getByTestId("fixture-invite-presses")).toHaveText("1");
141
+
142
+ await page.evaluate(() => globalThis.settleFixtureInvite("Already invited."));
143
+ await expect(dialog.getByText("Already invited.")).toBeVisible();
144
+ await expect(dialog.getByRole("textbox", { name: "Email" })).toBeFocused();
145
+ assert.equal(await framesOnBody(), 0, "focus fell to the page body while Send invite was pending");
146
+
147
+ // Accepted, focus stays on the button.
148
+ await tabTo(page, send, { max: 8 });
149
+ await page.keyboard.press("Enter");
150
+ await expect(page.getByTestId("fixture-invite-presses")).toHaveText("2");
151
+ await page.evaluate(() => globalThis.settleFixtureInvite());
152
+ await expect(send).toHaveText("Send invite");
153
+ await page.waitForTimeout(100);
154
+ await expect(send).toBeFocused();
155
+
156
+ // A refusal that marks a radio group whose first choice is disabled focuses its first enabled choice.
157
+ await page.keyboard.press("Enter");
158
+ await expect(page.getByTestId("fixture-invite-presses")).toHaveText("3");
159
+ await page.evaluate(() => globalThis.settleFixtureInvite("Choose a larger plan.", "plan"));
160
+ await expect(dialog.getByText("Choose a larger plan.")).toBeVisible();
161
+ await expect(dialog.getByRole("radio", { name: "Larger plan" })).toBeFocused();
162
+ });
163
+
164
+ test("a form's implicit submission does nothing while its v-pending submit button runs", {
165
+ skip: SKIP,
166
+ timeout: 120_000
167
+ }, async (t) => {
168
+ const page = await openPage(t, EXPANDED, "/home/pending-dialog");
169
+ await page.getByTestId("fixture-open-invite").click();
170
+ const name = page.getByRole("dialog").getByRole("textbox", { name: "Name" });
171
+ await name.fill("Ada");
172
+ await name.press("Enter");
173
+ await expect(page.getByTestId("fixture-invite-presses")).toHaveText("1");
174
+ await expect(page.getByTestId("fixture-send-invite")).toHaveText("Sending…");
175
+ await name.press("Enter");
176
+ await page.waitForTimeout(200);
177
+ await expect(page.getByTestId("fixture-invite-presses")).toHaveText("1");
178
+ await page.evaluate(() => globalThis.settleFixtureInvite());
179
+ await expect(page.getByTestId("fixture-send-invite")).toHaveText("Send invite");
180
+ // Focus was never on the button, so the settled action leaves it in the field.
181
+ await expect(name).toBeFocused();
182
+ });
@@ -0,0 +1,151 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { vPending } from "../src/client/directives/vPending.js";
4
+
5
+ // The browser behaviour (focus kept, Enter ignored, a marked field focused) is in pendingAction.browser.test.js; these
6
+ // check the directive's own steps on stand-in elements.
7
+
8
+ function createDocument() {
9
+ return { activeElement: null };
10
+ }
11
+
12
+ // A field the refusal marked; the directive's selector for a focusable control leaves out a disabled one.
13
+ function createField(document, { visible = true, disabled = false } = {}) {
14
+ const field = {
15
+ matches: () => !disabled,
16
+ querySelector: () => null,
17
+ getClientRects: () => (visible ? [{}] : []),
18
+ focus() {
19
+ document.activeElement = field;
20
+ }
21
+ };
22
+ return field;
23
+ }
24
+
25
+ function createButton(document, { form = null, dialog = null } = {}) {
26
+ const attributes = new Map();
27
+ const listeners = [];
28
+ const button = {
29
+ ownerDocument: document,
30
+ form,
31
+ matches: () => true,
32
+ querySelector: () => null,
33
+ closest: () => dialog,
34
+ contains: (other) => other === button,
35
+ setAttribute: (name, value) => attributes.set(name, String(value)),
36
+ removeAttribute: (name) => attributes.delete(name),
37
+ getAttribute: (name) => attributes.get(name) ?? null,
38
+ addEventListener: (type, handler, capture) => listeners.push({ type, handler, capture }),
39
+ removeEventListener: (type, handler, capture) => {
40
+ const index = listeners.findIndex((entry) => entry.type === type && entry.handler === handler && entry.capture === capture);
41
+ if (index >= 0) listeners.splice(index, 1);
42
+ },
43
+ listeners,
44
+ click() {
45
+ const calls = [];
46
+ const event = {
47
+ currentTarget: button,
48
+ preventDefault: () => calls.push("preventDefault"),
49
+ stopImmediatePropagation: () => calls.push("stopImmediatePropagation")
50
+ };
51
+ for (const { handler } of listeners.filter((entry) => entry.type === "click")) handler(event);
52
+ return calls;
53
+ },
54
+ focus() {
55
+ document.activeElement = button;
56
+ }
57
+ };
58
+ return button;
59
+ }
60
+
61
+ function scope(fields) {
62
+ return { querySelectorAll: () => fields };
63
+ }
64
+
65
+ const settled = () => new Promise((resolve) => setTimeout(resolve, 5));
66
+
67
+ test("a pending button reads as unavailable and cancels its activation until it settles", () => {
68
+ const document = createDocument();
69
+ const button = createButton(document);
70
+ vPending.mounted(button, { value: false });
71
+ assert.deepEqual(button.listeners.map(({ type, capture }) => [type, capture]), [["click", true]]);
72
+ assert.equal(button.getAttribute("aria-disabled"), null);
73
+ assert.deepEqual(button.click(), [], "an idle button's click goes through");
74
+
75
+ vPending.updated(button, { value: true, oldValue: false });
76
+ assert.equal(button.getAttribute("aria-disabled"), "true");
77
+ assert.deepEqual(button.click(), ["preventDefault", "stopImmediatePropagation"]);
78
+
79
+ vPending.updated(button, { value: false, oldValue: true });
80
+ assert.equal(button.getAttribute("aria-disabled"), null);
81
+ assert.deepEqual(button.click(), []);
82
+
83
+ vPending.beforeUnmount(button);
84
+ assert.equal(button.listeners.length, 0);
85
+ });
86
+
87
+ test("settling with focus on the button focuses the first visible, enabled field the refusal marked in its form", async () => {
88
+ const document = createDocument();
89
+ const hidden = createField(document, { visible: false });
90
+ const disabled = createField(document, { disabled: true });
91
+ const email = createField(document);
92
+ const button = createButton(document, { form: scope([hidden, disabled, email]) });
93
+ vPending.mounted(button, { value: true });
94
+ button.focus();
95
+ vPending.updated(button, { value: false, oldValue: true });
96
+ assert.equal(document.activeElement, button, "focus moves only once the refusal's errors have drawn");
97
+ await settled();
98
+ assert.equal(document.activeElement, email);
99
+ vPending.beforeUnmount(button);
100
+ });
101
+
102
+ test("outside a form the button's dialog, then the page, holds the marked fields", async () => {
103
+ const document = createDocument();
104
+ const inDialog = createField(document);
105
+ const dialogButton = createButton(document, { dialog: scope([inDialog]) });
106
+ vPending.mounted(dialogButton, { value: true });
107
+ dialogButton.focus();
108
+ vPending.updated(dialogButton, { value: false, oldValue: true });
109
+ await settled();
110
+ assert.equal(document.activeElement, inDialog);
111
+ vPending.beforeUnmount(dialogButton);
112
+
113
+ const onPage = createField(document);
114
+ Object.assign(document, scope([onPage]));
115
+ const barButton = createButton(document);
116
+ vPending.mounted(barButton, { value: true });
117
+ barButton.focus();
118
+ vPending.updated(barButton, { value: false, oldValue: true });
119
+ await settled();
120
+ assert.equal(document.activeElement, onPage);
121
+ vPending.beforeUnmount(barButton);
122
+ });
123
+
124
+ test("focus stays where it is when nothing is marked, when it left the button, or when the button goes", async () => {
125
+ const document = createDocument();
126
+ const accepted = createButton(document, { form: scope([]) });
127
+ vPending.mounted(accepted, { value: true });
128
+ accepted.focus();
129
+ vPending.updated(accepted, { value: false, oldValue: true });
130
+ await settled();
131
+ assert.equal(document.activeElement, accepted);
132
+ vPending.beforeUnmount(accepted);
133
+
134
+ const marked = createField(document);
135
+ const left = createButton(document, { form: scope([marked]) });
136
+ const elsewhere = createField(document);
137
+ vPending.mounted(left, { value: true });
138
+ elsewhere.focus();
139
+ vPending.updated(left, { value: false, oldValue: true });
140
+ await settled();
141
+ assert.equal(document.activeElement, elsewhere);
142
+ vPending.beforeUnmount(left);
143
+
144
+ const gone = createButton(document, { form: scope([marked]) });
145
+ vPending.mounted(gone, { value: true });
146
+ gone.focus();
147
+ vPending.updated(gone, { value: false, oldValue: true });
148
+ vPending.beforeUnmount(gone);
149
+ await settled();
150
+ assert.equal(document.activeElement, gone);
151
+ });