fix(ui): unify list hover and selection highlighting
This commit is contained in:
11 files changed
+142
-31
No files matched your search
@@ -20,6 +20,62 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
describe("CustomContextMenu lifecycle", () => {
|
||||
it("exposes the open state and closes only the active target", async () => {
|
||||
const firstOpen = vi.fn();
|
||||
const firstClose = vi.fn();
|
||||
const secondOpen = vi.fn();
|
||||
const secondClose = vi.fn();
|
||||
const root = defineComponent({
|
||||
setup() {
|
||||
const menu = (id: string, onOpen: () => void, onClose: () => void) =>
|
||||
h(
|
||||
CustomContextMenu,
|
||||
{ items: [{ label: `Inspect ${id}` }], onOpen, onClose },
|
||||
{
|
||||
default: ({ onContextMenu, isOpen }: { onContextMenu: (event: MouseEvent) => void; isOpen: boolean }) => h("div", { id, "data-context-open": String(isOpen), onContextmenu: onContextMenu }, id),
|
||||
},
|
||||
);
|
||||
return () => [menu("first-target", firstOpen, firstClose), menu("second-target", secondOpen, secondClose)];
|
||||
},
|
||||
});
|
||||
const container = document.createElement("div");
|
||||
mountedContainers.push(container);
|
||||
document.body.append(container);
|
||||
const app = createApp(root);
|
||||
app.mount(container);
|
||||
|
||||
const firstTarget = container.querySelector("#first-target");
|
||||
const secondTarget = container.querySelector("#second-target");
|
||||
firstTarget?.dispatchEvent(new MouseEvent("contextmenu", { bubbles: true }));
|
||||
await nextTick();
|
||||
expect(firstTarget?.getAttribute("data-context-open")).toBe("true");
|
||||
expect(secondTarget?.getAttribute("data-context-open")).toBe("false");
|
||||
expect(firstOpen).toHaveBeenCalledTimes(1);
|
||||
expect(firstClose).not.toHaveBeenCalled();
|
||||
|
||||
firstTarget?.dispatchEvent(new MouseEvent("contextmenu", { bubbles: true }));
|
||||
await nextTick();
|
||||
expect(firstTarget?.getAttribute("data-context-open")).toBe("true");
|
||||
expect(secondTarget?.getAttribute("data-context-open")).toBe("false");
|
||||
expect(firstOpen).toHaveBeenCalledTimes(2);
|
||||
expect(firstClose).toHaveBeenCalledTimes(1);
|
||||
|
||||
secondTarget?.dispatchEvent(new MouseEvent("contextmenu", { bubbles: true }));
|
||||
await nextTick();
|
||||
expect(firstTarget?.getAttribute("data-context-open")).toBe("false");
|
||||
expect(secondTarget?.getAttribute("data-context-open")).toBe("true");
|
||||
expect(firstClose).toHaveBeenCalledTimes(2);
|
||||
expect(secondOpen).toHaveBeenCalledTimes(1);
|
||||
|
||||
window.dispatchEvent(new Event("resize"));
|
||||
window.dispatchEvent(new Event("resize"));
|
||||
await nextTick();
|
||||
expect(secondTarget?.getAttribute("data-context-open")).toBe("false");
|
||||
expect(secondClose).toHaveBeenCalledTimes(1);
|
||||
|
||||
app.unmount();
|
||||
});
|
||||
|
||||
it("removes the capture keydown listener when unmounted while open", async () => {
|
||||
const documentAdd = vi.spyOn(document, "addEventListener");
|
||||
const documentRemove = vi.spyOn(document, "removeEventListener");
|
||||
|
||||
@@ -59,6 +59,30 @@ describe("customContextMenuRegistry", () => {
|
||||
registration.dispose();
|
||||
});
|
||||
|
||||
it("atomically reactivates a host after the capture listener clears it", () => {
|
||||
const documentTarget = new EventTarget();
|
||||
const windowTarget = new EventTarget();
|
||||
const registry = createContextMenuRegistry(documentTarget, windowTarget);
|
||||
const closeFirst = vi.fn();
|
||||
const closeSecond = vi.fn();
|
||||
const first = registry.register(closeFirst);
|
||||
const second = registry.register(closeSecond);
|
||||
|
||||
first.activate();
|
||||
documentTarget.dispatchEvent(new Event("contextmenu"));
|
||||
first.activate();
|
||||
second.activate();
|
||||
|
||||
expect(closeFirst).toHaveBeenCalledTimes(2);
|
||||
expect(closeSecond).not.toHaveBeenCalled();
|
||||
|
||||
windowTarget.dispatchEvent(new Event("resize"));
|
||||
expect(closeSecond).toHaveBeenCalledOnce();
|
||||
|
||||
first.dispose();
|
||||
second.dispose();
|
||||
});
|
||||
|
||||
it("removes disposed callbacks and detaches listeners after the final host", () => {
|
||||
const documentTarget = new EventTarget();
|
||||
const windowTarget = new EventTarget();
|
||||
|
||||
Reference in new issue
Block a user