@celestia-island/hikari 0.55.386 → 0.55.389
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/package.json +1 -1
- package/src/components/HkAdaptiveTabs.barrel.test.ts +17 -0
- package/src/components/HkAdaptiveTabs.contract.test.ts +62 -0
- package/src/components/HkAdaptiveTabs.scss +52 -0
- package/src/components/HkAdaptiveTabs.test.tsx +281 -0
- package/src/components/HkAdaptiveTabs.tsx +253 -0
- package/src/components/HkModal.open-close-scale.test.ts +119 -37
- package/src/components/HkModal.scss +42 -29
- package/src/components/HkModal.tsx +7 -5
- package/src/components/paneSwap.contract.test.ts +5 -0
- package/src/index.ts +2 -0
package/package.json
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import * as barrel from "../index";
|
|
3
|
+
import { asIndexable } from "../utils/typing";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The public barrel guard (HkAddTile.barrel.test.ts shape): the
|
|
7
|
+
* component's own tests reach it through "./HkAdaptiveTabs" — only an
|
|
8
|
+
* external consumer would notice a dropped export line.
|
|
9
|
+
*/
|
|
10
|
+
describe("the public barrel", () => {
|
|
11
|
+
it("exports the adaptive tabs under both family names", () => {
|
|
12
|
+
const hk = asIndexable(barrel.HkAdaptiveTabs);
|
|
13
|
+
expect(hk, "HkAdaptiveTabs must be re-exported").toBeTruthy();
|
|
14
|
+
expect(hk.name).toBe("HkAdaptiveTabs");
|
|
15
|
+
expect(barrel.HAdaptiveTabs).toBe(barrel.HkAdaptiveTabs);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import componentSource from "./HkAdaptiveTabs.tsx?raw";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Composition contract for the adaptive tabs (the
|
|
7
|
+
* HkNotificationBell.contract.test.ts shape): the component owns ONLY
|
|
8
|
+
* the breakpoint branch and the option rows — every surface is a
|
|
9
|
+
* shared family member, so a second popup grammar cannot grow here.
|
|
10
|
+
*/
|
|
11
|
+
function body(): string {
|
|
12
|
+
return componentSource.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe("HkAdaptiveTabs composition contract", () => {
|
|
16
|
+
it("the desktop arm IS HkTabs; the mobile arm IS HkButton + HkSelectPanel", () => {
|
|
17
|
+
const src = body();
|
|
18
|
+
expect(src).toContain("HkTabs");
|
|
19
|
+
expect(src).toContain("HkButton");
|
|
20
|
+
expect(src).toContain("HkSelectPanel");
|
|
21
|
+
// The sheet pin is exact (a sheetOnMobile={false} mutant must fail
|
|
22
|
+
// here AND the behavioral .hk-select-sheet-panel assertion).
|
|
23
|
+
expect(src).toContain("sheetOnMobile={true}"); // — sheet on phones
|
|
24
|
+
// No hand-rolled overlay machinery in this component.
|
|
25
|
+
expect(src).not.toContain("Teleport");
|
|
26
|
+
expect(src).not.toContain("ensureOverlayRoot");
|
|
27
|
+
expect(src).not.toContain("scrim");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("the branch threshold is the family's isMobile — no private width math", () => {
|
|
31
|
+
const src = body();
|
|
32
|
+
expect(src).toContain("useBreakpoint");
|
|
33
|
+
expect(src).toContain("isMobile");
|
|
34
|
+
expect(src).not.toContain("innerWidth");
|
|
35
|
+
expect(src).not.toContain("matchMedia");
|
|
36
|
+
expect(src).not.toContain("768");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("mobile rows reuse the shared option-row grammar — no second family", () => {
|
|
40
|
+
const src = body();
|
|
41
|
+
expect(src).toContain("hk-select-option");
|
|
42
|
+
expect(src).toContain("hk-menu-item-icon");
|
|
43
|
+
expect(src).toContain("hk-menu-label");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("the value contract never changes shape across the branch", () => {
|
|
47
|
+
const src = body();
|
|
48
|
+
// Both arms emit the same update; no mobile-only state shadow.
|
|
49
|
+
expect(src).toContain("update:modelValue");
|
|
50
|
+
expect(src).not.toContain("innerModel");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("badges anchor labels — never a floating mark", () => {
|
|
54
|
+
const src = body();
|
|
55
|
+
// The HkCornerBadge wraps the label span (HkTabs contract), so the
|
|
56
|
+
// badge JSX must contain the hk-menu-label class in its subtree.
|
|
57
|
+
const badgeIdx = src.indexOf("<HkCornerBadge");
|
|
58
|
+
expect(badgeIdx).toBeGreaterThan(-1);
|
|
59
|
+
const badgeBlock = src.slice(badgeIdx, badgeIdx + 500);
|
|
60
|
+
expect(badgeBlock).toContain("hk-menu-label");
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HkAdaptiveTabs chrome: the mobile trigger row and the option rows
|
|
3
|
+
* inside the HkSelectPanel surface. The rows reuse the shared
|
|
4
|
+
* `hk-select-option` / `hk-menu-*` grammar (HkSelect's own option
|
|
5
|
+
* voice, including its checked/disabled faces from the shared
|
|
6
|
+
* menu-item mixin) — this sheet only adds the trigger's caret
|
|
7
|
+
* geometry and open-state flip, never a second option-row family.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
.hk-adaptive-tabs {
|
|
11
|
+
position: relative;
|
|
12
|
+
display: inline-flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.hk-adaptive-tabs-trigger-icon {
|
|
17
|
+
display: inline-flex;
|
|
18
|
+
align-items: center;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.hk-adaptive-tabs-trigger-label {
|
|
22
|
+
max-width: 9rem;
|
|
23
|
+
overflow: hidden;
|
|
24
|
+
text-overflow: ellipsis;
|
|
25
|
+
white-space: nowrap;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.hk-adaptive-tabs-caret {
|
|
29
|
+
margin-left: var(--space-4, 0.25rem);
|
|
30
|
+
color: rgb(var(--color-text) / 55%);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.hk-adaptive-tabs-options {
|
|
34
|
+
display: flex;
|
|
35
|
+
flex-direction: column;
|
|
36
|
+
min-width: 12rem;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.hk-adaptive-tabs-option {
|
|
40
|
+
text-align: left;
|
|
41
|
+
|
|
42
|
+
/* Checked AND disabled faces come from the shared menu-item mixin the
|
|
43
|
+
`hk-select-option` grammar already composes — nothing re-styled
|
|
44
|
+
here (one emphasis, one implementation). */
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/* Open-state feedback for the trigger (the data-active hook the
|
|
48
|
+
component sets while the picker is up): the caret flips — the same
|
|
49
|
+
voice as a select field. */
|
|
50
|
+
.hk-adaptive-tabs .hk-btn[data-active] .hk-adaptive-tabs-caret {
|
|
51
|
+
transform: rotate(180deg);
|
|
52
|
+
}
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { createApp, h, nextTick } from "vue";
|
|
3
|
+
import { FileText, History, Network } from "lucide-vue-next";
|
|
4
|
+
|
|
5
|
+
import HkAdaptiveTabs from "./HkAdaptiveTabs";
|
|
6
|
+
import { setLocale } from "../i18n/context";
|
|
7
|
+
import type { TabItem } from "./HkTabs";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* HkAdaptiveTabs behavior tests (user direction 2026-11-15):
|
|
11
|
+
* - desktop arm renders the HkTabs strip and forwards picks
|
|
12
|
+
* - mobile arm (<768 via window.innerWidth + resize) collapses into a
|
|
13
|
+
* trigger showing the ACTIVE item; opening it surfaces the option
|
|
14
|
+
* rows in an HkSelectPanel surface; picking emits and closes
|
|
15
|
+
* - the `icon-${key}` slot vocabulary renders in BOTH arms
|
|
16
|
+
* - TabItem.badge anchors the row LABEL (not a floating mark)
|
|
17
|
+
* (Repo test convention: raw createApp + document queries.)
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const TABS: TabItem[] = [
|
|
21
|
+
{ key: "reports", label: "报告审阅" },
|
|
22
|
+
{ key: "nodes", label: "节点概览" },
|
|
23
|
+
{ key: "history", label: "历史记录" },
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
const mounts: Array<{ app: ReturnType<typeof createApp>; container: HTMLElement }> = [];
|
|
27
|
+
|
|
28
|
+
interface Harness {
|
|
29
|
+
values: string[];
|
|
30
|
+
container: HTMLElement;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function mountTabs(opts: {
|
|
34
|
+
tabs?: TabItem[];
|
|
35
|
+
slots?: Record<string, () => unknown>;
|
|
36
|
+
modelValue?: string;
|
|
37
|
+
} = {}): Harness {
|
|
38
|
+
const values: string[] = [];
|
|
39
|
+
const container = document.createElement("div");
|
|
40
|
+
document.body.appendChild(container);
|
|
41
|
+
let current = opts.modelValue ?? "reports";
|
|
42
|
+
const app = createApp({
|
|
43
|
+
render: () =>
|
|
44
|
+
h(HkAdaptiveTabs, {
|
|
45
|
+
modelValue: current,
|
|
46
|
+
tabs: opts.tabs ?? TABS,
|
|
47
|
+
ariaLabel: "面板",
|
|
48
|
+
"onUpdate:modelValue": (v: string) => {
|
|
49
|
+
current = v;
|
|
50
|
+
values.push(v);
|
|
51
|
+
},
|
|
52
|
+
}, opts.slots as never),
|
|
53
|
+
});
|
|
54
|
+
mounts.push({ app, container });
|
|
55
|
+
app.mount(container);
|
|
56
|
+
return { values, container };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function settle() {
|
|
60
|
+
await nextTick();
|
|
61
|
+
await new Promise((r) => setTimeout(r, 30));
|
|
62
|
+
await nextTick();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function setMobile(mobile: boolean) {
|
|
66
|
+
(window as unknown as { innerWidth: number }).innerWidth = mobile ? 500 : 1280;
|
|
67
|
+
window.dispatchEvent(new Event("resize"));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function strip(): HTMLElement | null {
|
|
71
|
+
return document.querySelector<HTMLElement>(".hk-tabs");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function trigger(): HTMLButtonElement {
|
|
75
|
+
return document.querySelector<HTMLButtonElement>(".hk-adaptive-tabs .hk-btn")!;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function optionRows(): HTMLElement[] {
|
|
79
|
+
return Array.from(document.querySelectorAll<HTMLElement>(".hk-adaptive-tabs-option"));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
afterEach(() => {
|
|
83
|
+
for (const { app, container } of mounts) {
|
|
84
|
+
app.unmount();
|
|
85
|
+
container.remove();
|
|
86
|
+
}
|
|
87
|
+
mounts.length = 0;
|
|
88
|
+
document.body
|
|
89
|
+
.querySelectorAll(".hk-select-sheet-scrim, .hk-select-panel, .hk-popover-panel")
|
|
90
|
+
.forEach((el) => el.remove());
|
|
91
|
+
setMobile(false);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe("desktop arm", () => {
|
|
95
|
+
it("renders the HkTabs strip and forwards picks", async () => {
|
|
96
|
+
const { values } = mountTabs();
|
|
97
|
+
await settle();
|
|
98
|
+
expect(strip()).toBeTruthy();
|
|
99
|
+
const history = Array.from(document.querySelectorAll<HTMLButtonElement>(".hk-tabs button"))
|
|
100
|
+
.find((b) => b.textContent?.includes("历史记录"));
|
|
101
|
+
history!.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
102
|
+
await settle();
|
|
103
|
+
expect(values).toEqual(["history"]);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("renders named icon slots in the strip", async () => {
|
|
107
|
+
mountTabs({ slots: { "icon-reports": () => h(FileText, { size: 14 }) } });
|
|
108
|
+
await settle();
|
|
109
|
+
expect(strip()?.querySelector("svg")).toBeTruthy();
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe("mobile arm", () => {
|
|
114
|
+
it("collapses into a trigger showing the ACTIVE item's label", async () => {
|
|
115
|
+
setMobile(true);
|
|
116
|
+
mountTabs({ modelValue: "nodes" });
|
|
117
|
+
await settle();
|
|
118
|
+
expect(strip()).toBeFalsy();
|
|
119
|
+
expect(trigger().textContent).toContain("节点概览");
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("opening the trigger surfaces the option rows; picking emits and closes", async () => {
|
|
123
|
+
setMobile(true);
|
|
124
|
+
const { values } = mountTabs();
|
|
125
|
+
await settle();
|
|
126
|
+
trigger().dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
127
|
+
await settle();
|
|
128
|
+
// The sheet pin (R2 S3): phones must get the BOTTOM SHEET surface,
|
|
129
|
+
// not a desktop-style popout — a sheetOnMobile={false} mutant fails
|
|
130
|
+
// this line.
|
|
131
|
+
expect(document.querySelector(".hk-select-sheet-panel")).toBeTruthy();
|
|
132
|
+
const rows = optionRows();
|
|
133
|
+
expect(rows).toHaveLength(3);
|
|
134
|
+
const checked = rows.find((r) => r.hasAttribute("data-checked"));
|
|
135
|
+
expect(checked?.textContent).toContain("报告审阅");
|
|
136
|
+
|
|
137
|
+
rows.find((r) => r.textContent?.includes("历史记录"))!
|
|
138
|
+
.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
139
|
+
await settle();
|
|
140
|
+
expect(values).toEqual(["history"]);
|
|
141
|
+
// Picking closes the popup (the surface leaves the document).
|
|
142
|
+
expect(document.querySelector(".hk-adaptive-tabs-option")).toBeFalsy();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("crossing the breakpoint while open resets the picker — no self-reopen", async () => {
|
|
146
|
+
// R2 S2 (PR #1323): the branch swap unmounts the panel before its
|
|
147
|
+
// own isMobile close watcher can run; without a reset here the next
|
|
148
|
+
// mobile mount would come up open=true and the sheet would reopen
|
|
149
|
+
// itself unbidden.
|
|
150
|
+
setMobile(true);
|
|
151
|
+
mountTabs();
|
|
152
|
+
await settle();
|
|
153
|
+
trigger().dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
154
|
+
await settle();
|
|
155
|
+
expect(document.querySelector(".hk-select-sheet-panel")).toBeTruthy();
|
|
156
|
+
|
|
157
|
+
setMobile(false);
|
|
158
|
+
await settle();
|
|
159
|
+
expect(document.querySelector(".hk-select-sheet-panel")).toBeFalsy();
|
|
160
|
+
|
|
161
|
+
setMobile(true);
|
|
162
|
+
await settle();
|
|
163
|
+
// Back on the phone arm: the sheet must stay SHUT until the user
|
|
164
|
+
// taps the trigger again.
|
|
165
|
+
expect(document.querySelector(".hk-select-sheet-panel")).toBeFalsy();
|
|
166
|
+
expect(optionRows()).toHaveLength(0);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("a disabled row swallows the click — no emit, sheet stays open", async () => {
|
|
170
|
+
setMobile(true);
|
|
171
|
+
const { values } = mountTabs({
|
|
172
|
+
tabs: [
|
|
173
|
+
{ key: "a", label: "甲" },
|
|
174
|
+
{ key: "b", label: "乙", disabled: true },
|
|
175
|
+
],
|
|
176
|
+
});
|
|
177
|
+
await settle();
|
|
178
|
+
trigger().dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
179
|
+
await settle();
|
|
180
|
+
const disabledRow = optionRows().find((r) => r.textContent?.includes("乙"))!;
|
|
181
|
+
// A REAL disabled attribute: the click never reaches the handler
|
|
182
|
+
// (the row is not actionable at all) — no emit, no close.
|
|
183
|
+
expect(disabledRow.hasAttribute("disabled")).toBe(true);
|
|
184
|
+
disabledRow.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
185
|
+
await settle();
|
|
186
|
+
expect(values).toEqual([]);
|
|
187
|
+
expect(document.querySelector(".hk-adaptive-tabs-option")).toBeTruthy();
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it("renders named icon slots in the sheet rows", async () => {
|
|
191
|
+
setMobile(true);
|
|
192
|
+
mountTabs({
|
|
193
|
+
slots: {
|
|
194
|
+
"icon-reports": () => h(FileText, { size: 14 }),
|
|
195
|
+
"icon-nodes": () => h(Network, { size: 14 }),
|
|
196
|
+
"icon-history": () => h(History, { size: 14 }),
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
await settle();
|
|
200
|
+
trigger().dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
201
|
+
await settle();
|
|
202
|
+
expect(optionRows().filter((r) => r.querySelector("svg"))).toHaveLength(3);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it("a TabItem.badge anchors the row LABEL, not a floating mark", async () => {
|
|
206
|
+
setMobile(true);
|
|
207
|
+
mountTabs({
|
|
208
|
+
tabs: [
|
|
209
|
+
{ key: "a", label: "甲", badge: { count: 3, max: 9, label: "3 条" } },
|
|
210
|
+
{ key: "b", label: "乙" },
|
|
211
|
+
],
|
|
212
|
+
});
|
|
213
|
+
await settle();
|
|
214
|
+
trigger().dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
215
|
+
await settle();
|
|
216
|
+
const rowWithBadge = optionRows().find((r) => r.textContent?.includes("甲"))!;
|
|
217
|
+
// The badge ANCHOR wrapper holds label + mark together (placement
|
|
218
|
+
// "right" = beside the label, never covering it).
|
|
219
|
+
const anchor = rowWithBadge.querySelector<HTMLElement>(".hk-corner-badge-anchor")!;
|
|
220
|
+
expect(anchor.textContent).toContain("甲");
|
|
221
|
+
expect(anchor.querySelector(".hk-corner-badge")?.textContent).toContain("3");
|
|
222
|
+
expect(anchor.querySelector(".hk-corner-badge")?.textContent).not.toContain("甲");
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it("a count-0 badge STAYS VISIBLE on the row (presence information)", async () => {
|
|
226
|
+
// The HkTabs contract (R2 S2, PR #1323): zero is presence, not
|
|
227
|
+
// noise — showZero passes through to the mobile rows too.
|
|
228
|
+
await setLocale("en");
|
|
229
|
+
setMobile(true);
|
|
230
|
+
mountTabs({
|
|
231
|
+
tabs: [{ key: "a", label: "甲", badge: { count: 0, label: "0 条" } }],
|
|
232
|
+
});
|
|
233
|
+
await settle();
|
|
234
|
+
trigger().dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
235
|
+
await settle();
|
|
236
|
+
const anchor = optionRows()[0].querySelector<HTMLElement>(".hk-corner-badge-anchor")!;
|
|
237
|
+
expect(anchor.querySelector(".hk-corner-badge")?.textContent).toContain("0");
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it("an empty-label badge renders no mark (a badge anchors a LABEL)", async () => {
|
|
241
|
+
// R3 mutation-d pin (PR #1323): dropping the `&& tab.label` guard
|
|
242
|
+
// must fail here — a badge without a label is a floating mark.
|
|
243
|
+
await setLocale("en");
|
|
244
|
+
setMobile(true);
|
|
245
|
+
mountTabs({
|
|
246
|
+
tabs: [{ key: "a", label: "", badge: { count: 2, label: "2 条" } }],
|
|
247
|
+
});
|
|
248
|
+
await settle();
|
|
249
|
+
trigger().dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
250
|
+
await settle();
|
|
251
|
+
expect(optionRows()[0].querySelector(".hk-corner-badge")).toBeFalsy();
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it("the trigger declares the popup it actually opens", async () => {
|
|
255
|
+
// R3 mutation-e pin (PR #1323): the sheet surface is a dialog —
|
|
256
|
+
// the trigger must not claim a listbox that never renders.
|
|
257
|
+
await setLocale("en");
|
|
258
|
+
setMobile(true);
|
|
259
|
+
mountTabs();
|
|
260
|
+
await settle();
|
|
261
|
+
expect(trigger().getAttribute("aria-haspopup")).toBe("dialog");
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it("warns in DEV when a badge lacks an accessible label", async () => {
|
|
265
|
+
// R4 pin (PR #1323): the mobile rows mirror HkTabs' second a11y
|
|
266
|
+
// alarm — a label-less badge is announced nowhere on the sheet.
|
|
267
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
268
|
+
try {
|
|
269
|
+
setMobile(true);
|
|
270
|
+
mountTabs({
|
|
271
|
+
tabs: [{ key: "a", label: "甲", badge: { count: 3 } }],
|
|
272
|
+
});
|
|
273
|
+
await settle();
|
|
274
|
+
const alarms = warn.mock.calls.filter((c) => String(c[0]).includes("badge without a label"));
|
|
275
|
+
expect(alarms.length, "the a11y drift alarm must fire").toBeGreaterThan(0);
|
|
276
|
+
expect(alarms[0]![1]).toBe("a");
|
|
277
|
+
} finally {
|
|
278
|
+
warn.mockRestore();
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
});
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HkAdaptiveTabs — the header/footer button group with a built-in
|
|
3
|
+
* mobile collapse (user direction 2026-11-15): ONE tab list, TWO
|
|
4
|
+
* renderings. Wide viewports (≥768) render the canonical HkTabs strip
|
|
5
|
+
* (variant passthrough, pill by default). Phone-width viewports
|
|
6
|
+
* (<768, useBreakpoint().isMobile — the sheet family's threshold)
|
|
7
|
+
* collapse the SAME list into a select-style trigger (active item's
|
|
8
|
+
* icon + label + caret) whose popup is an HkSelectPanel with
|
|
9
|
+
* `sheetOnMobile` — on phones the options rise as a bottom sheet,
|
|
10
|
+
* which is the point: a top- or bottom-anchored strip that squeezes
|
|
11
|
+
* into a scrolling sliver on a phone is space spent badly.
|
|
12
|
+
*
|
|
13
|
+
* The value contract never changes shape: `modelValue` +
|
|
14
|
+
* `update:modelValue` drive both forms, so `?tab=` deep links and
|
|
15
|
+
* store-bound values keep working across the breakpoint. The
|
|
16
|
+
* `icon-${key}` slot vocabulary of HkTabs is honored in BOTH forms
|
|
17
|
+
* (named slot wins, `TabItem.icon` vnode is the fallback), and
|
|
18
|
+
* `TabItem.badge` rides HkCornerBadge in both — beside the strip
|
|
19
|
+
* label on desktop, beside the sheet row label on mobile, with the
|
|
20
|
+
* same placement-aware offset default and `showZero` presence
|
|
21
|
+
* semantics as the strip (HkTabs contract).
|
|
22
|
+
*
|
|
23
|
+
* Composition discipline (contract test pinned): the desktop arm IS
|
|
24
|
+
* HkTabs and the mobile arm IS HkButton + HkSelectPanel — this
|
|
25
|
+
* component owns only the branch and the option rows, never popup
|
|
26
|
+
* chrome. Crossing the breakpoint while the picker is open RESETS the
|
|
27
|
+
* open flag here (R2 finding, PR #1323): the branch swap unmounts the
|
|
28
|
+
* HkSelectPanel in the same flush, so the panel's own isMobile-watcher
|
|
29
|
+
* close is stopped before it runs — unlike HkPopover, whose watcher
|
|
30
|
+
* survives because the popover stays mounted. Without the reset, the
|
|
31
|
+
* next mobile mount would come up `open=true` and the sheet would
|
|
32
|
+
* reopen itself unbidden (plus a spurious back-guard history entry).
|
|
33
|
+
*
|
|
34
|
+
* This is the DEFAULT form for page-chrome button groups anchored to
|
|
35
|
+
* the header's center slot or the footer's center slot (user ruling
|
|
36
|
+
* 2026-11-15); dynamic-list switchers with bespoke rows (the
|
|
37
|
+
* platform switcher) keep their own composition.
|
|
38
|
+
*
|
|
39
|
+
* Deliberate prop subset (R4 note, PR #1323): the HkTabs-only surface
|
|
40
|
+
* controls — `disabled` (whole strip), `scrollable`, `scrollbar`,
|
|
41
|
+
* `startAction`/`endAction`, `mergeKeys` — are NOT forwarded. Header/
|
|
42
|
+
* footer groups don't disable themselves wholesale and never carry
|
|
43
|
+
* strip decorations; if a host needs them, it wants HkTabs directly.
|
|
44
|
+
*/
|
|
45
|
+
import { ChevronDown } from "lucide-vue-next";
|
|
46
|
+
import { computed, defineComponent, ref, watch, type PropType, type VNodeChild } from "vue";
|
|
47
|
+
|
|
48
|
+
import { useBreakpoint } from "../runtime/useBreakpoint";
|
|
49
|
+
import HkButton from "./HkButton";
|
|
50
|
+
import HkCornerBadge from "./HkCornerBadge";
|
|
51
|
+
import HkSelectPanel, { type SelectPanelPlacement } from "./HkSelectPanel";
|
|
52
|
+
import HkTabs, { type TabItem } from "./HkTabs";
|
|
53
|
+
import "./HkAdaptiveTabs.scss";
|
|
54
|
+
|
|
55
|
+
export default defineComponent({
|
|
56
|
+
name: "HkAdaptiveTabs",
|
|
57
|
+
props: {
|
|
58
|
+
modelValue: { type: String, required: true },
|
|
59
|
+
tabs: { type: Array as PropType<TabItem[]>, required: true },
|
|
60
|
+
/** Strip variant on the desktop arm (HkTabs passthrough). */
|
|
61
|
+
variant: { type: String as PropType<"pill" | "segmented">, default: "pill" },
|
|
62
|
+
/** Row-filling strip on the desktop arm (HkTabs passthrough). */
|
|
63
|
+
block: { type: Boolean, default: false },
|
|
64
|
+
/** This component renders triggers only — panel slots are not
|
|
65
|
+
* managed here, so the desktop arm defaults to `renderPanels:
|
|
66
|
+
* false` (pass true only if the host supplies panel slots). */
|
|
67
|
+
renderPanels: { type: Boolean, default: false },
|
|
68
|
+
/** Accessible name for the strip / the mobile trigger / the sheet
|
|
69
|
+
* header. Required in practice — a DEV-only warning fires without
|
|
70
|
+
* it. */
|
|
71
|
+
ariaLabel: { type: String, default: undefined },
|
|
72
|
+
/** Mobile popout placement relative to the trigger (auto-flips).
|
|
73
|
+
* Header-center groups keep the default (open downward); a
|
|
74
|
+
* footer-center group passes "top-center" like the platform
|
|
75
|
+
* switcher. */
|
|
76
|
+
placement: {
|
|
77
|
+
type: String as PropType<SelectPanelPlacement>,
|
|
78
|
+
default: "bottom-start",
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
emits: {
|
|
82
|
+
"update:modelValue": (_value: string) => true,
|
|
83
|
+
},
|
|
84
|
+
setup(props, { emit, slots }) {
|
|
85
|
+
const { isMobile } = useBreakpoint();
|
|
86
|
+
const open = ref(false);
|
|
87
|
+
const wrapRef = ref<HTMLElement | null>(null);
|
|
88
|
+
|
|
89
|
+
// Branch swap = panel unmount, and the panel's own isMobile close
|
|
90
|
+
// watcher cannot survive its own unmount — see the header note.
|
|
91
|
+
// This reset IS the cross-breakpoint safety; the behavioral test
|
|
92
|
+
// pins it (widen-while-open → return to mobile → sheet stays shut).
|
|
93
|
+
watch(isMobile, () => {
|
|
94
|
+
open.value = false;
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Duplicate keys would render duplicate rows (and a Vue duplicate-key
|
|
98
|
+
// warning on phones only) — HkTabs dedupes + warns; same here.
|
|
99
|
+
const tabs = computed(() => {
|
|
100
|
+
const seen = new Set<string>();
|
|
101
|
+
const list = props.tabs.filter((t) => {
|
|
102
|
+
if (seen.has(t.key)) return false;
|
|
103
|
+
seen.add(t.key);
|
|
104
|
+
return true;
|
|
105
|
+
});
|
|
106
|
+
if (import.meta.env.DEV && list.length !== props.tabs.length) {
|
|
107
|
+
// eslint-disable-next-line no-console -- dev-only drift alarm
|
|
108
|
+
console.warn(
|
|
109
|
+
"[HkAdaptiveTabs] duplicate tab keys dropped:",
|
|
110
|
+
props.tabs.map((t) => t.key).join(", "),
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
if (import.meta.env.DEV) {
|
|
114
|
+
// HkTabs' second alarm, mirrored (R3 note, PR #1323): a badge
|
|
115
|
+
// without an accessible label renders as aria-hidden decoration
|
|
116
|
+
// — the count is announced nowhere on the mobile rows.
|
|
117
|
+
for (const t of props.tabs) {
|
|
118
|
+
if (t.badge && !t.badge.label) {
|
|
119
|
+
// eslint-disable-next-line no-console -- dev-only a11y alarm
|
|
120
|
+
console.warn(
|
|
121
|
+
"[HkAdaptiveTabs] tab badge without a label is aria-hidden — pass badge.label so the count is announced:",
|
|
122
|
+
t.key,
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return list;
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const active = computed(
|
|
131
|
+
() => tabs.value.find((t) => t.key === props.modelValue) ?? tabs.value[0],
|
|
132
|
+
);
|
|
133
|
+
if (import.meta.env.DEV && !props.ariaLabel) {
|
|
134
|
+
// eslint-disable-next-line no-console -- dev-only a11y alarm
|
|
135
|
+
console.warn("[HkAdaptiveTabs] ariaLabel is missing — the mobile trigger and sheet would be unnamed");
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** The HkTabs icon vocabulary, mirrored for the mobile rows: the
|
|
139
|
+
* named `icon-${key}` slot wins, `TabItem.icon` vnode falls back. */
|
|
140
|
+
function rowIcon(tab: TabItem): VNodeChild {
|
|
141
|
+
return slots[`icon-${tab.key}`]?.() ?? (tab.icon != null ? (tab.icon as VNodeChild) : null);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function renderMobileRows() {
|
|
145
|
+
return (
|
|
146
|
+
<div class="hk-adaptive-tabs-options">
|
|
147
|
+
{tabs.value.map((tab) => {
|
|
148
|
+
// Badge passthrough mirrors the HkTabs strip contract:
|
|
149
|
+
// showZero (count 0 is PRESENCE information), the
|
|
150
|
+
// placement-aware offset default (side marks are spaced by
|
|
151
|
+
// the wrapper, corner marks keep their 4px clearance), and
|
|
152
|
+
// the empty-label guard (a badge anchors a LABEL — no
|
|
153
|
+
// label, no badge).
|
|
154
|
+
const badgePlacement = tab.badge?.placement ?? "right";
|
|
155
|
+
const badgeOffset =
|
|
156
|
+
tab.badge?.offset ??
|
|
157
|
+
(badgePlacement === "right" || badgePlacement === "left" ? 0 : 4);
|
|
158
|
+
const label = tab.badge && tab.label ? (
|
|
159
|
+
<HkCornerBadge
|
|
160
|
+
variant={tab.badge.variant ?? "primary"}
|
|
161
|
+
count={tab.badge.count}
|
|
162
|
+
max={tab.badge.max}
|
|
163
|
+
showZero
|
|
164
|
+
label={tab.badge.label}
|
|
165
|
+
placement={badgePlacement}
|
|
166
|
+
offset={badgeOffset}
|
|
167
|
+
>
|
|
168
|
+
<span class="hk-menu-label">{tab.label}</span>
|
|
169
|
+
</HkCornerBadge>
|
|
170
|
+
) : (
|
|
171
|
+
<span class="hk-menu-label">{tab.label}</span>
|
|
172
|
+
);
|
|
173
|
+
return (
|
|
174
|
+
<button
|
|
175
|
+
key={tab.key}
|
|
176
|
+
type="button"
|
|
177
|
+
class="hk-select-option hk-adaptive-tabs-option"
|
|
178
|
+
data-checked={tab.key === props.modelValue || undefined}
|
|
179
|
+
disabled={tab.disabled || undefined}
|
|
180
|
+
data-disabled={tab.disabled || undefined}
|
|
181
|
+
onClick={() => {
|
|
182
|
+
open.value = false;
|
|
183
|
+
if (!tab.disabled && tab.key !== props.modelValue) {
|
|
184
|
+
emit("update:modelValue", tab.key);
|
|
185
|
+
}
|
|
186
|
+
}}
|
|
187
|
+
>
|
|
188
|
+
<span class="hk-menu-item-icon" aria-hidden="true">
|
|
189
|
+
{rowIcon(tab)}
|
|
190
|
+
</span>
|
|
191
|
+
{label}
|
|
192
|
+
</button>
|
|
193
|
+
);
|
|
194
|
+
})}
|
|
195
|
+
</div>
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return () => {
|
|
200
|
+
if (!isMobile.value) {
|
|
201
|
+
return (
|
|
202
|
+
<HkTabs
|
|
203
|
+
modelValue={props.modelValue}
|
|
204
|
+
onUpdate:modelValue={(v: string) => emit("update:modelValue", v)}
|
|
205
|
+
tabs={tabs.value}
|
|
206
|
+
variant={props.variant}
|
|
207
|
+
block={props.block}
|
|
208
|
+
renderPanels={props.renderPanels}
|
|
209
|
+
ariaLabel={props.ariaLabel}
|
|
210
|
+
>
|
|
211
|
+
{{ ...slots }}
|
|
212
|
+
</HkTabs>
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
const ActiveIcon = active.value ? rowIcon(active.value) : null;
|
|
216
|
+
return (
|
|
217
|
+
<span class="hk-adaptive-tabs" ref={wrapRef}>
|
|
218
|
+
<HkSelectPanel
|
|
219
|
+
open={open.value}
|
|
220
|
+
onUpdate:open={(v: boolean) => (open.value = v)}
|
|
221
|
+
anchorRef={wrapRef.value ?? null}
|
|
222
|
+
title={props.ariaLabel ?? ""}
|
|
223
|
+
placement={props.placement}
|
|
224
|
+
matchAnchorWidth={false}
|
|
225
|
+
offset={6}
|
|
226
|
+
/* The WHOLE point of the collapse: phones pick from a rising
|
|
227
|
+
bottom sheet (pinned explicitly so the behavioral test
|
|
228
|
+
can hold the line — a sheetOnMobile={false} mutant must
|
|
229
|
+
fail the .hk-select-sheet-panel assertion). */
|
|
230
|
+
sheetOnMobile={true}
|
|
231
|
+
>
|
|
232
|
+
{renderMobileRows()}
|
|
233
|
+
</HkSelectPanel>
|
|
234
|
+
<HkButton
|
|
235
|
+
variant="ghost"
|
|
236
|
+
size="sm"
|
|
237
|
+
ariaLabel={props.ariaLabel}
|
|
238
|
+
aria-haspopup="dialog"
|
|
239
|
+
aria-expanded={open.value ? "true" : "false"}
|
|
240
|
+
data-active={open.value || undefined}
|
|
241
|
+
onClick={() => {
|
|
242
|
+
open.value = !open.value;
|
|
243
|
+
}}
|
|
244
|
+
>
|
|
245
|
+
{ActiveIcon ? <span class="hk-adaptive-tabs-trigger-icon" aria-hidden="true">{ActiveIcon}</span> : null}
|
|
246
|
+
<span class="hk-adaptive-tabs-trigger-label">{active.value?.label ?? props.modelValue}</span>
|
|
247
|
+
<ChevronDown size={12} class="hk-adaptive-tabs-caret" aria-hidden="true" />
|
|
248
|
+
</HkButton>
|
|
249
|
+
</span>
|
|
250
|
+
);
|
|
251
|
+
};
|
|
252
|
+
},
|
|
253
|
+
});
|
|
@@ -3,10 +3,14 @@
|
|
|
3
3
|
* against the COMPILED stylesheet, not the source text.
|
|
4
4
|
*
|
|
5
5
|
* User direction 2026-11-07 (fifth revision, chosen from a comparison
|
|
6
|
-
* page): the whole window zooms and rises — B3. The
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* page): the whole window zooms and rises — B3. The ride lives on
|
|
7
|
+
* `transform` as a px-only translateY+scale pair; the PERMANENT centering
|
|
8
|
+
* lives on the individual `translate` property (2026-11-15 carrier split —
|
|
9
|
+
* it composes before `transform`, is never animated, and re-resolves
|
|
10
|
+
* against the live box every frame, so a mid-enter content growth can no
|
|
11
|
+
* longer seat the window on a stale ride matrix); opacity rides the same
|
|
12
|
+
* clock. The body carries NO rule in this choreography (nothing inside is
|
|
13
|
+
* ever scaled on its own).
|
|
10
14
|
*/
|
|
11
15
|
import { describe, expect, it } from "vitest";
|
|
12
16
|
import { dirname, join } from "node:path";
|
|
@@ -305,14 +309,15 @@ const RIDE = [
|
|
|
305
309
|
|
|
306
310
|
const child = (parent: MockElement, cls: string): MockElement => el([cls], parent);
|
|
307
311
|
|
|
308
|
-
const
|
|
309
|
-
"
|
|
312
|
+
const CENTERING_TRANSLATE =
|
|
313
|
+
"calc(-50% + var(--hk-modal-shift-x, 0px)) calc(-50% + var(--hk-modal-shift-y, 0px))";
|
|
310
314
|
|
|
311
|
-
/** Frame ride states: the centering translate
|
|
312
|
-
*
|
|
313
|
-
* the
|
|
314
|
-
|
|
315
|
-
const
|
|
315
|
+
/** Frame ride states: the centering translate lives on the INDIVIDUAL
|
|
316
|
+
* `translate` property (never animated, re-resolves against the live box
|
|
317
|
+
* every frame — the 2026-11-15 field fix) and only the ride legs change
|
|
318
|
+
* on `transform` (the whole window zooms about its center). */
|
|
319
|
+
const FRAME_FROM = "translateY(10px) scale(0.97)";
|
|
320
|
+
const FRAME_TO = "translateY(0) scale(1)";
|
|
316
321
|
|
|
317
322
|
/** Exact compiled transition values (winner()-normalized) — pinned whole,
|
|
318
323
|
* not by prefix: an embedded fourth time value (delay) or a smuggled extra
|
|
@@ -337,42 +342,98 @@ describe("HkModal desktop open/close contract (compiled cascade, user direction
|
|
|
337
342
|
});
|
|
338
343
|
|
|
339
344
|
it("rides the whole window on the centering translate plus a zoom pair", () => {
|
|
340
|
-
// B3 (user direction 2026-11-07, fifth revision
|
|
341
|
-
//
|
|
342
|
-
// — a compositor-only
|
|
343
|
-
//
|
|
344
|
-
//
|
|
345
|
-
//
|
|
345
|
+
// B3 (user direction 2026-11-07, fifth revision; carrier split
|
|
346
|
+
// 2026-11-15): the frame's `transform` is ONLY the ride legs
|
|
347
|
+
// (translateY+scale, percentages nowhere) — a compositor-safe px-only
|
|
348
|
+
// animation — while the PERMANENT centering lives on the individual
|
|
349
|
+
// `translate` property in every state, shift tokens included. A
|
|
350
|
+
// -50% smuggled back into any ride state is the exact regression
|
|
351
|
+
// this pins: the ride would freeze its matrices against the
|
|
352
|
+
// mount-time box again and a mid-enter content growth would seat the
|
|
353
|
+
// window low (2026-11-15 field report).
|
|
346
354
|
for (const state of [...RIDE, { name: "rest", classes: [] as string[] }]) {
|
|
347
355
|
const compressed = state.classes.some((c) =>
|
|
348
356
|
c.includes("enter-from") || c.includes("leave-to"));
|
|
349
357
|
const expected = state.classes.length === 0
|
|
350
|
-
?
|
|
358
|
+
? undefined
|
|
351
359
|
: compressed ? FRAME_FROM : FRAME_TO;
|
|
352
360
|
for (const [label, frame] of [
|
|
353
361
|
["", frameWith(...state.classes)],
|
|
354
362
|
["draggable ", draggableFrameWith(...state.classes)],
|
|
355
363
|
] as const) {
|
|
356
364
|
expect(winner(frame, "transform", DESKTOP), `${label}${state.name}`).toBe(expected);
|
|
357
|
-
|
|
365
|
+
expect(winner(frame, "translate", DESKTOP), `${label}${state.name} translate`).toBe(
|
|
366
|
+
CENTERING_TRANSLATE,
|
|
367
|
+
);
|
|
368
|
+
for (const prop of ["scale", "zoom", "rotate", "transform-origin"]) {
|
|
358
369
|
expect(winner(frame, prop, DESKTOP), `${label}${state.name} ${prop}`).toBeUndefined();
|
|
359
370
|
}
|
|
371
|
+
// The ride transform carries no percentage anywhere — the whole
|
|
372
|
+
// point of the carrier split (a % leg inside the animated
|
|
373
|
+
// property is what froze the stale centering offset).
|
|
374
|
+
if (expected !== undefined) {
|
|
375
|
+
expect(expected, `${label}${state.name} has no % leg`).not.toContain("%");
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
it("never lets the centering percentage ride the animated transform", () => {
|
|
382
|
+
// Fail-closed, selector-level and MEDIA-INDEPENDENT: every rule that
|
|
383
|
+
// names the frame — the base rule, any ride state, any media-gated
|
|
384
|
+
// duplicate — must keep the CENTERING legs (-50%, and the shift vars
|
|
385
|
+
// they are composed with) out of the ANIMATED `transform` property.
|
|
386
|
+
// They live on the `translate` longhand alone; inside a transitioned
|
|
387
|
+
// transform their matrices freeze against the mount-time box, which
|
|
388
|
+
// is the 2026-11-15 field bug verbatim. The mobile sheet's
|
|
389
|
+
// `translateY(100%)` slide is a DIFFERENT percentage by design (it
|
|
390
|
+
// docks from below the viewport and is pinned by the sheet test) and
|
|
391
|
+
// stays legal here.
|
|
392
|
+
const offenders: string[] = [];
|
|
393
|
+
for (const rule of RULES) {
|
|
394
|
+
if (!/hk-modal-content/.test(rule.selector)) continue;
|
|
395
|
+
const isRide = /hk-modal-content-(enter|leave)-(from|to|active)/.test(rule.selector);
|
|
396
|
+
for (const prop of rule.declarations.keys()) {
|
|
397
|
+
if (prop !== "transform") continue;
|
|
398
|
+
const value = (rule.declarations.get(prop) ?? "").replace(/\s+/g, " ").trim();
|
|
399
|
+
if (value === "none") continue;
|
|
400
|
+
if (value.includes("-50%")) {
|
|
401
|
+
offenders.push(`${rule.selector} { transform: ${value} } (a centering leg in the animated transform)`);
|
|
402
|
+
} else if (isRide && value.includes("var(--hk-modal-shift")) {
|
|
403
|
+
offenders.push(`${rule.selector} { transform: ${value} } (shift vars belong to the translate longhand)`);
|
|
404
|
+
}
|
|
360
405
|
}
|
|
361
406
|
}
|
|
407
|
+
expect(offenders, "the centering carrier must stay the translate longhand").toEqual([]);
|
|
408
|
+
// Known-positive self-check: the probes above must really see the ride
|
|
409
|
+
// rules (the R2-audited matcher bug made this sweep vacuous once — a
|
|
410
|
+
// matcher that matches nothing is not a green gate).
|
|
411
|
+
expect(RULES.filter((r) => /hk-modal-content-(enter|leave)-(from|to)/.test(r.selector)).length).toBeGreaterThan(0);
|
|
412
|
+
const probe = RULES.find(
|
|
413
|
+
(r) => /hk-modal-content-enter-from/.test(r.selector) && r.declarations.has("transform"),
|
|
414
|
+
);
|
|
415
|
+
expect(probe, "an enter-from transform rule exists to guard").toBeDefined();
|
|
362
416
|
});
|
|
363
417
|
|
|
364
418
|
it("never lets a transform longhand creep onto the frame", () => {
|
|
365
|
-
//
|
|
419
|
+
// The frame carries exactly ONE longhand — the centering `translate`
|
|
420
|
+
// — plus nothing else: a frame-level `scale:` / `zoom:` / `rotate:`
|
|
366
421
|
// (or an origin override) would ride the chrome on its own grammar
|
|
367
|
-
// instead of the contracted
|
|
422
|
+
// instead of the contracted ride list.
|
|
368
423
|
for (const state of RIDE) {
|
|
369
424
|
const frame = frameWith(...state.classes);
|
|
370
|
-
|
|
425
|
+
expect(winner(frame, "translate", DESKTOP), `${state.name} frame translate`).toBe(
|
|
426
|
+
CENTERING_TRANSLATE,
|
|
427
|
+
);
|
|
428
|
+
for (const prop of ["scale", "zoom", "rotate", "transform-origin"]) {
|
|
371
429
|
expect(winner(frame, prop, DESKTOP), `${state.name} frame ${prop}`).toBeUndefined();
|
|
372
430
|
}
|
|
373
431
|
// …and the same at rest, where a duplicate frame rule would re-seat it.
|
|
374
432
|
const rest = frameWith();
|
|
375
|
-
|
|
433
|
+
expect(winner(rest, "translate", DESKTOP), "rest frame translate").toBe(
|
|
434
|
+
CENTERING_TRANSLATE,
|
|
435
|
+
);
|
|
436
|
+
for (const prop of ["scale", "zoom", "rotate", "transform-origin"]) {
|
|
376
437
|
expect(winner(rest, prop, DESKTOP), `rest frame ${prop}`).toBeUndefined();
|
|
377
438
|
}
|
|
378
439
|
}
|
|
@@ -467,22 +528,27 @@ describe("HkModal desktop open/close contract (compiled cascade, user direction
|
|
|
467
528
|
expect(winner(body, "transition", DESKTOP_REDUCED)).toBe("none");
|
|
468
529
|
expect(winner(body, "will-change", DESKTOP_REDUCED)).toBe("auto");
|
|
469
530
|
expect(winner(frame, "transition", DESKTOP_REDUCED)).toBe("none");
|
|
470
|
-
// The
|
|
471
|
-
//
|
|
472
|
-
//
|
|
473
|
-
//
|
|
474
|
-
// (S3): the body flatten used to pin enter-from only).
|
|
475
|
-
expect(winner(frame, "transform", DESKTOP_REDUCED)).toBe(
|
|
531
|
+
// The ride flatten is now "no ride legs at all": the ride states drop
|
|
532
|
+
// their transform override while the centering — which lives on the
|
|
533
|
+
// individual `translate` property, outside every ride rule — keeps
|
|
534
|
+
// the desktop frame seated. Both ride directions pin (R2 finding
|
|
535
|
+
// 2026-11-06 (S3): the body flatten used to pin enter-from only).
|
|
536
|
+
expect(winner(frame, "transform", DESKTOP_REDUCED)).toBe("none");
|
|
537
|
+
expect(winner(frame, "translate", DESKTOP_REDUCED)).toBe(CENTERING_TRANSLATE);
|
|
476
538
|
const leaveEnd = frameWith("hk-modal-content-leave-to", "hk-modal-content-leave-active");
|
|
477
|
-
expect(winner(leaveEnd, "transform", DESKTOP_REDUCED)).toBe(
|
|
539
|
+
expect(winner(leaveEnd, "transform", DESKTOP_REDUCED)).toBe("none");
|
|
540
|
+
expect(winner(leaveEnd, "translate", DESKTOP_REDUCED)).toBe(CENTERING_TRANSLATE);
|
|
478
541
|
const leaveBody = child(leaveEnd, "hk-modal-body");
|
|
479
542
|
expect(winner(leaveBody, "transform", DESKTOP_REDUCED)).toBe("none");
|
|
480
543
|
// Phones flatten too: the media-independent reduce block also wins over
|
|
481
544
|
// the ≤767px sheet's translateY(100%) — a reduced-motion phone falls
|
|
482
|
-
// back to
|
|
483
|
-
// instead of a full-height slide flash.
|
|
484
|
-
|
|
485
|
-
expect(winner(
|
|
545
|
+
// back to a plain fade in place (one opacity-0 frame hides the flip)
|
|
546
|
+
// instead of a full-height slide flash. The sheet's own translate
|
|
547
|
+
// neutralization holds under reduce as well.
|
|
548
|
+
expect(winner(frame, "transform", MOBILE_REDUCED)).toBe("none");
|
|
549
|
+
expect(winner(leaveEnd, "transform", MOBILE_REDUCED)).toBe("none");
|
|
550
|
+
expect(winner(frame, "translate", MOBILE_REDUCED)).toBe("none");
|
|
551
|
+
expect(winner(leaveEnd, "translate", MOBILE_REDUCED)).toBe("none");
|
|
486
552
|
});
|
|
487
553
|
|
|
488
554
|
it("keeps the mobile sheet's translateY choreography untouched", () => {
|
|
@@ -498,6 +564,21 @@ describe("HkModal desktop open/close contract (compiled cascade, user direction
|
|
|
498
564
|
expect(winner(frameWith("hk-modal-content-leave-from", "hk-modal-content-leave-active"), "transform", MOBILE)).toBe("none");
|
|
499
565
|
const resting = frameWith();
|
|
500
566
|
expect(winner(resting, "transform", MOBILE)).toBe("none");
|
|
567
|
+
// The desktop centering `translate` is NEUTRALIZED in the sheet
|
|
568
|
+
// branch — a docked sheet anchors by top:auto/bottom/full width, and
|
|
569
|
+
// the live -50%/-50% would shift it up-left by half its own size.
|
|
570
|
+
// Pinned at all three shapes: entering, leaving, resting (the sheet
|
|
571
|
+
// rule is class-independent, but the states are where a ride rule
|
|
572
|
+
// could smuggle a translate back in).
|
|
573
|
+
for (const [name, f] of [
|
|
574
|
+
["enter-from", frame],
|
|
575
|
+
["leave-to", leaveEnd],
|
|
576
|
+
["enter-to", frameWith("hk-modal-content-enter-to", "hk-modal-content-enter-active")],
|
|
577
|
+
["leave-from", frameWith("hk-modal-content-leave-from", "hk-modal-content-leave-active")],
|
|
578
|
+
["rest", resting],
|
|
579
|
+
] as const) {
|
|
580
|
+
expect(winner(f, "translate", MOBILE), `sheet ${name} translate`).toBe("none");
|
|
581
|
+
}
|
|
501
582
|
// No content-region scale in the sheet layout — at EITHER end of the
|
|
502
583
|
// ride. The settled states used to go unpinned (a max-width block
|
|
503
584
|
// could scale the body there and no assertion noticed; R3 mutation
|
|
@@ -595,9 +676,10 @@ describe("HkModal desktop open/close contract (compiled cascade, user direction
|
|
|
595
676
|
"bottom",
|
|
596
677
|
]);
|
|
597
678
|
// The contracted transform values a ride rule may carry. Frame: the
|
|
598
|
-
//
|
|
599
|
-
//
|
|
600
|
-
|
|
679
|
+
// two px-only zoom pairs (reduced-motion flatten included — the
|
|
680
|
+
// centering lives on the `translate` longhand, outside every ride
|
|
681
|
+
// rule); body: nothing (its width is never scaled — 2026-11-07).
|
|
682
|
+
const LEGAL_FRAME = new Set([FRAME_FROM, FRAME_TO, "none"]);
|
|
601
683
|
// The body carries no transform contract any more (2026-11-07): any
|
|
602
684
|
// ride rule targeting it is an offender outright.
|
|
603
685
|
const LEGAL_BODY = new Set<string>([
|
|
@@ -123,15 +123,26 @@
|
|
|
123
123
|
z-index: 1;
|
|
124
124
|
top: 50%;
|
|
125
125
|
left: 50%;
|
|
126
|
-
// The centering translate is the frame's PERMANENT
|
|
127
|
-
//
|
|
128
|
-
//
|
|
129
|
-
//
|
|
130
|
-
//
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
126
|
+
// The centering translate is the frame's PERMANENT prefix — carried by
|
|
127
|
+
// the INDIVIDUAL `translate` property, never by `transform`. The
|
|
128
|
+
// open/close choreography animates `transform` only (a translateY +
|
|
129
|
+
// scale pair with no percentages anywhere), so a running ride's
|
|
130
|
+
// matrices are pure px and can never freeze a stale centering offset.
|
|
131
|
+
// Why this matters (2026-11-15 field report, chest: the topic window
|
|
132
|
+
// opened from the report window's footer): a window whose content grew
|
|
133
|
+
// during its enter (async detail fetch — loading spinner, then the
|
|
134
|
+
// full body) visibly sat too low — its top edge parked at the viewport
|
|
135
|
+
// midline, exactly the unparsed -50% — until the choreography ended
|
|
136
|
+
// and snapped it centered, because the promoted layer's ride matrices
|
|
137
|
+
// were resolved against the small mount-time box and the box then grew
|
|
138
|
+
// under them. With the centering on `translate` it re-resolves
|
|
139
|
+
// against the LIVE box every frame: the race has no representation
|
|
140
|
+
// left. (`translate` composes before `transform`, so the painted
|
|
141
|
+
// order — center, then ride legs, drag shift included — is
|
|
142
|
+
// unchanged. The ≤767px sheet block neutralizes it alongside its own
|
|
143
|
+
// `transform: none`.)
|
|
144
|
+
translate: calc(-50% + var(--hk-modal-shift-x, 0px))
|
|
145
|
+
calc(-50% + var(--hk-modal-shift-y, 0px));
|
|
135
146
|
width: 100%;
|
|
136
147
|
// Size changes animate instead of snapping: `height: auto` growth
|
|
137
148
|
// cannot fire a CSS transition (verified in Chromium — neither auto
|
|
@@ -192,9 +203,10 @@
|
|
|
192
203
|
// frame's layout height and read as jank on content-heavy windows. The 3%
|
|
193
204
|
// scale is imperceptible as glyph distortion while still giving the window
|
|
194
205
|
// a sense of arriving; the 10px rise adds direction. The centering
|
|
195
|
-
// translate
|
|
196
|
-
//
|
|
197
|
-
// re-
|
|
206
|
+
// translate does NOT ride here — it lives on the individual `translate`
|
|
207
|
+
// property (see the base rule), which the choreography never animates, so
|
|
208
|
+
// a mid-enter content growth re-seats the frame live instead of sliding
|
|
209
|
+
// on a stale ride matrix.
|
|
198
210
|
.hk-modal-content-enter-active {
|
|
199
211
|
transition:
|
|
200
212
|
opacity var(--hk-modal-duration, 0.42s)
|
|
@@ -224,21 +236,13 @@
|
|
|
224
236
|
// end pose) means the layer is composited before the transition's
|
|
225
237
|
// first measured frame, not one hitch later.
|
|
226
238
|
will-change: opacity, transform;
|
|
227
|
-
transform:
|
|
228
|
-
calc(-50% + var(--hk-modal-shift-x, 0px)),
|
|
229
|
-
calc(-50% + var(--hk-modal-shift-y, 0px))
|
|
230
|
-
)
|
|
231
|
-
translateY(10px) scale(0.97);
|
|
239
|
+
transform: translateY(10px) scale(0.97);
|
|
232
240
|
}
|
|
233
241
|
|
|
234
242
|
.hk-modal-content-enter-to,
|
|
235
243
|
.hk-modal-content-leave-from {
|
|
236
244
|
opacity: 1;
|
|
237
|
-
transform:
|
|
238
|
-
calc(-50% + var(--hk-modal-shift-x, 0px)),
|
|
239
|
-
calc(-50% + var(--hk-modal-shift-y, 0px))
|
|
240
|
-
)
|
|
241
|
-
translateY(0) scale(1);
|
|
245
|
+
transform: translateY(0) scale(1);
|
|
242
246
|
}
|
|
243
247
|
}
|
|
244
248
|
|
|
@@ -622,6 +626,10 @@
|
|
|
622
626
|
left: 0;
|
|
623
627
|
right: 0;
|
|
624
628
|
transform: none;
|
|
629
|
+
// The centering translate is neutralized with it: the sheet anchors
|
|
630
|
+
// by `top: auto` / `bottom` / full width, and the base rule's live
|
|
631
|
+
// -50%/-50% would shift a docked sheet up-left by half its own size.
|
|
632
|
+
translate: none;
|
|
625
633
|
// Content morphs reveal by clip instead of animating height (see
|
|
626
634
|
// useSizeMorph): the pin lands instantly and the top edge sweeps up
|
|
627
635
|
// as a paint-only clip with the box's own corner radii — the same
|
|
@@ -763,16 +771,21 @@
|
|
|
763
771
|
.hk-modal-content {
|
|
764
772
|
transition: none;
|
|
765
773
|
}
|
|
766
|
-
// The zoom choreography flattens with it: the ride states
|
|
767
|
-
//
|
|
774
|
+
// The zoom choreography flattens with it: the ride states drop their
|
|
775
|
+
// transform override entirely (same specificity as the desktop state
|
|
768
776
|
// rules above, later in the sheet, so the flattened state wins by source
|
|
769
|
-
// order — one painted frame at opacity 0 hides the flip).
|
|
777
|
+
// order — one painted frame at opacity 0 hides the flip). The centering
|
|
778
|
+
// is untouched: it lives on the `translate` longhand, outside every
|
|
779
|
+
// ride rule.
|
|
770
780
|
.hk-modal-content-enter-from,
|
|
771
781
|
.hk-modal-content-leave-to {
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
782
|
+
// The flatten is "no ride legs at all": the ride states drop their
|
|
783
|
+
// transform override and the centering — which lives on the
|
|
784
|
+
// individual `translate` property, outside every ride rule — keeps
|
|
785
|
+
// centering desktop frames untouched. Phones fall back to a plain
|
|
786
|
+
// fade in place (one opacity-0 frame hides the flip) instead of a
|
|
787
|
+
// full-height slide flash.
|
|
788
|
+
transform: none;
|
|
776
789
|
}
|
|
777
790
|
// The content region carries no transform of its own in this choreography
|
|
778
791
|
// (the whole window zooms; the body is never scaled). Belt-and-braces.
|
|
@@ -181,10 +181,11 @@ export default defineComponent({
|
|
|
181
181
|
backGuard: { type: Boolean, default: true },
|
|
182
182
|
/**
|
|
183
183
|
* Desktop-only drag: the header becomes a grab handle that moves
|
|
184
|
-
* the centered frame (
|
|
185
|
-
* --hk-modal-shift-x/y
|
|
186
|
-
*
|
|
187
|
-
*
|
|
184
|
+
* the centered frame (the shift composes into the frame's
|
|
185
|
+
* individual `translate` property via the --hk-modal-shift-x/y
|
|
186
|
+
* vars, so the enter/leave choreography — which animates only
|
|
187
|
+
* `transform` — is untouched). The mobile bottom sheet never
|
|
188
|
+
* drags. Reopening resets the shift.
|
|
188
189
|
*/
|
|
189
190
|
draggable: { type: Boolean, default: false },
|
|
190
191
|
},
|
|
@@ -212,7 +213,8 @@ export default defineComponent({
|
|
|
212
213
|
const bodyRef = ref<HTMLElement>();
|
|
213
214
|
const contentRef = ref<HTMLElement>();
|
|
214
215
|
/** Live drag shift in px (null = not dragged); mirrored onto the
|
|
215
|
-
* frame as CSS vars so the
|
|
216
|
+
* frame as CSS vars so the centering `translate` property (and the
|
|
217
|
+
* class-driven choreography) stays intact. */
|
|
216
218
|
const dragShift = ref<{ x: number; y: number } | null>(null);
|
|
217
219
|
let dragStart: { px: number; py: number; x: number; y: number } | null = null;
|
|
218
220
|
|
|
@@ -172,6 +172,11 @@ describe("pane-swap contract", () => {
|
|
|
172
172
|
// empty-action hooks (modals own their own enter/leave motion).
|
|
173
173
|
"HkAdminHeader.tsx",
|
|
174
174
|
"HkAdminTablePage.tsx",
|
|
175
|
+
// Trigger icon slots only (the `icon-${key}` vocabulary mirrored
|
|
176
|
+
// from HkTabs): decorative glyphs inside triggers and option rows,
|
|
177
|
+
// never a keyed pane — HkAdaptiveTabs renders no panels at all
|
|
178
|
+
// (renderPanels defaults false) and owns no pane-swap motion.
|
|
179
|
+
"HkAdaptiveTabs.tsx",
|
|
175
180
|
]);
|
|
176
181
|
const unexplained = slotRenders.filter((r) => !EXCEPTIONS.has(r.file));
|
|
177
182
|
expect(
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { default as HActionBar } from "./components/HkActionBar";
|
|
2
2
|
export { default as HAdaptiveDialog } from "./components/HkAdaptiveDialog";
|
|
3
|
+
export { default as HAdaptiveTabs } from "./components/HkAdaptiveTabs";
|
|
3
4
|
export { default as HAlert } from "./components/HkAlert";
|
|
4
5
|
export { default as HAltSignIn } from "./components/HkAltSignIn";
|
|
5
6
|
export { default as HAmbientLayer } from "./components/HkAmbientLayer";
|
|
@@ -751,6 +752,7 @@ export {
|
|
|
751
752
|
|
|
752
753
|
export { default as HkActionBar } from "./components/HkActionBar";
|
|
753
754
|
export { default as HkAdaptiveDialog } from "./components/HkAdaptiveDialog";
|
|
755
|
+
export { default as HkAdaptiveTabs } from "./components/HkAdaptiveTabs";
|
|
754
756
|
export { default as HkAlert } from "./components/HkAlert";
|
|
755
757
|
export { default as HkAltSignIn, type HkAltSignInEntry } from "./components/HkAltSignIn";
|
|
756
758
|
export { default as HkAmbientLayer } from "./components/HkAmbientLayer";
|