@jskit-ai/shell-web 0.2.41 → 0.2.43

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
+ - A navigation rail label never breaks inside a word. A label wider than the rail wraps between its words to a second line, as Material 3's rail labels do, and only a label that needs a third line ends its second in an ellipsis, as before; a single word wider than the rail now ends in an ellipsis too, where it was split across two lines ("Administrati" over "on").
6
+ - Closing a dialog no longer makes a closed modal navigation drawer or side sheet reachable. The page behind a dialog made every part `ShellLayout` marks `data-shell-page` live when the dialog closed, and when the layout mounted, the closed drawer and side sheet included, which Vuetify keeps `inert` while they are closed, so their off-screen destinations and content took keyboard focus and assistive technology read them. Now only the parts the dialog made inert are made live again; a part already inert stays so, and a drawer that closes behind the dialog (a window that narrows, a link in the dialog) is inert once the dialog closes.
5
7
  - The page behind an open modal dialog is inert, as the WAI-ARIA dialog pattern has it and as the dialog's scrim already had it for the pointer: while a `v-dialog` or a `v-bottom-sheet` is open, `ShellLayout`'s app bar, rail, drawer, main (with the page's FAB and its other actions), navigation bar and side sheet carry `inert`, so they take no focus, assistive technology skips them and axe judges only the dialog, its target-size rule included. Before, the page stayed live in the accessibility tree under the scrim: axe's target-size rule judged a note's Edit button and a card link behind the scrim as targets, and an app had to narrow its axe checks to the topmost dialog. Vuetify's overlay layer, where it teleports dialogs, menus, tooltips and snackbars, is never inert, so a select or menu opened in the dialog works and a snackbar shown over it is announced; of two dialogs open at once, the lower is inert under the upper until that closes. The shell sees every dialog, an app's and JSKIT's own (`ShellErrorHost`'s, auth-web's `SecondFactorDialog`), by watching the document for Vuetify's open modal overlays (`.v-overlay--active[aria-modal="true"]`), with no dialog component of its own. The page is live again the moment its dialog closes or unmounts, before the dialog gives focus back, and focus then returns to the element that opened the dialog when it has nowhere else to be: Vuetify's own return to an activator runs while the page is still inert, and a dialog opened from `v-model`, with no activator, never had one. A dialog that closes by leaving its page leaves focus to the next page, and the page there is live. A dialog attached or contained inside the page (`attach`, `contained`) stays local to that part and leaves the page as it is. The parts the shell makes inert carry `data-shell-page`. An app that drew its own layout around `v-main` (with `useShellAppBar()`) does not get this.
6
8
  - `ShellErrorHost`'s dialog has an accessible name, its title ("Attention required"), as a dialog must (WCAG 4.1.2, axe `aria-dialog-name`): Vuetify names no dialog itself, so it was a dialog with no name.
7
9
  - 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.
package/README.md CHANGED
@@ -40,3 +40,11 @@ focus returns to the element that opened it unless focus already went
40
40
  somewhere; a dialog that closes by leaving its page leaves focus to the next
41
41
  page. A dialog attached or contained inside the page stays local and leaves the
42
42
  page alone.
43
+
44
+ Only the parts the dialog made inert are made live again. A part already inert
45
+ of its own, as Vuetify keeps a closed modal drawer or side sheet, stays inert
46
+ after the dialog, and a drawer that closes behind the dialog (the window
47
+ narrows, or a link in the dialog leaves the page) is inert once the dialog
48
+ closes; one that opens behind it is inert until the dialog closes and live
49
+ after. A layout of an app's own that binds `inert` on a part it marks
50
+ `data-shell-page` keeps the value it binds in the same way.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/shell-web",
3
- "version": "0.2.41",
3
+ "version": "0.2.43",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "jskit test"
@@ -47,7 +47,7 @@
47
47
  "./locales/en.json": "./locales/en.json"
48
48
  },
49
49
  "dependencies": {
50
- "@jskit-ai/architecture-inspector": "0.1.25"
50
+ "@jskit-ai/architecture-inspector": "0.1.26"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@jskit-ai/material-web": "0.1.9",
@@ -186,21 +186,25 @@ Unwrapped.inheritAttrs = false;
186
186
  color: rgb(var(--v-theme-on-secondary-container));
187
187
  }
188
188
 
189
- /* A rail label is shown in full: one wider than the rail wraps to a second line, as Material 3's rail labels do,
190
- and only a label that needs a third line ends the second in an ellipsis. */
189
+ /* A rail label is shown in full: one wider than the rail wraps to a second line between its words, as Material 3's rail
190
+ labels do, and only a label that needs a third line ends the second in an ellipsis. A word is never broken: one
191
+ wider than the rail ends in an ellipsis. */
191
192
  .shell-menu-link-item__rail-label {
192
193
  -webkit-box-orient: vertical;
193
194
  -webkit-line-clamp: 2;
194
195
  display: -webkit-box;
195
196
  font-size: 0.75rem;
196
197
  font-weight: 500;
198
+ hyphens: manual;
197
199
  letter-spacing: 0.03125rem;
198
200
  line-height: 1rem;
199
201
  max-width: calc(var(--shell-navigation-rail-width, 80px) - 8px);
200
202
  overflow: hidden;
201
- overflow-wrap: break-word;
203
+ overflow-wrap: normal;
202
204
  text-align: center;
205
+ text-overflow: ellipsis;
203
206
  white-space: normal;
207
+ word-break: normal;
204
208
  }
205
209
 
206
210
  .shell-menu-link-item--rail.v-list-item--active .shell-menu-link-item__rail-label {
@@ -60,6 +60,11 @@ function concernsDialogs(records) {
60
60
  * alone. What turns inert lets go first: focus in it moves into the dialog, and what the pointer is on is told the
61
61
  * pointer left, so a tooltip on the element that opened the dialog closes as it would have without `inert`.
62
62
  *
63
+ * A part that is inert of its own, as Vuetify keeps a closed modal drawer or side sheet, is left alone, and only the
64
+ * parts this made inert are made live again. What a part's owner sets its `inert` to while this holds it, as a drawer
65
+ * that closes behind the dialog does (a narrower window, a link in the dialog), is the part's again once the dialogs
66
+ * close.
67
+ *
63
68
  * It watches the document for Vuetify's overlays, so it sees every dialog, whoever renders it, without a dialog
64
69
  * component of its own. The page is live again as soon as the render that closes or unmounts its dialog ends, before
65
70
  * code that waits for it (`await nextTick()`) gives focus back. Focus then returns to the element that opened the
@@ -73,6 +78,8 @@ function useShellInertBehindDialog() {
73
78
  const open = new Map();
74
79
  /** @type {Set<HTMLElement>} the dialogs this made inert under the one on top */
75
80
  const inertDialogs = new Set();
81
+ /** @type {Map<HTMLElement, { inert: boolean }>} the parts of the page this made inert, each with its owner's inert */
82
+ const heldParts = new Map();
76
83
  /** @type {EventTarget | null} */
77
84
  let focused = null;
78
85
  /** @type {EventTarget | null} */
@@ -127,11 +134,56 @@ function useShellInertBehindDialog() {
127
134
  }
128
135
  }
129
136
 
130
- /** @param {boolean} inert */
137
+ /**
138
+ * Makes a live part of the page inert and keeps aside what its owner sets its `inert` to until `release`. Vue sets
139
+ * `inert` only when the owner's own value changes (Vuetify's drawer has `inert` while it is closed), so a drawer that
140
+ * closes while it is held sets it once, here, and that value must outlast this hold: forgetting it would leave the
141
+ * closed drawer live after the dialog.
142
+ * @param {HTMLElement} part
143
+ */
144
+ function hold(part) {
145
+ const inert = /** @type {PropertyDescriptor} */ (Object.getOwnPropertyDescriptor(HTMLElement.prototype, "inert"));
146
+ if (!heldParts.has(part)) {
147
+ const own = { inert: false };
148
+ Object.defineProperty(part, "inert", {
149
+ configurable: true,
150
+ get: () => inert.get?.call(part),
151
+ set: (value) => {
152
+ own.inert = Boolean(value);
153
+ }
154
+ });
155
+ heldParts.set(part, own);
156
+ }
157
+ inert.set?.call(part, true);
158
+ }
159
+
160
+ /**
161
+ * Gives a held part its own `inert` back: live, unless its owner made it inert meanwhile.
162
+ * @param {HTMLElement} part
163
+ */
164
+ function release(part) {
165
+ const own = heldParts.get(part);
166
+ heldParts.delete(part);
167
+ Reflect.deleteProperty(part, "inert");
168
+ part.inert = Boolean(own?.inert);
169
+ }
170
+
171
+ /**
172
+ * While dialogs are open, every live part of the page is held inert; once none is, the parts this holds are released.
173
+ * A part inert of its own is never touched.
174
+ * @param {boolean} inert
175
+ */
131
176
  function setPageInert(inert) {
132
- for (const part of document.querySelectorAll(SHELL_PAGE)) {
133
- if (part instanceof HTMLElement && part.inert !== inert) {
134
- part.inert = inert;
177
+ if (inert) {
178
+ for (const part of document.querySelectorAll(SHELL_PAGE)) {
179
+ if (part instanceof HTMLElement && !part.inert) {
180
+ hold(part);
181
+ }
182
+ }
183
+ }
184
+ for (const part of [...heldParts.keys()]) {
185
+ if (!inert || !part.isConnected) {
186
+ release(part);
135
187
  }
136
188
  }
137
189
  }
@@ -1917,3 +1917,66 @@ test("segmented buttons, filter chips, fixed tabs, menus and dialog actions take
1917
1917
  await stopProcess(vite);
1918
1918
  }
1919
1919
  });
1920
+
1921
+ // A rail label wraps only between words, to two lines at most, as Material 3's rail labels do: a word wider than the
1922
+ // rail ends in an ellipsis instead of breaking in two, and a label that needs a third line ends its second in one.
1923
+ test("rail labels wrap only between words, and a word wider than the rail ends in an ellipsis, at the rail's default and a narrow width", {
1924
+ skip: RUN_BROWSER_TEST ? false : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1",
1925
+ timeout: 90_000
1926
+ }, async (t) => {
1927
+ const { vite, browser } = await startFixture(t);
1928
+ const page = await browser.newPage({ baseURL: vite.baseURL, viewport: { width: 768, height: 1024 } });
1929
+ for (const railWidth of [80, 56]) {
1930
+ await page.goto(`/w/acme/admin/bookings?theme=light&railWidth=${railWidth}`);
1931
+ const rail = page.getByTestId("jskit-shell-rail");
1932
+ const labels = rail.locator(".shell-menu-link-item__rail-label");
1933
+ await expect(labels.first()).toBeVisible();
1934
+ await expect.poll(async () => Math.round((await rail.boundingBox())?.width || 0)).toBe(railWidth);
1935
+ // A label as the rail lays it out: its lines, the words that lie on two of them, the words wider than the label's
1936
+ // room, whether it ends in an ellipsis, and whether it stays inside the rail.
1937
+ const layout = (text) => labels.nth(1).evaluate(async (element, label) => {
1938
+ element.textContent = label;
1939
+ await document.fonts.ready;
1940
+ const style = window.getComputedStyle(element);
1941
+ const box = element.getBoundingClientRect();
1942
+ const railBox = element.closest("[data-testid=jskit-shell-rail]").getBoundingClientRect();
1943
+ const split = [];
1944
+ const tooWide = [];
1945
+ for (const match of label.matchAll(/\S+/gu)) {
1946
+ const range = document.createRange();
1947
+ range.setStart(element.firstChild, match.index);
1948
+ range.setEnd(element.firstChild, match.index + match[0].length);
1949
+ const rects = [...range.getClientRects()].filter((rect) => rect.width > 0);
1950
+ if (new Set(rects.map((rect) => Math.round(rect.top))).size > 1) {
1951
+ split.push(match[0]);
1952
+ }
1953
+ if (range.getBoundingClientRect().width > element.clientWidth + 0.5) {
1954
+ tooWide.push(match[0]);
1955
+ }
1956
+ }
1957
+ return {
1958
+ lines: Math.round(box.height / Number.parseFloat(style.lineHeight)),
1959
+ split,
1960
+ tooWide,
1961
+ ellipsis: style.textOverflow === "ellipsis" &&
1962
+ (element.scrollWidth > element.clientWidth + 0.5 || element.scrollHeight > element.clientHeight + 0.5),
1963
+ inside: box.left >= railBox.left - 0.5 && box.right <= railBox.right + 0.5
1964
+ };
1965
+ }, text);
1966
+ const at = `at a ${railWidth}px rail`;
1967
+ assert.deepEqual(await layout("Home"), { lines: 1, split: [], tooWide: [], ellipsis: false, inside: true }, `a short word ${at}`);
1968
+ assert.deepEqual(await layout("Administration"), { lines: 1, split: [], tooWide: ["Administration"], ellipsis: true, inside: true }, `one word wider than the rail ${at}`);
1969
+ // Two words, each on its own line; one wider than the rail ends in an ellipsis.
1970
+ const twoWords = await layout("Race Engineer");
1971
+ assert.deepEqual(twoWords, { lines: 2, split: [], tooWide: twoWords.tooWide, ellipsis: twoWords.tooWide.length > 0, inside: true }, `two words ${at}`);
1972
+ if (railWidth === 80) {
1973
+ assert.deepEqual(twoWords.tooWide, [], "both words fit the default rail");
1974
+ }
1975
+ const after = await layout("Supplier Administration");
1976
+ assert.ok(after.tooWide.includes("Administration"), `"Administration" is wider than the rail ${at}`);
1977
+ assert.deepEqual({ ...after, tooWide: [] }, { lines: 2, split: [], tooWide: [], ellipsis: true, inside: true }, `a word wider than the rail after another ${at}`);
1978
+ const long = await layout("Quarterly performance and planning");
1979
+ assert.deepEqual({ ...long, tooWide: [] }, { lines: 2, split: [], tooWide: [], ellipsis: true, inside: true }, `a label that needs three lines ${at}`);
1980
+ }
1981
+ await page.close();
1982
+ });
@@ -42,17 +42,23 @@ async function activate(locator) {
42
42
  await locator.press("Enter");
43
43
  }
44
44
 
45
- // The parts of the page ShellLayout makes inert, and whether each is.
45
+ // The parts of the page ShellLayout makes inert: whether each is, and whether it is a closed modal drawer or side
46
+ // sheet, which Vuetify keeps inert of its own.
46
47
  function readPageParts(page) {
47
- return page.evaluate(() => [...document.querySelectorAll("[data-shell-page]")].map((part) => part.inert));
48
+ return page.evaluate(() => [...document.querySelectorAll("[data-shell-page]")].map((part) => ({
49
+ inert: part.inert,
50
+ closedDrawer: part.classList.contains("v-navigation-drawer--temporary") &&
51
+ !part.classList.contains("v-navigation-drawer--active")
52
+ })));
48
53
  }
49
54
 
50
- // Every part of the page, the app bar, the navigation and main at least, inert or else live.
55
+ // Every part of the page, the app bar, the navigation and main at least, inert, or else live but for a closed modal
56
+ // drawer or side sheet, which stays inert.
51
57
  async function expectPageInert(page, inert, message) {
52
58
  await expect.poll(async () => {
53
59
  const parts = await readPageParts(page);
54
- return parts.length >= 3 && parts.every((part) => part === inert);
55
- }, { message: `${message}: every part of the page ${inert ? "inert" : "live"}` }).toBe(true);
60
+ return parts.length >= 3 && parts.every((part) => part.inert === (inert || part.closedDrawer));
61
+ }, { message: `${message}: every part of the page ${inert ? "inert" : "live, a closed drawer inert"}` }).toBe(true);
56
62
  }
57
63
 
58
64
  // Whether `locator`'s element takes focus when asked, as a keyboard and assistive technology ask.
@@ -313,3 +319,68 @@ test("a tooltip open on what opens a dialog closes as the dialog opens, whether
313
319
  await expect(inviteDialog).toBeHidden();
314
320
  await page.close();
315
321
  });
322
+
323
+ test("a closed modal drawer stays inert after a dialog, and a drawer that closes or opens behind a dialog is as it is once the dialog closes", {
324
+ skip: SKIP,
325
+ timeout: 120_000
326
+ }, async (t) => {
327
+ const page = await openNotes(t, COMPACT);
328
+ const drawer = page.getByTestId("jskit-shell-drawer");
329
+ const help = drawer.getByRole("link", { name: "Help and support" });
330
+ const drawerInert = () => drawer.evaluate((element) => element.inert);
331
+ const dialog = page.getByTestId("fixture-invite-dialog");
332
+ const modal = () => expect(drawer).toHaveClass(/v-navigation-drawer--temporary/u);
333
+ const standard = () => expect(drawer).not.toHaveClass(/v-navigation-drawer--temporary/u);
334
+ assert.equal(await drawerInert(), true, "the closed modal drawer is inert");
335
+
336
+ // A dialog opens and closes over the page: the closed drawer stays inert, out of the keyboard's and assistive
337
+ // technology's reach, while the rest of the page is live again.
338
+ await activate(buttonOf(page.getByTestId("fixture-invite")));
339
+ await expectDialogOpen(page, dialog);
340
+ await expectPageInert(page, true, "with the dialog open");
341
+ await activate(page.getByTestId("fixture-invite-cancel"));
342
+ await expect(dialog).toBeHidden();
343
+ await expectPageInert(page, false, "after the dialog closes");
344
+ assert.equal(await drawerInert(), true, "the closed drawer is inert after the dialog");
345
+ assert.equal(await takesFocus(help), false, "the closed drawer's destination takes no focus");
346
+ assert.equal((await readAccessibleNames(page)).has("Help and support"), false, "assistive technology skips the closed drawer");
347
+
348
+ // The menu control still opens it, live, and Escape closes it, inert again.
349
+ await activate(page.getByTestId("jskit-shell-nav-toggle"));
350
+ await expect.poll(drawerInert, { message: "the open drawer is live" }).toBe(false);
351
+ assert.equal(await takesFocus(help), true, "the open drawer's destination takes focus");
352
+ await page.keyboard.press("Escape");
353
+ await expect.poll(drawerInert, { message: "the drawer closed by Escape is inert" }).toBe(true);
354
+
355
+ // On an expanded window the standard drawer is live. Behind a dialog it is inert, and when the window narrows it
356
+ // closes there, as a modal drawer: once the dialog closes it is the closed drawer it became, inert.
357
+ await page.setViewportSize(EXPANDED);
358
+ await standard();
359
+ await expect.poll(drawerInert, { message: "the standard drawer is live" }).toBe(false);
360
+ await activate(page.getByTestId("fixture-invite"));
361
+ await expectDialogOpen(page, dialog);
362
+ await expectPageInert(page, true, "with the dialog open on an expanded window");
363
+ await page.setViewportSize(COMPACT);
364
+ await modal();
365
+ await expectPageInert(page, true, "with the dialog open once the window narrowed");
366
+ await activate(page.getByTestId("fixture-invite-cancel"));
367
+ await expect(dialog).toBeHidden();
368
+ await expectPageInert(page, false, "after the dialog over the drawer that closed behind it");
369
+ assert.equal(await drawerInert(), true, "the drawer that closed behind the dialog is inert");
370
+ assert.equal(await takesFocus(help), false, "its destination takes no focus");
371
+
372
+ // The other way: the closed modal drawer opens as the standard drawer when the window widens behind a dialog. It is
373
+ // inert while the dialog is open and live once it closes.
374
+ await activate(buttonOf(page.getByTestId("fixture-invite")));
375
+ await expectDialogOpen(page, dialog);
376
+ await page.setViewportSize(EXPANDED);
377
+ await standard();
378
+ await expectPageInert(page, true, "with the dialog open once the window widened");
379
+ assert.equal(await takesFocus(help), false, "the drawer that opened behind the dialog takes no focus");
380
+ await activate(page.getByTestId("fixture-invite-cancel"));
381
+ await expect(dialog).toBeHidden();
382
+ await expectPageInert(page, false, "after the dialog over the drawer that opened behind it");
383
+ assert.equal(await drawerInert(), false, "the standard drawer is live");
384
+ assert.equal(await takesFocus(help), true, "its destination takes focus");
385
+ await page.close();
386
+ });