feat: migrate ListBox with virtual collection and accessible parts
This commit is contained in:
@@ -15,3 +15,5 @@ pnpm exec tsc --noEmit --strict --skipLibCheck --module esnext --moduleResolutio
|
||||
SLIDER-01 已在 `/private/tmp/heroui-slider-consumer` 完成上述检查,临时契约文件名为 `contract.ts`。默认工作区 typecheck 仍使用源码 alias,所以不能代替此独立产物检查。
|
||||
|
||||
M30–M32 增加 consume-m30-m32.mjs 和 m30-m32-contract.ts。将它们复制到同一个独立消费工程,执行运行脚本,并将契约文件加入上述两种 tsc 命令。合并后的产物还应同时通过原 NumberField/Slider 消费检查,避免只验证新加组件。
|
||||
|
||||
LISTBOX-01 增加 `consume-list-box.mjs` / `list-box-contract.ts`。同样复制到独立消费者,用两份新 tarball 安装后运行脚本,并在 NodeNext / bundler 两种模式执行契约文件。Root 的泛型 Props 曾在 Parameters 提取后退化,非法模型/模式反例与事件参数推断必须保留。
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { createSSRApp, h } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import {
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
ListBoxSection,
|
||||
Header,
|
||||
Label,
|
||||
Description,
|
||||
listboxVariants,
|
||||
listboxItemVariants,
|
||||
} from "@heroui-vue/components";
|
||||
const html = await renderToString(
|
||||
createSSRApp({
|
||||
render: () =>
|
||||
h(ListBox, { modelValue: [0], "aria-label": "People" }, () => [
|
||||
h(ListBoxSection, {}, () => [
|
||||
h(Header, {}, () => "Team"),
|
||||
h(ListBoxItem, { id: 0 }, () => [
|
||||
h(Label, {}, () => "Bob"),
|
||||
h(Description, {}, () => "Details"),
|
||||
h(ListBoxItemIndicator),
|
||||
]),
|
||||
]),
|
||||
h(ListBoxItem, { id: "0" }, () => "Fred"),
|
||||
]),
|
||||
}),
|
||||
);
|
||||
assert.equal((html.match(/aria-selected="true"/g) ?? []).length, 1);
|
||||
assert(html.includes('role="group"'));
|
||||
assert(html.includes('aria-labelledby="'));
|
||||
assert(html.includes('aria-describedby="'));
|
||||
assert(listboxVariants().includes("hv-list-box"));
|
||||
assert(
|
||||
listboxItemVariants().indicator().includes("hv-list-box-item__indicator"),
|
||||
);
|
||||
const css = readFileSync(
|
||||
new URL(import.meta.resolve("@heroui-vue/styles/css")),
|
||||
"utf8",
|
||||
);
|
||||
for (const name of [
|
||||
".hv-list-box",
|
||||
".hv-list-box-item",
|
||||
".hv-list-box-section",
|
||||
])
|
||||
assert(css.includes(name));
|
||||
console.log(
|
||||
"ListBox independent tarball: ESM, SSR, typed selection, labels and CSS passed.",
|
||||
);
|
||||
@@ -0,0 +1,38 @@
|
||||
import {
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
ListBoxSection,
|
||||
type ListBoxProps,
|
||||
type ListBoxItemProps,
|
||||
} from "@heroui-vue/components";
|
||||
const props: ListBoxProps = {
|
||||
modelValue: [0, "0"],
|
||||
selectionMode: "multiple",
|
||||
variant: "danger",
|
||||
onSelectionChange: (keys) => keys.forEach((key) => String(key)),
|
||||
};
|
||||
const item: ListBoxItemProps = { id: 0, textValue: "Zero" };
|
||||
// @ts-expect-error Vue collection models are key arrays, not scalars
|
||||
const scalar: ListBoxProps = { modelValue: 0 };
|
||||
// @ts-expect-error Keys cannot be objects
|
||||
const badKey: ListBoxProps = { modelValue: [{}] };
|
||||
// @ts-expect-error Selection mode is constrained
|
||||
const badMode: ListBoxProps = { selectionMode: "radio" };
|
||||
// @ts-expect-error Variant is constrained
|
||||
const badVariant: ListBoxItemProps = { id: "a", variant: "solid" };
|
||||
// @ts-expect-error Item identity is required
|
||||
const missing: ListBoxItemProps = { textValue: "Missing" };
|
||||
void [
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
ListBoxSection,
|
||||
props,
|
||||
item,
|
||||
scalar,
|
||||
badKey,
|
||||
badMode,
|
||||
badVariant,
|
||||
missing,
|
||||
];
|
||||
Reference in New Issue
Block a user