fix: cancel swatch picker press ownership on window blur
This commit is contained in:
@@ -885,3 +885,57 @@ describe("ColorSwatchPicker activation lifecycle and dynamic focus", () => {
|
||||
expect(disabled.getComponent(ColorSwatchPicker).emitted("update:modelValue")).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe("ColorSwatchPicker activation cancellation boundaries", () => {
|
||||
it("clears pressed state when the browser window loses focus", async () => {
|
||||
const w = picker();
|
||||
press(items(w)[0]!);
|
||||
await w.vm.$nextTick();
|
||||
expect(items(w)[0]!.attributes("data-pressed")).toBe("true");
|
||||
window.dispatchEvent(new Event("blur"));
|
||||
await w.vm.$nextTick();
|
||||
expect(items(w)[0]!.attributes("data-pressed")).toBeUndefined();
|
||||
});
|
||||
it("allows click-only retry after a press is cancelled by window blur", async () => {
|
||||
const w = picker({ modelValue: COLORS[0] });
|
||||
const root = w.getComponent(ColorSwatchPicker);
|
||||
press(items(w)[1]!);
|
||||
await w.vm.$nextTick();
|
||||
expect(root.emitted("update:modelValue")).toHaveLength(1);
|
||||
window.dispatchEvent(new Event("blur"));
|
||||
items(w)[1]!.element.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true, detail: 0 }));
|
||||
await w.vm.$nextTick();
|
||||
expect(root.emitted("update:modelValue")).toHaveLength(2);
|
||||
});
|
||||
it("keeps cancellation scoped to the targeted picker", async () => {
|
||||
const first = picker();
|
||||
const second = picker({ modelValue: COLORS[0] });
|
||||
press(items(first)[1]!);
|
||||
press(items(second)[1]!);
|
||||
await second.vm.$nextTick();
|
||||
first.get("[data-slot=color-swatch-picker]").element.dispatchEvent(new Event("pointercancel", { bubbles: true }));
|
||||
await second.vm.$nextTick();
|
||||
expect(items(second)[1]!.attributes("data-pressed")).toBe("true");
|
||||
// Cancelling the first owner must not clear the second's click suppression.
|
||||
items(second)[1]!.element.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true, detail: 0 }));
|
||||
await second.vm.$nextTick();
|
||||
expect(second.getComponent(ColorSwatchPicker).emitted("update:modelValue")).toHaveLength(1);
|
||||
window.dispatchEvent(new Event("blur"));
|
||||
await second.vm.$nextTick();
|
||||
expect(items(second)[1]!.attributes("data-pressed")).toBeUndefined();
|
||||
items(second)[1]!.element.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true, detail: 0 }));
|
||||
await second.vm.$nextTick();
|
||||
expect(second.getComponent(ColorSwatchPicker).emitted("update:modelValue")).toHaveLength(2);
|
||||
});
|
||||
it("allows repeated click-only proposals after controlled rejection", async () => {
|
||||
const w = picker({ modelValue: COLORS[0] });
|
||||
const root = w.getComponent(ColorSwatchPicker);
|
||||
for (let attempt = 0; attempt < 2; attempt++) {
|
||||
items(w)[1]!.element.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true, detail: 0 }));
|
||||
await w.vm.$nextTick();
|
||||
expect(items(w)[1]!.attributes("aria-selected")).toBe("false");
|
||||
}
|
||||
expect(root.emitted("update:modelValue")).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user