feat: migrate Tag, TagGroup and ErrorMessage with collection and focus contracts
Port the fixed HeroUI baseline tag/tag-group/error-message components onto the existing collection selection/registry protocols instead of a second state model. - TagGroup owns selection, disabled scope, removal requests and name/description wiring; TagGroupList renders the role=grid node and Tag renders role=row. - Removal has one path: a press inside the remove subtree is a removal request, so custom remove buttons work without a second event source; focus follows the next neighbour only after the item is actually gone. - ErrorMessage keeps the baseline slot marker and reuses the field part ids without gaining validation or aria-invalid semantics. - Ship the 12 tag-group and 2 error-message previews, both doc pages, navigation, a 35-case behavioural suite and independent tarball consumption checks.
This commit is contained in:
@@ -25,3 +25,5 @@ SELECT-01 增加 `consume-select.mjs` / `select-contract.ts`。新 tarball 安
|
||||
DATE-02 增加 `consume-date-field.mjs` / `date-field-contract.ts`。独立消费者显式安装 `@internationalized/date@3.12.4`,运行完整 ISO 时区提交/SSR/样式检查,分别用 NodeNext 与 bundler 验证 DateValue、粒度、变体、范围和 segment 的正反类型,不从源码 alias 取公共类型。
|
||||
|
||||
M35–M36 使用 `consume-m35-m36.mjs` / `m35-m36-contract.ts`,新建 `/private/tmp/heroui-m35-consumer`。pnpm 11 的本地样式 tarball override 写在消费者 `pnpm-workspace.yaml`;不依赖已弃用的 package.json pnpm 字段。分别验证 ESM/CSS、真正 node SSR、所有部件导出,以及 bundler/NodeNext 类型正反例(含 Promise 参数推断)。
|
||||
|
||||
B03 使用 `consume-b03-tag-error-message.mjs` / `b03-tag-error-message-contract.ts`,消费者目录 `/private/tmp/heroui-b03-consumer`(pnpm 11 的样式包 override 写在 `pnpm-workspace.yaml`)。验证 ESM 运行时(导出、SSR HTML 契约)、编译产物 CSS 选择器,以及 Tag/TagGroup/TagGroupList/TagRemoveButton/ErrorMessage 的正反类型(bundler 与 NodeNext)。
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
import { h } from "vue";
|
||||
import {
|
||||
ErrorMessage,
|
||||
Tag,
|
||||
TagGroup,
|
||||
TagGroupList,
|
||||
TagRemoveButton,
|
||||
type TagGroupProps,
|
||||
type TagGroupListProps,
|
||||
type TagKey,
|
||||
type TagProps,
|
||||
type TagRemoveButtonProps,
|
||||
type TagRenderState,
|
||||
type ErrorMessageProps,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const key: TagKey = "news";
|
||||
const numericKey: TagKey = 0;
|
||||
// @ts-expect-error collection keys are strings or finite numbers
|
||||
const invalidKey: TagKey = {};
|
||||
|
||||
const groupProps: TagGroupProps = {
|
||||
selectionMode: "multiple",
|
||||
modelValue: [key, numericKey],
|
||||
defaultValue: [],
|
||||
disabledKeys: [key],
|
||||
isDisabled: false,
|
||||
disallowEmptySelection: true,
|
||||
size: "lg",
|
||||
variant: "surface",
|
||||
dir: "rtl",
|
||||
as: "section",
|
||||
asChild: false,
|
||||
};
|
||||
// @ts-expect-error selectionMode is a closed union
|
||||
const badMode: TagGroupProps = { selectionMode: "triple" };
|
||||
// @ts-expect-error size is a closed union
|
||||
const badSize: TagGroupProps = { size: "xl" };
|
||||
|
||||
// `items` keeps the caller's item type: extra fields are allowed and reach the
|
||||
// scoped slot unchanged.
|
||||
const listProps: TagGroupListProps<{ id: string; name: string }> = {
|
||||
items: [{ id: "a", name: "A" }],
|
||||
as: "div",
|
||||
};
|
||||
// @ts-expect-error items must carry a collection key
|
||||
const listPropsWithoutId: TagGroupListProps<{ name: string }> = {
|
||||
items: [{ name: "A" }],
|
||||
};
|
||||
|
||||
const tagProps: TagProps = { id: key, textValue: "资讯", isDisabled: false };
|
||||
const removeProps: TagRemoveButtonProps = {
|
||||
textValue: "资讯",
|
||||
isDisabled: true,
|
||||
};
|
||||
// ErrorMessage declares no props of its own: content, `id` and `class` are
|
||||
// ordinary attributes / slots.
|
||||
const messageProps: ErrorMessageProps = {};
|
||||
|
||||
const state: TagRenderState = {
|
||||
isSelected: true,
|
||||
isDisabled: false,
|
||||
isHovered: false,
|
||||
isPressed: false,
|
||||
isFocused: true,
|
||||
isFocusVisible: true,
|
||||
allowsRemoving: true,
|
||||
};
|
||||
|
||||
const tree = h(
|
||||
TagGroup,
|
||||
{
|
||||
selectionMode: "single",
|
||||
modelValue: [key],
|
||||
"onUpdate:modelValue": (keys: TagKey[]) => keys.length,
|
||||
onSelectionChange: (keys: TagKey[]) => keys,
|
||||
onRemove: (keys: TagKey[]) => keys,
|
||||
},
|
||||
{
|
||||
default: () => [
|
||||
h(TagGroupList, null, {
|
||||
default: () =>
|
||||
h(
|
||||
Tag,
|
||||
{ id: key },
|
||||
{
|
||||
default: (tagState: TagRenderState) =>
|
||||
tagState.isSelected ? "selected" : "tag",
|
||||
},
|
||||
),
|
||||
empty: () =>
|
||||
h(ErrorMessage, { ...messageProps, id: "error" }, () => "empty"),
|
||||
}),
|
||||
h(Tag, tagProps, {
|
||||
default: () => [
|
||||
"资讯",
|
||||
h(TagRemoveButton, removeProps, { default: () => "x" }),
|
||||
],
|
||||
}),
|
||||
h(ErrorMessage, null, () => "请选择"),
|
||||
],
|
||||
},
|
||||
);
|
||||
|
||||
// @ts-expect-error Tag requires a collection key
|
||||
const missingId = h(Tag, {});
|
||||
|
||||
// @ts-expect-error remove button text must be a string
|
||||
const badRemoveText = h(TagRemoveButton, { textValue: 1 });
|
||||
|
||||
void [
|
||||
listPropsWithoutId,
|
||||
invalidKey,
|
||||
badMode,
|
||||
badSize,
|
||||
state,
|
||||
tree,
|
||||
missingId,
|
||||
badRemoveText,
|
||||
groupProps,
|
||||
];
|
||||
@@ -0,0 +1,88 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { createSSRApp, h } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import * as lib from "@heroui-vue/components";
|
||||
|
||||
for (const name of [
|
||||
"TagGroup",
|
||||
"TagGroupList",
|
||||
"Tag",
|
||||
"TagRemoveButton",
|
||||
"ErrorMessage",
|
||||
"tagVariants",
|
||||
"tagGroupVariants",
|
||||
"errorMessageVariants",
|
||||
])
|
||||
assert(lib[name], name);
|
||||
|
||||
const html = await renderToString(
|
||||
createSSRApp({
|
||||
render: () =>
|
||||
h(
|
||||
lib.TagGroup,
|
||||
{
|
||||
"aria-label": "分类",
|
||||
selectionMode: "multiple",
|
||||
modelValue: ["news"],
|
||||
onRemove: () => {},
|
||||
},
|
||||
{
|
||||
default: () => [
|
||||
h(lib.TagGroupList, null, {
|
||||
default: () => [
|
||||
h(lib.Tag, { id: "news" }, { default: () => "资讯" }),
|
||||
h(
|
||||
lib.Tag,
|
||||
{ id: 0, isDisabled: true },
|
||||
{ default: () => "零" },
|
||||
),
|
||||
],
|
||||
}),
|
||||
h(lib.ErrorMessage, null, { default: () => "请至少选择一项" }),
|
||||
],
|
||||
},
|
||||
),
|
||||
}),
|
||||
);
|
||||
|
||||
assert(html.includes('role="grid"'), "grid role on the list");
|
||||
assert(html.includes('aria-label="分类"'), "grid carries the group label");
|
||||
assert(html.includes('aria-multiselectable="true"'), "multiple selection flag");
|
||||
assert(html.includes('role="row"'), "rows for tags");
|
||||
assert(html.includes('aria-selected="true"'), "accepted selection");
|
||||
assert(html.includes('aria-disabled="true"'), "disabled tag");
|
||||
assert(html.includes("Remove tag 资讯"), "composed remove button name");
|
||||
assert(html.includes('data-slot="tag-remove-button"'), "remove button slot");
|
||||
assert(html.includes('data-slot="error-message"'), "error message slot");
|
||||
assert(html.includes('slot="errorMessage"'), "baseline error message marker");
|
||||
|
||||
const css = readFileSync(
|
||||
"node_modules/@heroui-vue/styles/dist/styles.css",
|
||||
"utf8",
|
||||
);
|
||||
for (const rule of [
|
||||
".hv-tag",
|
||||
".hv-tag--sm",
|
||||
".hv-tag--lg",
|
||||
".hv-tag--surface",
|
||||
".hv-tag__remove-button",
|
||||
".hv-tag-group",
|
||||
".hv-tag-group__list",
|
||||
".hv-error-message",
|
||||
])
|
||||
assert(css.includes(rule), `missing CSS rule ${rule}`);
|
||||
// The list padding rule must survive minification for Description/ErrorMessage.
|
||||
assert(
|
||||
/\.hv-tag-group\s*\[data-slot=["']?error-message/.test(css),
|
||||
"missing tag-group error-message padding rule",
|
||||
);
|
||||
|
||||
assert.equal(typeof lib.tagVariants({ size: "sm" }).base, "function");
|
||||
assert(lib.tagVariants({ size: "sm" }).base().includes("hv-tag--sm"));
|
||||
assert(
|
||||
lib.tagVariants({ variant: "surface" }).base().includes("hv-tag--surface"),
|
||||
);
|
||||
assert(lib.errorMessageVariants().includes("hv-error-message"));
|
||||
|
||||
console.log("B03 tag/error-message consumption OK");
|
||||
Reference in New Issue
Block a user