@jskit-ai/shell-web 0.2.18 → 0.2.20
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 +2 -0
- package/fixtures/adaptive-shell/src/ActionsPage.vue +8 -3
- package/fixtures/adaptive-shell/src/App.vue +2 -1
- package/fixtures/adaptive-shell/src/StatusButton.vue +34 -1
- package/fixtures/adaptive-shell/src/main.js +5 -4
- package/package.json +4 -4
- package/src/client/components/ShellLayout.vue +60 -17
- package/src/client/components/ShellPageActionsTarget.vue +32 -5
- package/src/client/composables/useShellDrawer.js +8 -6
- package/src/client/composables/useShellTopRightOverflow.js +108 -0
- package/src/client/support/topRightOverflow.js +28 -0
- package/src/test/adaptiveShellSmoke.js +39 -9
- package/test/adaptiveShell.browser.test.js +96 -70
- package/test/settingsPlacementContract.test.js +6 -2
- package/test/topRightOverflow.test.js +31 -0
- package/test/useShellDrawer.test.js +19 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- On compact windows the top app bar moves only the top-right items it has no room for into its overflow menu: the items stay while they fit beside the whole page title, and those that don't follow the page actions into the menu, farthest from the corner first. The item nearest the corner (the account avatar) still stays unless the page's primary action takes its place, and medium and wider windows are unchanged. The bar used to decide by the window's size class alone, so a short title and three small icons went into the menu. It measures the title and its items as drawn, and again when the bar's content changes (a new title, an item's count, a page action), when the window is resized and when fonts load. Each top-right item now renders once and moves between the bar and the menu as the same component, and the menu keeps it mounted while it is closed: an item that does more than draw a button (a live count, a panel, a floating button it teleports above the navigation bar) existed only while the menu was open on a phone, and was created anew each time it moved. `ShellPageActionsTarget` keeps its `#menu` slot mounted while the menu is closed and takes `menu-items` (default true), false while the slot holds nothing to show. `ShellLayout` sizes the title's `h1` to its text, up to the room it has.
|
|
6
|
+
- `ShellLayout`'s drawer fits its labels and identity by default (what `drawerWidth="content"` did), instead of Material 3's fixed 360dp, so an app no longer wraps `ShellLayout` to get a narrow drawer. It stays within 120-360dp and, as a modal drawer, leaves 56dp of the page beside it. `drawerWidth="material"` gives Material 3's full 360dp (narrowed on a small window, as before), a number still fixes the width and `"content"` still fits it. `runAdaptiveShellSmokeCase` reads the drawer's width again while it settles, and accepts a fitted drawer at its 120dp minimum or one its identity widens past the labels.
|
|
5
7
|
- A content-sized drawer (`drawer-width="content"`) fits the identity at its top (`ShellLayout`'s `top-left` slot or the `shell-layout:top-left` outlet, such as a workspace switcher) as well as its labels. It measured only the labels, so a name longer than they were was cut to the drawer's width; the identity is now read at the width its content wants, its 12dp padding included, and the drawer takes the wider of that and the labels, up to 360dp as before.
|
|
6
8
|
- The shell's client provider starts loading the app's `src/placementTopology.js`, `src/placement.js` and `src/error.js` together instead of each after the one before; it still reads, checks and applies them in the same order, and each is still optional. Measured on the accounts starter with 60 ms of latency per request: the three arrived by 851 ms instead of 935 ms (721-790, 799-865 and 869-935 ms before, 718-851 ms together after), and the bootstrap request that follows them started 82 ms sooner.
|
|
7
9
|
- After Up or the browser's Back, the shell's attempts to focus the element that opened the page left (every 100 ms for up to 1.5 s, until the page draws it) stop at the next navigation and when focus has moved since they started. Before, they outlived both: a Back then a Forward within 1.5 s could focus a matching link or tab on the next page and take the caret from a field someone was typing in. Focus that only fell back to the page body, as when the left page's element goes away, still gets the opener.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { ref } from "vue";
|
|
3
|
-
import { RouterLink } from "vue-router";
|
|
3
|
+
import { RouterLink, useRoute } from "vue-router";
|
|
4
4
|
import ShellPageAction from "../../../src/client/components/ShellPageAction.vue";
|
|
5
5
|
import ShellPageActions from "../../../src/client/components/ShellPageActions.vue";
|
|
6
6
|
import ShellPrimaryAction from "../../../src/client/components/ShellPrimaryAction.vue";
|
|
@@ -10,13 +10,16 @@ import TitleClaim from "./TitleClaim.vue";
|
|
|
10
10
|
|
|
11
11
|
// Page actions in every form: icon-only and labelled, links that leave the app or download a file, a destructive one,
|
|
12
12
|
// an overflow one and, on compact windows, more than the bar holds; the adaptive primary action opening a dialog; and
|
|
13
|
-
// a nested component that claims the title for a while.
|
|
13
|
+
// a nested component that claims the title for a while, or a title too long for a phone's bar. `?title=` sets the
|
|
14
|
+
// page's own title.
|
|
14
15
|
const paths = usePaths();
|
|
16
|
+
const route = useRoute();
|
|
15
17
|
const log = ref([]);
|
|
16
18
|
const dialog = ref(false);
|
|
17
19
|
const panel = ref(false);
|
|
20
|
+
const longTitle = ref(false);
|
|
18
21
|
|
|
19
|
-
useShellPageTitle("Page actions");
|
|
22
|
+
useShellPageTitle(() => String(route.query.title || "Page actions"));
|
|
20
23
|
</script>
|
|
21
24
|
|
|
22
25
|
<template>
|
|
@@ -60,6 +63,8 @@ useShellPageTitle("Page actions");
|
|
|
60
63
|
</p>
|
|
61
64
|
<v-btn variant="text" data-testid="fixture-toggle-panel" @click="panel = !panel">Toggle panel</v-btn>
|
|
62
65
|
<TitleClaim v-if="panel" title="Panel title" />
|
|
66
|
+
<v-btn variant="text" data-testid="fixture-toggle-long-title" @click="longTitle = !longTitle">Toggle long title</v-btn>
|
|
67
|
+
<TitleClaim v-if="longTitle" title="Quarterly statements for every supplier" />
|
|
63
68
|
|
|
64
69
|
<v-dialog v-model="dialog" max-width="400">
|
|
65
70
|
<v-card title="New record" data-testid="fixture-new-dialog">
|
|
@@ -19,7 +19,8 @@ const surfaceLabel = computed(() => ({ admin: "Admin", account: "Account" })[sur
|
|
|
19
19
|
const themeMode = computed(() => route.query.theme === "dark" ? "dark" : "light");
|
|
20
20
|
const railWidth = computed(() => Number(route.query.railWidth) || undefined);
|
|
21
21
|
const navigationItemSpacing = computed(() => Number(route.query.navigationItemSpacing) || undefined);
|
|
22
|
-
|
|
22
|
+
// ?drawerWidth=material asks for Material 3's full drawer width; unset, the drawer fits its labels.
|
|
23
|
+
const drawerWidth = computed(() => (route.query.drawerWidth === "material" ? "material" : undefined));
|
|
23
24
|
// ?identity=<name> puts an identity at the top of the drawer, as a workspace switcher does.
|
|
24
25
|
const identity = computed(() => String(route.query.identity || ""));
|
|
25
26
|
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
|
|
2
|
+
import { onBeforeUnmount, onMounted } from "vue";
|
|
3
|
+
|
|
4
|
+
// One of the top app bar's own items (an app's tools, status or avatar), from a top-right placement. It counts its
|
|
5
|
+
// mounts and unmounts by label in window.__fixtureStatusLifecycle, so a test can tell it stays mounted wherever the
|
|
6
|
+
// bar puts it, and with `surface` it also draws a surface of its own elsewhere on the page, as an item that opens a
|
|
7
|
+
// panel or a floating button does.
|
|
3
8
|
const props = defineProps({
|
|
4
9
|
icon: {
|
|
5
10
|
type: String,
|
|
@@ -8,10 +13,38 @@ const props = defineProps({
|
|
|
8
13
|
label: {
|
|
9
14
|
type: String,
|
|
10
15
|
required: true
|
|
16
|
+
},
|
|
17
|
+
surface: {
|
|
18
|
+
type: Boolean,
|
|
19
|
+
default: false
|
|
11
20
|
}
|
|
12
21
|
});
|
|
22
|
+
|
|
23
|
+
function count(event) {
|
|
24
|
+
const lifecycle = window.__fixtureStatusLifecycle || (window.__fixtureStatusLifecycle = {});
|
|
25
|
+
const key = `${props.label} ${event}`;
|
|
26
|
+
lifecycle[key] = (lifecycle[key] || 0) + 1;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
onMounted(() => count("mounted"));
|
|
30
|
+
onBeforeUnmount(() => count("unmounted"));
|
|
13
31
|
</script>
|
|
14
32
|
|
|
15
33
|
<template>
|
|
16
34
|
<v-btn :icon="props.icon" variant="text" color="on-surface-variant" :aria-label="props.label" data-testid="fixture-status" />
|
|
35
|
+
<Teleport v-if="props.surface" to="body">
|
|
36
|
+
<div class="fixture-status-surface" data-testid="fixture-status-surface">{{ props.label }}</div>
|
|
37
|
+
</Teleport>
|
|
17
38
|
</template>
|
|
39
|
+
|
|
40
|
+
<style scoped>
|
|
41
|
+
.fixture-status-surface {
|
|
42
|
+
background: rgb(var(--v-theme-surface-container-high));
|
|
43
|
+
border-radius: 8px;
|
|
44
|
+
inset-block-end: 96px;
|
|
45
|
+
inset-inline-start: 16px;
|
|
46
|
+
padding: 4px 8px;
|
|
47
|
+
position: fixed;
|
|
48
|
+
z-index: 1;
|
|
49
|
+
}
|
|
50
|
+
</style>
|
|
@@ -208,19 +208,20 @@ const placements = [
|
|
|
208
208
|
}
|
|
209
209
|
];
|
|
210
210
|
|
|
211
|
-
// `?topRight=3` gives the top app bar three items of its own, as an app's tools, status and avatar
|
|
211
|
+
// `?topRight=3` gives the top app bar three items of its own, as an app's tools, status and avatar; the status draws a
|
|
212
|
+
// surface of its own on the page too.
|
|
212
213
|
const statusPlacements = [
|
|
213
214
|
["$settings", "Tools"],
|
|
214
|
-
["$notifications", "Status"],
|
|
215
|
+
["$notifications", "Status", true],
|
|
215
216
|
["$accountCircle", "Account"]
|
|
216
|
-
].slice(0, Number(new URLSearchParams(window.location.search).get("topRight")) || 0).map(([icon, label], index) => ({
|
|
217
|
+
].slice(0, Number(new URLSearchParams(window.location.search).get("topRight")) || 0).map(([icon, label, surface], index) => ({
|
|
217
218
|
id: `fixture.status.${index}`,
|
|
218
219
|
target: "shell.status",
|
|
219
220
|
kind: "component",
|
|
220
221
|
componentToken: "fixture.status-button",
|
|
221
222
|
surfaces: ["home", "admin"],
|
|
222
223
|
order: 10 + index,
|
|
223
|
-
props: { icon, label }
|
|
224
|
+
props: { icon, label, surface: Boolean(surface) }
|
|
224
225
|
}));
|
|
225
226
|
|
|
226
227
|
const menuRenderers = Object.freeze({ link: "fixture.surface-menu-link" });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/shell-web",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.20",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jskit test"
|
|
@@ -46,14 +46,14 @@
|
|
|
46
46
|
"./locales/en.json": "./locales/en.json"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@jskit-ai/architecture-inspector": "0.1.
|
|
49
|
+
"@jskit-ai/architecture-inspector": "0.1.14"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@jskit-ai/material-web": "0.1.
|
|
52
|
+
"@jskit-ai/material-web": "0.1.4",
|
|
53
53
|
"@vue/compiler-sfc": "3.5.44"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@jskit-ai/kernel": "0.2.
|
|
56
|
+
"@jskit-ai/kernel": "0.2.16",
|
|
57
57
|
"pinia": "^4.0.3",
|
|
58
58
|
"vue": "^3.5.44",
|
|
59
59
|
"vue-router": "^5.3.1",
|
|
@@ -6,6 +6,7 @@ import { useShellDrawer } from "../composables/useShellDrawer.js";
|
|
|
6
6
|
import { useShellOutletPlacements } from "../composables/useShellOutletPlacements.js";
|
|
7
7
|
import { useShellLayoutState } from "../composables/useShellLayoutState.js";
|
|
8
8
|
import { useShellPullToRefresh } from "../composables/useShellPullToRefresh.js";
|
|
9
|
+
import { useShellTopRightOverflow } from "../composables/useShellTopRightOverflow.js";
|
|
9
10
|
import {
|
|
10
11
|
DEFAULT_SHELL_NAVIGATION_ITEM_SPACING,
|
|
11
12
|
DEFAULT_SHELL_RAIL_WIDTH
|
|
@@ -51,10 +52,11 @@ const props = defineProps({
|
|
|
51
52
|
type: String,
|
|
52
53
|
default: "rail"
|
|
53
54
|
},
|
|
54
|
-
//
|
|
55
|
+
// "content" fits the drawer to its labels and identity, up to Material 3's 360dp; "material" is that full width and a
|
|
56
|
+
// number fixes it.
|
|
55
57
|
drawerWidth: {
|
|
56
58
|
type: [Number, String],
|
|
57
|
-
default:
|
|
59
|
+
default: "content"
|
|
58
60
|
},
|
|
59
61
|
railWidth: {
|
|
60
62
|
type: Number,
|
|
@@ -145,16 +147,25 @@ const navigationStyle = computed(() => ({
|
|
|
145
147
|
"--shell-navigation-rail-width": `${resolvedRailWidth.value}px`
|
|
146
148
|
}));
|
|
147
149
|
|
|
148
|
-
// A compact bar
|
|
149
|
-
//
|
|
150
|
-
//
|
|
150
|
+
// A compact bar moves the top-right items it has no room for beside the whole title into its overflow menu, after the
|
|
151
|
+
// page actions, farthest from the corner first; the one nearest the corner (the account menu) stays unless the page's
|
|
152
|
+
// primary action takes its place. Each item renders once and moves there and back mounted, so an item that does more
|
|
153
|
+
// than draw a button (a live count, a panel or a button it teleports elsewhere) keeps working while it is in the menu.
|
|
154
|
+
// A layout's own top-right slot stays as it is.
|
|
155
|
+
const TOP_RIGHT_MENU_ID = "jskit-shell-top-right-menu";
|
|
151
156
|
const { pageActions } = useShellAppBar();
|
|
152
157
|
const topRight = useShellOutletPlacements("shell-layout:top-right");
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
+
const appBarRow = ref(null);
|
|
159
|
+
const appBarHeadline = ref(null);
|
|
160
|
+
const topRightItems = ref(null);
|
|
161
|
+
const { inMenu: topRightInMenu } = useShellTopRightOverflow({
|
|
162
|
+
enabled: computed(() => isCompactLayout.value && !slots["top-right"]),
|
|
163
|
+
placements: topRight,
|
|
164
|
+
pageActions,
|
|
165
|
+
row: appBarRow,
|
|
166
|
+
headline: appBarHeadline,
|
|
167
|
+
items: topRightItems,
|
|
168
|
+
menuId: TOP_RIGHT_MENU_ID
|
|
158
169
|
});
|
|
159
170
|
|
|
160
171
|
function updateScrolled() {
|
|
@@ -181,7 +192,7 @@ onBeforeUnmount(() => {
|
|
|
181
192
|
data-testid="jskit-shell-app-bar"
|
|
182
193
|
:data-size-class="sizeClass"
|
|
183
194
|
>
|
|
184
|
-
<div class="shell-layout__app-bar-row">
|
|
195
|
+
<div ref="appBarRow" class="shell-layout__app-bar-row">
|
|
185
196
|
<ShellUpButton v-if="canGoUp" class="shell-layout__leading" />
|
|
186
197
|
<v-btn
|
|
187
198
|
v-else-if="toggleInAppBar"
|
|
@@ -197,20 +208,35 @@ onBeforeUnmount(() => {
|
|
|
197
208
|
@click="toggleDrawer"
|
|
198
209
|
/>
|
|
199
210
|
|
|
200
|
-
<div
|
|
211
|
+
<div
|
|
212
|
+
ref="appBarHeadline"
|
|
213
|
+
class="shell-layout__headline"
|
|
214
|
+
:class="{ 'shell-layout__headline--leading': canGoUp || toggleInAppBar }"
|
|
215
|
+
>
|
|
201
216
|
<ShellPageTitle :title="fallbackTitle" />
|
|
202
217
|
<p v-if="props.subtitle" class="shell-layout__page-subtitle">{{ text(props.subtitle) }}</p>
|
|
203
218
|
</div>
|
|
204
219
|
|
|
205
|
-
<ShellPageActionsTarget>
|
|
206
|
-
<template v-if="
|
|
207
|
-
<
|
|
220
|
+
<ShellPageActionsTarget :menu-items="topRightInMenu > 0">
|
|
221
|
+
<template v-if="topRight.length > 0 && !slots['top-right']" #menu>
|
|
222
|
+
<div :id="TOP_RIGHT_MENU_ID" class="shell-layout__top-right-menu" />
|
|
208
223
|
</template>
|
|
209
224
|
</ShellPageActionsTarget>
|
|
210
225
|
|
|
211
226
|
<slot name="top-right" :surface="resolvedSurface">
|
|
212
|
-
<div class="shell-layout__top-right">
|
|
213
|
-
|
|
227
|
+
<div ref="topRightItems" class="shell-layout__top-right">
|
|
228
|
+
<!-- One instance per item, in the bar or moved into the menu; `order` keeps the bar's order in both. -->
|
|
229
|
+
<Teleport
|
|
230
|
+
v-for="(entry, index) in topRight"
|
|
231
|
+
:key="entry.id"
|
|
232
|
+
defer
|
|
233
|
+
:to="`#${TOP_RIGHT_MENU_ID}`"
|
|
234
|
+
:disabled="index >= topRightInMenu"
|
|
235
|
+
>
|
|
236
|
+
<div class="shell-layout__top-right-item" :data-placement-id="entry.id" :style="{ order: index }">
|
|
237
|
+
<ShellOutlet target="shell-layout:top-right" :start="index" :end="index + 1" />
|
|
238
|
+
</div>
|
|
239
|
+
</Teleport>
|
|
214
240
|
</div>
|
|
215
241
|
</slot>
|
|
216
242
|
</div>
|
|
@@ -421,6 +447,12 @@ onBeforeUnmount(() => {
|
|
|
421
447
|
padding-inline-start: 4px;
|
|
422
448
|
}
|
|
423
449
|
|
|
450
|
+
/* The title's box is its text, up to the room it has, so the bar can tell how wide the whole title is. */
|
|
451
|
+
.shell-layout__headline :deep(.shell-page-title) {
|
|
452
|
+
inline-size: fit-content;
|
|
453
|
+
max-inline-size: 100%;
|
|
454
|
+
}
|
|
455
|
+
|
|
424
456
|
.shell-layout__page-subtitle {
|
|
425
457
|
color: rgb(var(--v-theme-on-surface-variant));
|
|
426
458
|
font-size: 0.75rem;
|
|
@@ -441,6 +473,17 @@ onBeforeUnmount(() => {
|
|
|
441
473
|
min-width: 0;
|
|
442
474
|
}
|
|
443
475
|
|
|
476
|
+
.shell-layout__top-right-item {
|
|
477
|
+
align-items: center;
|
|
478
|
+
display: flex;
|
|
479
|
+
flex: 0 0 auto;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/* The items in the menu are the menu panel's own, laid out by it. */
|
|
483
|
+
.shell-layout__top-right-menu {
|
|
484
|
+
display: contents;
|
|
485
|
+
}
|
|
486
|
+
|
|
444
487
|
/* Navigation rail (medium windows, and expanded ones with the drawer collapsed): 80dp, menu control on top. */
|
|
445
488
|
.shell-layout__rail,
|
|
446
489
|
.shell-layout__drawer {
|
|
@@ -1,19 +1,46 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import { computed, inject, mergeProps, useSlots } from "vue";
|
|
2
|
+
import { computed, inject, mergeProps, ref, useSlots, watch } from "vue";
|
|
3
3
|
import { useJskitText } from "../i18n.js";
|
|
4
4
|
import { SHELL_PAGE_ACTIONS_ID } from "../support/navigationPresentation.js";
|
|
5
5
|
import { NO_SHELL_PAGE_ACTIONS_REGISTRY, SHELL_PAGE_ACTIONS_REGISTRY_KEY } from "../support/pageActions.js";
|
|
6
6
|
|
|
7
7
|
// Where the current page's ShellPageActions show: after the page title in the top app bar, followed by the bar's
|
|
8
8
|
// overflow menu (Material 3's trailing "More actions" menu) when an action goes there. Its `menu` slot adds the
|
|
9
|
-
// bar's own items that don't fit (on a phone, ShellLayout's top-right items) below the actions.
|
|
9
|
+
// bar's own items that don't fit (on a phone, ShellLayout's top-right items) below the actions. The menu keeps the slot
|
|
10
|
+
// mounted while it is closed, so an item there that does more than draw a button keeps working. ShellLayout's bar has
|
|
10
11
|
// it; a layout that draws its own top app bar renders it once there and calls useShellAppBar().
|
|
12
|
+
const props = defineProps({
|
|
13
|
+
// Whether the `menu` slot holds items now. A layout that moves its items in and out of the slot keeps it and says
|
|
14
|
+
// when it holds any: with none, the menu shows only the page's actions, or no menu button without them.
|
|
15
|
+
menuItems: {
|
|
16
|
+
type: Boolean,
|
|
17
|
+
default: true
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
11
21
|
const { t } = useJskitText();
|
|
12
22
|
/** @type {import("../support/pageActions.js").ShellPageActionsRegistry} */
|
|
13
23
|
const registry = inject(SHELL_PAGE_ACTIONS_REGISTRY_KEY, NO_SHELL_PAGE_ACTIONS_REGISTRY);
|
|
14
24
|
const menuEntries = registry.menuEntries;
|
|
15
25
|
const moreLabel = computed(() => t("jskit.shell.actions.more"));
|
|
16
26
|
const slots = useSlots();
|
|
27
|
+
const menuOpen = ref(false);
|
|
28
|
+
|
|
29
|
+
// Read as the menu renders, since slots are not reactive.
|
|
30
|
+
function showsItems() {
|
|
31
|
+
return props.menuItems && Boolean(slots.menu);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function showsMenu() {
|
|
35
|
+
return menuEntries.value.length > 0 || showsItems();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Nothing left to show, such as the last item moving back to a bar that has grown: the menu closes.
|
|
39
|
+
watch(showsMenu, (shows) => {
|
|
40
|
+
if (!shows) {
|
|
41
|
+
menuOpen.value = false;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
17
44
|
|
|
18
45
|
// A menu item's props: the action's own attributes, then its label, icon, colour, link or download, and state.
|
|
19
46
|
function itemProps(entry) {
|
|
@@ -35,9 +62,9 @@ function itemProps(entry) {
|
|
|
35
62
|
|
|
36
63
|
<template>
|
|
37
64
|
<div :id="SHELL_PAGE_ACTIONS_ID" class="shell-page-actions-target" />
|
|
38
|
-
<v-menu v-if="menuEntries.length > 0 || slots.menu" location="bottom end">
|
|
65
|
+
<v-menu v-if="menuEntries.length > 0 || slots.menu" v-model="menuOpen" location="bottom end" :eager="Boolean(slots.menu)">
|
|
39
66
|
<template #activator="{ props: menuProps }">
|
|
40
|
-
<v-tooltip :text="moreLabel" location="bottom">
|
|
67
|
+
<v-tooltip v-if="showsMenu()" :text="moreLabel" location="bottom">
|
|
41
68
|
<template #activator="{ props: tooltipProps }">
|
|
42
69
|
<v-btn
|
|
43
70
|
v-bind="mergeProps(menuProps, tooltipProps)"
|
|
@@ -71,7 +98,7 @@ function itemProps(entry) {
|
|
|
71
98
|
@click="entry.activate"
|
|
72
99
|
/>
|
|
73
100
|
</v-list>
|
|
74
|
-
<div class="shell-page-actions-target__items" data-testid="jskit-shell-page-actions-overflow-items">
|
|
101
|
+
<div v-show="showsItems()" class="shell-page-actions-target__items" data-testid="jskit-shell-page-actions-overflow-items">
|
|
75
102
|
<slot name="menu" />
|
|
76
103
|
</div>
|
|
77
104
|
</v-sheet>
|
|
@@ -26,8 +26,9 @@ function navigationDrawerElement() {
|
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* The shell's navigation drawer: what opens it on each layout, how it presents, and how wide it is. The drawer is
|
|
29
|
-
* modal on compact and medium windows and a standard drawer, collapsing to a rail, on expanded ones. It
|
|
30
|
-
*
|
|
29
|
+
* modal on compact and medium windows and a standard drawer, collapsing to a rail, on expanded ones. It fits its labels
|
|
30
|
+
* and identity, within Material 3's 360dp and leaving a modal drawer's 56dp of the page, unless `drawerWidth` is
|
|
31
|
+
* "material" (Material 3's full width) or a number, which fixes it.
|
|
31
32
|
* @param {object} options
|
|
32
33
|
* @param {{ desktopDrawerClosedMode: string, drawerWidth: number | string | null, railWidth: number, navigationItemSpacing: number }} options.props
|
|
33
34
|
* @param {import("vue").Ref<boolean>} options.modalLayout
|
|
@@ -57,13 +58,14 @@ function useShellDrawer({ props, modalLayout, viewportWidth, navigationToggle, l
|
|
|
57
58
|
modal: modalLayout.value,
|
|
58
59
|
open: drawerOpen.value
|
|
59
60
|
}));
|
|
60
|
-
const fixedDrawerWidth = computed(() => props.drawerWidth
|
|
61
|
+
const fixedDrawerWidth = computed(() => !["content", null, undefined].includes(props.drawerWidth));
|
|
61
62
|
const resolvedDrawerWidth = computed(() => {
|
|
63
|
+
const materialWidth = resolveMaterialDrawerWidth({ modal: modalLayout.value, viewportWidth: viewportWidth.value });
|
|
62
64
|
if (!fixedDrawerWidth.value) {
|
|
63
|
-
return normalizeShellDrawerWidth(measuredDrawerWidth.value);
|
|
65
|
+
return Math.min(normalizeShellDrawerWidth(measuredDrawerWidth.value), materialWidth);
|
|
64
66
|
}
|
|
65
|
-
if (props.drawerWidth ===
|
|
66
|
-
return
|
|
67
|
+
if (props.drawerWidth === "material") {
|
|
68
|
+
return materialWidth;
|
|
67
69
|
}
|
|
68
70
|
return normalizeShellDrawerWidth(props.drawerWidth);
|
|
69
71
|
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from "vue";
|
|
2
|
+
import { PAGE_TITLE_ID } from "../navigation/shellNavigationRuntime.js";
|
|
3
|
+
import { resolveTopRightItemsInMenu } from "../support/topRightOverflow.js";
|
|
4
|
+
|
|
5
|
+
// Material 3's icon button: the width of an item, or of the overflow button, that the bar has not drawn yet.
|
|
6
|
+
const ICON_BUTTON_WIDTH = 48;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The title's whole width: its box when the text fits (ShellLayout sizes the h1 to its text), else the text it clips,
|
|
10
|
+
* a pixel more, since scrollWidth is a whole number and a rounding must never make a clipped title fit.
|
|
11
|
+
* @param {HTMLElement} title
|
|
12
|
+
*/
|
|
13
|
+
function wholeTitleWidth(title) {
|
|
14
|
+
return title.scrollWidth > title.clientWidth ? title.scrollWidth + 1 : title.getBoundingClientRect().width;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* How many of a compact top app bar's top-right items (from the first, the farthest from the corner) ShellLayout
|
|
19
|
+
* moves into the bar's overflow menu: as few as leave the page title whole beside the rest
|
|
20
|
+
* (resolveTopRightItemsInMenu), measured on the bar as drawn. It measures again when the bar's content changes (a new
|
|
21
|
+
* title, an item's count, a page action), when the bar is resized and when fonts load. An item in the menu keeps the
|
|
22
|
+
* width it had in the bar. Medium and wider bars, and a layout's own top-right slot, keep every item (`enabled`).
|
|
23
|
+
* @param {object} options
|
|
24
|
+
* @param {import("vue").Ref<boolean>} options.enabled
|
|
25
|
+
* @param {import("vue").Ref<readonly { id: string }[]>} options.placements The top-right placements, in bar order.
|
|
26
|
+
* @param {import("../support/pageActions.js").ShellPageActionsRegistry} options.pageActions The bar's page actions.
|
|
27
|
+
* @param {import("vue").Ref<HTMLElement | null>} options.row The bar's row, whose width is the bar's.
|
|
28
|
+
* @param {import("vue").Ref<HTMLElement | null>} options.headline The title's box.
|
|
29
|
+
* @param {import("vue").Ref<HTMLElement | null>} options.items The box of the top-right items in the bar, each a child
|
|
30
|
+
* with `data-placement-id`.
|
|
31
|
+
* @param {string} options.menuId The id of the element in the overflow menu that the items move into.
|
|
32
|
+
* @returns {{ inMenu: import("vue").ComputedRef<number> }}
|
|
33
|
+
*/
|
|
34
|
+
function useShellTopRightOverflow({ enabled, placements, pageActions, row, headline, items, menuId }) {
|
|
35
|
+
const measured = ref(0);
|
|
36
|
+
const widths = new Map();
|
|
37
|
+
let menuButtonWidth = ICON_BUTTON_WIDTH;
|
|
38
|
+
let resizeObserver = null;
|
|
39
|
+
let mutationObserver = null;
|
|
40
|
+
const keepLast = computed(() => !pageActions.hasPrimary.value);
|
|
41
|
+
const inMenu = computed(() => {
|
|
42
|
+
if (!enabled.value) {
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
return Math.min(measured.value, Math.max(placements.value.length - (keepLast.value ? 1 : 0), 0));
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
function fit() {
|
|
49
|
+
const rowElement = row.value;
|
|
50
|
+
const headlineElement = headline.value;
|
|
51
|
+
const itemsElement = items.value;
|
|
52
|
+
const title = headlineElement ? headlineElement.querySelector(`#${PAGE_TITLE_ID}`) : null;
|
|
53
|
+
// The items move into the menu only once it is there to take them.
|
|
54
|
+
if (!enabled.value || !rowElement || !itemsElement || !title || !document.getElementById(menuId)) {
|
|
55
|
+
measured.value = 0;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
let inBar = 0;
|
|
59
|
+
for (const element of itemsElement.querySelectorAll(":scope > [data-placement-id]")) {
|
|
60
|
+
const width = element.getBoundingClientRect().width;
|
|
61
|
+
widths.set(element.dataset.placementId, width);
|
|
62
|
+
inBar += width;
|
|
63
|
+
}
|
|
64
|
+
const menuButton = rowElement.querySelector(".shell-page-actions-overflow");
|
|
65
|
+
if (menuButton) {
|
|
66
|
+
menuButtonWidth = menuButton.getBoundingClientRect().width;
|
|
67
|
+
}
|
|
68
|
+
const style = window.getComputedStyle(headlineElement);
|
|
69
|
+
const titleRoom = headlineElement.clientWidth -
|
|
70
|
+
Number.parseFloat(style.paddingInlineStart) -
|
|
71
|
+
Number.parseFloat(style.paddingInlineEnd);
|
|
72
|
+
measured.value = resolveTopRightItemsInMenu({
|
|
73
|
+
room: titleRoom + inBar + (menuButton ? menuButtonWidth : 0),
|
|
74
|
+
title: wholeTitleWidth(title),
|
|
75
|
+
items: placements.value.map((entry) => widths.get(entry.id) ?? ICON_BUTTON_WIDTH),
|
|
76
|
+
menuButton: menuButtonWidth,
|
|
77
|
+
menuShown: pageActions.menuEntries.value.length > 0,
|
|
78
|
+
keepLast: keepLast.value
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
watch(
|
|
83
|
+
[enabled, () => placements.value.map((entry) => entry.id).join("\n"), keepLast, () => pageActions.menuEntries.value.length],
|
|
84
|
+
fit,
|
|
85
|
+
{ flush: "post" }
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
onMounted(() => {
|
|
89
|
+
// The row is as wide as the bar whatever its items do, so a fit in its callback never resizes what it observes.
|
|
90
|
+
resizeObserver = new ResizeObserver(fit);
|
|
91
|
+
resizeObserver.observe(row.value);
|
|
92
|
+
// A change inside the bar (the title, an item's count, a page action, an item moving) can change what fits.
|
|
93
|
+
mutationObserver = new MutationObserver(fit);
|
|
94
|
+
mutationObserver.observe(row.value, { childList: true, subtree: true, characterData: true });
|
|
95
|
+
document.fonts.addEventListener("loadingdone", fit);
|
|
96
|
+
void nextTick().then(fit);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
onBeforeUnmount(() => {
|
|
100
|
+
resizeObserver.disconnect();
|
|
101
|
+
mutationObserver.disconnect();
|
|
102
|
+
document.fonts.removeEventListener("loadingdone", fit);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
return { inMenu };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export { useShellTopRightOverflow };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How many of a compact top app bar's own items (its top-right placements, in bar order) go into its overflow menu:
|
|
3
|
+
* the fewest, farthest from the corner first, that leave the page title its whole width beside the rest, so a short
|
|
4
|
+
* title keeps every item that fits. The item nearest the corner (the account avatar) stays unless the page's primary
|
|
5
|
+
* action holds the bar's trailing place, so a title too long for the bar is clipped beside it.
|
|
6
|
+
* @param {object} options
|
|
7
|
+
* @param {number} options.room The width the title, the items in the bar and the overflow button share.
|
|
8
|
+
* @param {number} options.title The title's whole width.
|
|
9
|
+
* @param {readonly number[]} options.items Each item's width, in bar order.
|
|
10
|
+
* @param {number} options.menuButton The overflow button's width.
|
|
11
|
+
* @param {boolean} options.menuShown Whether the bar shows the overflow button anyway, for page actions in its menu.
|
|
12
|
+
* @param {boolean} options.keepLast Whether the item nearest the corner stays in the bar whatever room is left.
|
|
13
|
+
* @returns {number} How many items, from the first, are in the menu.
|
|
14
|
+
*/
|
|
15
|
+
function resolveTopRightItemsInMenu({ room, title, items, menuButton, menuShown, keepLast }) {
|
|
16
|
+
const most = Math.max(items.length - (keepLast ? 1 : 0), 0);
|
|
17
|
+
let inBar = items.reduce((total, width) => total + width, 0);
|
|
18
|
+
for (let inMenu = 0; inMenu < most; inMenu += 1) {
|
|
19
|
+
const button = menuShown || inMenu > 0 ? menuButton : 0;
|
|
20
|
+
if (title + inBar + button <= room) {
|
|
21
|
+
return inMenu;
|
|
22
|
+
}
|
|
23
|
+
inBar -= items[inMenu];
|
|
24
|
+
}
|
|
25
|
+
return most;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { resolveTopRightItemsInMenu };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { MAXIMUM_SHELL_DRAWER_WIDTH, MINIMUM_SHELL_DRAWER_WIDTH } from "../client/support/drawerWidth.js";
|
|
2
|
+
|
|
1
3
|
const DEFAULT_SMOKE_PATH = String(process.env.JSKIT_PLAYWRIGHT_SMOKE_PATH || "/home");
|
|
2
4
|
const DEFAULT_VIEWPORTS = Object.freeze([
|
|
3
5
|
Object.freeze({ name: "compact", width: 390, height: 844 }),
|
|
@@ -94,12 +96,14 @@ async function readConfiguredWidth(drawer, attribute) {
|
|
|
94
96
|
return width;
|
|
95
97
|
}
|
|
96
98
|
|
|
97
|
-
|
|
99
|
+
// The element settles at the width the drawer reports in `attribute`, read again on each poll: a drawer that fits its
|
|
100
|
+
// labels measures them once it shows, and again once the fonts load, so the width it reports can change as it opens.
|
|
101
|
+
async function expectDrawerWidth(element, expect, drawer, attribute) {
|
|
98
102
|
await expect.poll(async () => {
|
|
99
|
-
const box = await
|
|
100
|
-
return box ? Math.abs(box.width -
|
|
103
|
+
const box = await element.boundingBox();
|
|
104
|
+
return box ? Math.abs(box.width - await readConfiguredWidth(drawer, attribute)) : Number.POSITIVE_INFINITY;
|
|
101
105
|
}, {
|
|
102
|
-
message: `Shell drawer did not settle at ${
|
|
106
|
+
message: `Shell drawer did not settle at its ${attribute}.`
|
|
103
107
|
}).toBeLessThanOrEqual(1);
|
|
104
108
|
}
|
|
105
109
|
|
|
@@ -120,6 +124,18 @@ async function expectContentAwareDrawerFit(drawer, expect) {
|
|
|
120
124
|
const innerEnd = rightToLeft
|
|
121
125
|
? drawerRect.left + endBorderWidth
|
|
122
126
|
: drawerRect.right - endBorderWidth;
|
|
127
|
+
// The identity at the drawer's top (a workspace switcher) at the width its content wants, as the shell measures it.
|
|
128
|
+
const identity = element.querySelector(".shell-layout__identity");
|
|
129
|
+
let identityEndGap = null;
|
|
130
|
+
if (identity && window.getComputedStyle(identity).display !== "none") {
|
|
131
|
+
const { width, maxWidth } = identity.style;
|
|
132
|
+
identity.style.width = "max-content";
|
|
133
|
+
identity.style.maxWidth = "none";
|
|
134
|
+
const identityRect = identity.getBoundingClientRect();
|
|
135
|
+
identity.style.width = width;
|
|
136
|
+
identity.style.maxWidth = maxWidth;
|
|
137
|
+
identityEndGap = rightToLeft ? identityRect.left - innerEnd : innerEnd - identityRect.right;
|
|
138
|
+
}
|
|
123
139
|
const labels = Array.from(element.querySelectorAll(".v-list-item-title"))
|
|
124
140
|
.filter((label) => {
|
|
125
141
|
const style = window.getComputedStyle(label);
|
|
@@ -162,6 +178,8 @@ async function expectContentAwareDrawerFit(drawer, expect) {
|
|
|
162
178
|
}, null);
|
|
163
179
|
return {
|
|
164
180
|
clipped: labels.some((label) => label.clipped),
|
|
181
|
+
drawerWidth: drawerRect.width,
|
|
182
|
+
identityEndGap,
|
|
165
183
|
endGap: rightToLeft
|
|
166
184
|
? furthestLabel.logicalEnd - innerEnd
|
|
167
185
|
: innerEnd - furthestLabel.logicalEnd,
|
|
@@ -173,7 +191,19 @@ async function expectContentAwareDrawerFit(drawer, expect) {
|
|
|
173
191
|
|
|
174
192
|
expect(fit).not.toBeNull();
|
|
175
193
|
expect(fit.clipped).toBe(false);
|
|
176
|
-
expect(
|
|
194
|
+
expect(fit.endGap).toBeGreaterThanOrEqual(configuredSpacing - 1.1);
|
|
195
|
+
// The widest label ends the spacing from the drawer's end, unless the drawer is at its narrowest or the identity at its
|
|
196
|
+
// top is wider than the labels: it then ends at the drawer's end, or is cut there by the widest drawer.
|
|
197
|
+
const fittedToLabels = Math.abs(fit.endGap - configuredSpacing) <= 1.1;
|
|
198
|
+
const fittedToIdentity = fit.identityEndGap !== null && (
|
|
199
|
+
Math.abs(fit.identityEndGap) <= 1.1 ||
|
|
200
|
+
(fit.identityEndGap < 0 && fit.drawerWidth >= MAXIMUM_SHELL_DRAWER_WIDTH - 1)
|
|
201
|
+
);
|
|
202
|
+
const atMinimum = fit.drawerWidth <= MINIMUM_SHELL_DRAWER_WIDTH + 1;
|
|
203
|
+
expect(
|
|
204
|
+
fittedToLabels || fittedToIdentity || atMinimum,
|
|
205
|
+
`The drawer is ${fit.drawerWidth}px wide, its widest label ${fit.endGap}px from its end and its identity ${fit.identityEndGap}px.`
|
|
206
|
+
).toBe(true);
|
|
177
207
|
expect(fit.iconLabelGaps.length).toBeGreaterThan(0);
|
|
178
208
|
for (const gap of fit.iconLabelGaps) {
|
|
179
209
|
expect(Math.abs(gap - configuredSpacing)).toBeLessThanOrEqual(1);
|
|
@@ -345,11 +375,11 @@ async function runAdaptiveShellSmokeCase({
|
|
|
345
375
|
const rail = page.getByTestId("jskit-shell-rail");
|
|
346
376
|
await expect(rail).toBeVisible();
|
|
347
377
|
await expectElementVisibility(page, expect, "jskit-shell-drawer", false);
|
|
348
|
-
await expectDrawerWidth(rail, expect,
|
|
378
|
+
await expectDrawerWidth(rail, expect, drawer, "data-rail-width");
|
|
349
379
|
await toggle.click();
|
|
350
380
|
await expect(drawer).toHaveAttribute("data-presentation", "modal");
|
|
351
381
|
await expectElementVisibility(page, expect, "jskit-shell-drawer", true);
|
|
352
|
-
await expectDrawerWidth(drawer, expect,
|
|
382
|
+
await expectDrawerWidth(drawer, expect, drawer, "data-drawer-width");
|
|
353
383
|
const drawerIconCenters = await readNavigationIconCenters(drawer, expect);
|
|
354
384
|
await page.keyboard.press("Escape");
|
|
355
385
|
await expectElementVisibility(page, expect, "jskit-shell-drawer", false);
|
|
@@ -362,7 +392,7 @@ async function runAdaptiveShellSmokeCase({
|
|
|
362
392
|
await toggle.click();
|
|
363
393
|
}
|
|
364
394
|
await expect(drawer).toHaveAttribute("data-presentation", "drawer");
|
|
365
|
-
await expectDrawerWidth(drawer, expect,
|
|
395
|
+
await expectDrawerWidth(drawer, expect, drawer, "data-drawer-width");
|
|
366
396
|
await expectContentAwareDrawerFit(drawer, expect);
|
|
367
397
|
const expandedIconCenters = await readNavigationIconCenters(drawer, expect);
|
|
368
398
|
await page.keyboard.press("Escape");
|
|
@@ -370,7 +400,7 @@ async function runAdaptiveShellSmokeCase({
|
|
|
370
400
|
|
|
371
401
|
await toggle.click();
|
|
372
402
|
await expect(drawer).toHaveAttribute("data-presentation", "rail");
|
|
373
|
-
await expectDrawerWidth(drawer, expect,
|
|
403
|
+
await expectDrawerWidth(drawer, expect, drawer, "data-rail-width");
|
|
374
404
|
await expectCentredRailNavigation(page, drawer, expect, expandedIconCenters);
|
|
375
405
|
await expectNoHorizontalOverflow(page, expect);
|
|
376
406
|
}
|
|
@@ -269,15 +269,18 @@ test("shell-web adaptive navigation passes package-owned browser contracts", {
|
|
|
269
269
|
|
|
270
270
|
const railPage = await context.newPage();
|
|
271
271
|
await railPage.setViewportSize({ width: 1280, height: 900 });
|
|
272
|
-
|
|
272
|
+
// drawerWidth="material" asks for Material 3's full width in place of the fitted one.
|
|
273
|
+
await railPage.goto("/w/acme/admin/bookings?theme=light&drawerWidth=material");
|
|
274
|
+
await expect(railPage.getByTestId("jskit-shell-drawer")).toHaveAttribute("data-drawer-width-mode", "fixed");
|
|
273
275
|
await expect(railPage.getByTestId("jskit-shell-drawer")).toHaveAttribute("data-drawer-width", "360");
|
|
274
276
|
await assertRailKeyboardAndSelection(railPage);
|
|
275
277
|
await railPage.close();
|
|
276
278
|
|
|
279
|
+
// Without a drawerWidth the drawer fits its labels.
|
|
277
280
|
const configuredPage = await context.newPage();
|
|
278
281
|
await configuredPage.setViewportSize({ width: 1280, height: 900 });
|
|
279
282
|
await configuredPage.goto(
|
|
280
|
-
"/w/acme/admin/bookings?theme=light&railWidth=64&navigationItemSpacing=8
|
|
283
|
+
"/w/acme/admin/bookings?theme=light&railWidth=64&navigationItemSpacing=8"
|
|
281
284
|
);
|
|
282
285
|
const configuredDrawer = configuredPage.getByTestId("jskit-shell-drawer");
|
|
283
286
|
await expect(configuredDrawer).toHaveAttribute("data-navigation-item-spacing", "8");
|
|
@@ -502,15 +505,15 @@ test("a snackbar never covers the FAB, the navigation bar or a form's Save, so S
|
|
|
502
505
|
}
|
|
503
506
|
});
|
|
504
507
|
|
|
505
|
-
//
|
|
506
|
-
test("
|
|
508
|
+
// The drawer fits a long name in its identity (a workspace switcher, say) as well as its labels.
|
|
509
|
+
test("the drawer is wide enough for its identity's name", {
|
|
507
510
|
skip: RUN_BROWSER_TEST ? false : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1",
|
|
508
511
|
timeout: 90_000
|
|
509
512
|
}, async (t) => {
|
|
510
513
|
const { vite, browser } = await startFixture(t);
|
|
511
514
|
const page = await browser.newPage({ baseURL: vite.baseURL, viewport: { width: 1280, height: 900 } });
|
|
512
515
|
const name = "Northwind Regional Distribution";
|
|
513
|
-
await page.goto(`/home?
|
|
516
|
+
await page.goto(`/home?identity=${encodeURIComponent(name)}`);
|
|
514
517
|
const drawer = page.getByTestId("jskit-shell-drawer");
|
|
515
518
|
await expect(drawer).toHaveAttribute("data-presentation", "drawer");
|
|
516
519
|
await expect(drawer.getByRole("button", { name })).toBeVisible();
|
|
@@ -546,7 +549,7 @@ test("a content-sized drawer is wide enough for its identity's name", {
|
|
|
546
549
|
await settle();
|
|
547
550
|
assert.equal((await fit()).width, settled);
|
|
548
551
|
// Without the long name the drawer fits its labels again.
|
|
549
|
-
await page.goto("/home
|
|
552
|
+
await page.goto("/home");
|
|
550
553
|
await expect.poll(async () => Math.round((await drawer.boundingBox())?.width || 0)).toBeLessThan(settled);
|
|
551
554
|
await page.close();
|
|
552
555
|
});
|
|
@@ -1174,72 +1177,95 @@ test("a nested component's title gives the page's own title back, and Save retur
|
|
|
1174
1177
|
}
|
|
1175
1178
|
});
|
|
1176
1179
|
|
|
1177
|
-
test("on a phone, the bar keeps
|
|
1180
|
+
test("on a phone, the bar keeps the items that fit beside the whole title, moves the rest into its menu and keeps each one mounted", {
|
|
1178
1181
|
skip: RUN_BROWSER_TEST ? false : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1",
|
|
1179
1182
|
timeout: 90_000
|
|
1180
|
-
}, async () => {
|
|
1181
|
-
const vite = await
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1183
|
+
}, async (t) => {
|
|
1184
|
+
const { vite, browser } = await startFixture(t);
|
|
1185
|
+
const page = await browser.newPage({ baseURL: vite.baseURL, viewport: { width: 390, height: 844 } });
|
|
1186
|
+
const bar = page.getByTestId("jskit-shell-app-bar");
|
|
1187
|
+
const overflow = bar.getByTestId("jskit-shell-page-actions-overflow");
|
|
1188
|
+
const items = page.getByTestId("jskit-shell-page-actions-overflow-items");
|
|
1189
|
+
const barItems = () =>
|
|
1190
|
+
bar.locator(".shell-layout__top-right [data-testid=fixture-status]").evaluateAll((elements) =>
|
|
1191
|
+
elements.map((element) => element.getAttribute("aria-label"))
|
|
1192
|
+
);
|
|
1193
|
+
const room = () =>
|
|
1194
|
+
page.evaluate(() => {
|
|
1195
|
+
const title = document.querySelector("[data-testid=jskit-shell-page-title]");
|
|
1196
|
+
const trailing = Array.from(document.querySelectorAll("[data-testid=jskit-shell-app-bar] .v-btn")).at(-1);
|
|
1197
|
+
return {
|
|
1198
|
+
title: Math.round(title.getBoundingClientRect().width),
|
|
1199
|
+
clipped: title.scrollWidth > title.clientWidth + 1,
|
|
1200
|
+
right: Math.round(trailing.getBoundingClientRect().right)
|
|
1201
|
+
};
|
|
1202
|
+
});
|
|
1203
|
+
// Every item, in the bar or the menu, mounted once and never unmounted.
|
|
1204
|
+
const lifecycle = () => page.evaluate(() => window.__fixtureStatusLifecycle);
|
|
1205
|
+
const mountedOnce = { "Tools mounted": 1, "Status mounted": 1, "Account mounted": 1 };
|
|
1206
|
+
|
|
1207
|
+
// Tools, status and the account avatar beside a short title and the page actions' menu: all three fit, so all three
|
|
1208
|
+
// stay in the bar, and the menu holds only the page actions.
|
|
1209
|
+
await page.goto("/home/actions?topRight=3&title=Actions");
|
|
1210
|
+
await expect(shellPageTitle(page)).toHaveText("Actions");
|
|
1211
|
+
await expect.poll(barItems).toEqual(["Tools", "Status", "Account"]);
|
|
1212
|
+
await expect(bar.locator(".shell-page-action")).toHaveCount(0);
|
|
1213
|
+
const short = await room();
|
|
1214
|
+
assert.ok(!short.clipped, `the short title is whole (${short.title}px)`);
|
|
1215
|
+
assert.ok(short.right <= 390, `the avatar is in the window (${short.right}px)`);
|
|
1216
|
+
await overflow.click();
|
|
1217
|
+
await expect(page.getByRole("menu")).toBeVisible();
|
|
1218
|
+
await expect(page.getByRole("menuitem")).toHaveText(["Edit", "Export", "Open site", "Delete", "Duplicate"]);
|
|
1219
|
+
await expect(items).toBeHidden();
|
|
1220
|
+
await page.keyboard.press("Escape");
|
|
1221
|
+
await expect(page.getByRole("menu")).toBeHidden();
|
|
1222
|
+
|
|
1223
|
+
// A title too long for the bar: the items farthest from the corner move into the menu, after the page actions, and
|
|
1224
|
+
// the avatar stays. The status's own surface stays on the page while its button is in the closed menu.
|
|
1225
|
+
await page.getByTestId("fixture-toggle-long-title").click();
|
|
1226
|
+
await expect(shellPageTitle(page)).toHaveText("Quarterly statements for every supplier");
|
|
1227
|
+
await expect.poll(barItems).toEqual(["Account"]);
|
|
1228
|
+
await expect(page.getByTestId("fixture-status")).toHaveCount(3);
|
|
1229
|
+
await expect(page.getByTestId("fixture-status-surface")).toBeVisible();
|
|
1230
|
+
const long = await room();
|
|
1231
|
+
assert.ok(long.right <= 390, `the avatar is in the window (${long.right}px)`);
|
|
1232
|
+
await overflow.click();
|
|
1233
|
+
await expect(page.getByRole("menuitem")).toHaveText(["Edit", "Export", "Open site", "Delete", "Duplicate"]);
|
|
1234
|
+
await expect(items.getByTestId("fixture-status")).toHaveCount(2);
|
|
1235
|
+
await expect(items.getByRole("button", { name: "Tools", exact: true })).toBeVisible();
|
|
1236
|
+
await expect(items.getByRole("button", { name: "Status", exact: true })).toBeVisible();
|
|
1237
|
+
await page.keyboard.press("Escape");
|
|
1238
|
+
await expect(items).toBeHidden();
|
|
1239
|
+
await expect(page.getByTestId("fixture-status-surface")).toBeVisible();
|
|
1240
|
+
|
|
1241
|
+
// The short title again: the items come back to the bar.
|
|
1242
|
+
await page.getByTestId("fixture-toggle-long-title").click();
|
|
1243
|
+
await expect(shellPageTitle(page)).toHaveText("Actions");
|
|
1244
|
+
await expect.poll(barItems).toEqual(["Tools", "Status", "Account"]);
|
|
1245
|
+
assert.deepEqual(await lifecycle(), mountedOnce);
|
|
1246
|
+
|
|
1247
|
+
// A form's Save is a trailing item too: whatever does not fit beside it and the whole title, the avatar included,
|
|
1248
|
+
// is in the menu, and nothing remounts.
|
|
1249
|
+
await page.getByRole("link", { name: "New entry", exact: true }).click();
|
|
1250
|
+
await expect(bar.getByRole("button", { name: "Save", exact: true })).toBeVisible();
|
|
1251
|
+
await expect(page.getByTestId("jskit-shell-back")).toHaveAttribute("data-action", "close");
|
|
1252
|
+
await expect(page.getByTestId("fixture-status")).toHaveCount(3);
|
|
1253
|
+
const form = await room();
|
|
1254
|
+
const formItems = await barItems();
|
|
1255
|
+
assert.ok(!form.clipped || formItems.length === 0, `the form's title is whole, or the bar holds none of its items (${formItems})`);
|
|
1256
|
+
assert.ok(form.right <= 390, `the bar's trailing item is in the window (${form.right}px)`);
|
|
1257
|
+
assert.deepEqual(formItems, ["Tools", "Status", "Account"].slice(3 - formItems.length), "the bar keeps the items nearest the corner");
|
|
1258
|
+
await page.getByTestId("jskit-shell-back").click();
|
|
1259
|
+
await expect(shellPageTitle(page)).toHaveText("Actions");
|
|
1260
|
+
await expect.poll(barItems).toEqual(["Tools", "Status", "Account"]);
|
|
1261
|
+
|
|
1262
|
+
// Wider windows keep every item in the bar, the same instances.
|
|
1263
|
+
await page.setViewportSize({ width: 1280, height: 900 });
|
|
1264
|
+
await expect(bar.getByTestId("fixture-status")).toHaveCount(3);
|
|
1265
|
+
await page.setViewportSize({ width: 390, height: 844 });
|
|
1266
|
+
await expect.poll(barItems).toEqual(["Tools", "Status", "Account"]);
|
|
1267
|
+
assert.deepEqual(await lifecycle(), mountedOnce);
|
|
1268
|
+
await page.close();
|
|
1243
1269
|
});
|
|
1244
1270
|
|
|
1245
1271
|
function shellPageActionButton(page, name) {
|
|
@@ -83,11 +83,15 @@ test("shell-web shell layout registers navigation at the app layout level", asyn
|
|
|
83
83
|
assert.match(layoutSource, /const \{ pageActions \} = useShellAppBar\(\);/u);
|
|
84
84
|
assert.match(layoutSource, /<ShellUpButton v-if="canGoUp" class="shell-layout__leading" \/>/u);
|
|
85
85
|
assert.match(layoutSource, /<ShellPageTitle :title="fallbackTitle" \/>/u);
|
|
86
|
+
// Each top-right item renders once, in the bar or teleported into the overflow menu, which keeps it mounted.
|
|
86
87
|
assert.match(
|
|
87
88
|
layoutSource,
|
|
88
|
-
/<ShellPageActionsTarget>\s*<template v-if="
|
|
89
|
+
/<ShellPageActionsTarget :menu-items="topRightInMenu > 0">\s*<template v-if="topRight\.length > 0 && !slots\['top-right'\]" #menu>\s*<div :id="TOP_RIGHT_MENU_ID"/u
|
|
90
|
+
);
|
|
91
|
+
assert.match(
|
|
92
|
+
layoutSource,
|
|
93
|
+
/<Teleport\s+v-for="\(entry, index\) in topRight"[\s\S]*?:to="`#\$\{TOP_RIGHT_MENU_ID\}`"\s+:disabled="index >= topRightInMenu"\s*>[\s\S]*?<ShellOutlet target="shell-layout:top-right" :start="index" :end="index \+ 1" \/>/u
|
|
89
94
|
);
|
|
90
|
-
assert.match(layoutSource, /<ShellOutlet target="shell-layout:top-right" :start="topRightInMenu" \/>/u);
|
|
91
95
|
assert.doesNotMatch(layoutSource, /\$arrowBack|PAGE_TITLE_ID|SHELL_PAGE_ACTIONS_ID|attachShell/u);
|
|
92
96
|
|
|
93
97
|
assert.doesNotMatch(source, /<v-layout\b/);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { resolveTopRightItemsInMenu } from "../src/client/support/topRightOverflow.js";
|
|
4
|
+
|
|
5
|
+
// A 390dp phone's bar after its padding and Up arrow: 326dp for the title, three 48dp items and the 48dp overflow
|
|
6
|
+
// button that the page's actions already need.
|
|
7
|
+
const PHONE = Object.freeze({ room: 326, items: [48, 48, 48], menuButton: 48, menuShown: true, keepLast: true });
|
|
8
|
+
|
|
9
|
+
test("a compact bar keeps every top-right item that fits beside the whole title", () => {
|
|
10
|
+
assert.equal(resolveTopRightItemsInMenu({ ...PHONE, title: 70 }), 0, "a short title leaves room for all three");
|
|
11
|
+
assert.equal(resolveTopRightItemsInMenu({ ...PHONE, title: 134 }), 0, "a title that fits to the pixel");
|
|
12
|
+
assert.equal(resolveTopRightItemsInMenu({ ...PHONE, title: 135 }), 1, "the item farthest from the corner moves first");
|
|
13
|
+
assert.equal(resolveTopRightItemsInMenu({ ...PHONE, title: 190 }), 2);
|
|
14
|
+
assert.equal(resolveTopRightItemsInMenu({ ...PHONE, title: 400 }), 2, "the avatar stays beside a title too long for the bar");
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test("the overflow button the items need takes room, and a primary action lets every item go", () => {
|
|
18
|
+
// No page action in the menu: the bar draws no overflow button while every item is in it.
|
|
19
|
+
const ownMenu = { ...PHONE, menuShown: false };
|
|
20
|
+
assert.equal(resolveTopRightItemsInMenu({ ...ownMenu, title: 182 }), 0, "every item fits, with no menu button");
|
|
21
|
+
assert.equal(
|
|
22
|
+
resolveTopRightItemsInMenu({ ...ownMenu, title: 183 }),
|
|
23
|
+
2,
|
|
24
|
+
"moving one item makes room for the menu button only, so two move"
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const form = { ...PHONE, keepLast: false };
|
|
28
|
+
assert.equal(resolveTopRightItemsInMenu({ ...form, title: 70 }), 0, "beside Save, whatever fits stays");
|
|
29
|
+
assert.equal(resolveTopRightItemsInMenu({ ...form, title: 400 }), 3, "the avatar goes too when the title needs it");
|
|
30
|
+
assert.equal(resolveTopRightItemsInMenu({ ...PHONE, items: [], title: 400 }), 0);
|
|
31
|
+
});
|
|
@@ -163,8 +163,25 @@ test("Escape closes the compact drawer and returns focus to its toggle", async (
|
|
|
163
163
|
app.unmount();
|
|
164
164
|
});
|
|
165
165
|
|
|
166
|
-
test("the drawer
|
|
167
|
-
const { app, frames, isCompactLayout, result, viewportWidth } = mountDrawer(t);
|
|
166
|
+
test("without a drawerWidth the drawer fits its labels, and a modal one leaves 56dp of the page", async (t) => {
|
|
167
|
+
const { app, frames, isCompactLayout, observers, result, viewportWidth } = mountDrawer(t);
|
|
168
|
+
assert.equal(result.fixedDrawerWidth.value, false);
|
|
169
|
+
|
|
170
|
+
await runFrames(frames);
|
|
171
|
+
const fitted = 16 + LABEL_TEXT_WIDTH + 12 + 1;
|
|
172
|
+
assert.equal(result.resolvedDrawerWidth.value, fitted);
|
|
173
|
+
assert.equal(observers[0].connected, true);
|
|
174
|
+
|
|
175
|
+
isCompactLayout.value = true;
|
|
176
|
+
viewportWidth.value = 390;
|
|
177
|
+
assert.equal(result.resolvedDrawerWidth.value, fitted);
|
|
178
|
+
viewportWidth.value = 200;
|
|
179
|
+
assert.equal(result.resolvedDrawerWidth.value, 200 - 56);
|
|
180
|
+
app.unmount();
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test("drawerWidth=\"material\" is Material 3's 360dp and a modal one leaves 56dp of the page", async (t) => {
|
|
184
|
+
const { app, frames, isCompactLayout, result, viewportWidth } = mountDrawer(t, { props: { drawerWidth: "material" } });
|
|
168
185
|
assert.equal(result.fixedDrawerWidth.value, true);
|
|
169
186
|
assert.equal(result.resolvedDrawerWidth.value, 360);
|
|
170
187
|
await runFrames(frames);
|