feat: add Checkbox and Radio field families

This commit is contained in:
maoyingjie
2026-10-22 09:15:27 +08:00
parent a4fb3c550a
commit bcadbeaf8c
75 changed files with 5293 additions and 22 deletions
+50
View File
@@ -144,3 +144,53 @@ it("renders disabled fieldsets and search fields without browser globals", async
expect(html).toContain('data-slot="search-field-clear-button"');
expect(html).toContain('data-disabled="true"');
});
it("renders choice groups and nested content associations without browser globals", async () => {
const {
CheckboxGroup,
Checkbox,
CheckboxContent,
RadioGroup,
Radio,
RadioContent,
Label,
Description,
} = await import("../packages/vue/src");
const html = await renderToString(
createSSRApp({
render: () =>
h("form", {}, [
h(
CheckboxGroup,
{ name: "features", defaultValue: ["a"], isRequired: true },
() => [
h(Label, {}, () => "Features"),
h(Checkbox, { value: "a" }, () =>
h(CheckboxContent, {}, () => [
"A",
h(Description, {}, () => "Nested hint"),
]),
),
],
),
h(RadioGroup, { name: "plan", defaultValue: "pro" }, () => [
h(Label, {}, () => "Plan"),
h(Radio, { value: "basic" }, () =>
h(RadioContent, {}, () => "Basic"),
),
h(Radio, { value: "pro" }, () => h(RadioContent, {}, () => "Pro")),
]),
]),
}),
);
expect(html).toContain('name="features"');
expect(html).toContain('name="plan"');
expect(html).toContain('value="pro" checked');
const ids = [...html.matchAll(/\sid="([^"]+)"/g)].map((m) => m[1]);
const refs = [
...html.matchAll(/aria-(?:labelledby|describedby)="([^"]+)"/g),
].flatMap((m) => m[1].split(" "));
expect(new Set(ids).size).toBe(ids.length);
expect(refs.length).toBeGreaterThan(2);
for (const id of refs) expect(ids).toContain(id);
});