fix: retain fallback ColorSwatch ids on slot roots

This commit is contained in:
maoyingjie
2026-10-26 13:43:39 +08:00
parent b18949c071
commit d74ad1b711
5 changed files with 28 additions and 13 deletions
@@ -9,7 +9,8 @@ afterEach(() => {
document.body.innerHTML = "";
});
it("keeps asChild self-labelledby attached to the actual root ID", async () => {
const id = ref("child-id");
const id = ref<string | undefined>("child-id");
const childRef = ref<HTMLElement | null>(null);
const w = mount(
defineComponent({
setup: () => () =>
@@ -19,7 +20,7 @@ it("keeps asChild self-labelledby attached to the actual root ID", async () => {
ColorSwatch,
{ asChild: true, color: "#0485F7", "aria-labelledby": "caption" },
{
default: () => h("div", { id: id.value }),
default: () => h("div", { id: id.value, ref: childRef }),
},
),
]),
@@ -36,6 +37,13 @@ it("keeps asChild self-labelledby attached to the actual root ID", async () => {
expect(root.attributes("aria-labelledby")).toBe(
`${root.attributes("id")} caption`,
);
id.value = undefined;
await nextTick();
expect(root.attributes("id")).toBeTruthy();
expect(childRef.value).toBe(root.element);
expect(root.attributes("aria-labelledby")).toBe(
`${root.attributes("id")} caption`,
);
});
it("retains ordinary template styles together with styleFn", () => {
const w = mount(