fix: preserve ColorSwatch asChild ids and merged styles
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import { afterEach, expect, it } from "vitest";
|
||||
import { mount } from "@vue/test-utils";
|
||||
import { defineComponent, h, ref, nextTick } from "vue";
|
||||
import { ColorSwatch } from "../../../packages/vue/src";
|
||||
|
||||
const wrappers: ReturnType<typeof mount>[] = [];
|
||||
afterEach(() => {
|
||||
wrappers.splice(0).forEach((w) => w.unmount());
|
||||
document.body.innerHTML = "";
|
||||
});
|
||||
it("keeps asChild self-labelledby attached to the actual root ID", async () => {
|
||||
const id = ref("child-id");
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
setup: () => () =>
|
||||
h("div", [
|
||||
h("span", { id: "caption" }, "Brand"),
|
||||
h(
|
||||
ColorSwatch,
|
||||
{ asChild: true, color: "#0485F7", "aria-labelledby": "caption" },
|
||||
{
|
||||
default: () => h("div", { id: id.value }),
|
||||
},
|
||||
),
|
||||
]),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
wrappers.push(w);
|
||||
const root = w.get("[data-slot=color-swatch]");
|
||||
expect(root.attributes("aria-labelledby")).toBe(
|
||||
`${root.attributes("id")} caption`,
|
||||
);
|
||||
id.value = "next-child-id";
|
||||
await nextTick();
|
||||
expect(root.attributes("aria-labelledby")).toBe(
|
||||
`${root.attributes("id")} caption`,
|
||||
);
|
||||
});
|
||||
it("retains ordinary template styles together with styleFn", () => {
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: { ColorSwatch },
|
||||
template: `<ColorSwatch color="#0485F7" :style="{ outline: '2px solid red' }" :style-fn="() => ({ opacity: 0.5 })" />`,
|
||||
}),
|
||||
);
|
||||
wrappers.push(w);
|
||||
const style = (w.element as HTMLElement).style;
|
||||
expect(style.outline).toBe("2px solid red");
|
||||
expect(style.opacity).toBe("0.5");
|
||||
});
|
||||
Reference in New Issue
Block a user