mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-09 08:59:40 +02:00
refactor(tiles): the picker's outside-click close loses its left-click leftovers
The Tiles picker opens on right-click now. Three pieces only served the left-click picker: stopPropagation on the opening event, the tick of delay before the outside-click listener went in (so the opening click could not close it), and the exception for clicks on the Tiles button. A right-click fires no click event, and a left click on the button runs toggleTileGrid, which closes the picker before the click reaches the document. The preventDefault that keeps the browser menu away stays. The outside-click close had no test: tile-grid-open-set now checks that a click inside the picker leaves it open and one elsewhere closes it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -18,7 +18,14 @@ import { readFileSync } from 'node:fs';
|
||||
import { resolve } from 'node:path';
|
||||
import vm from 'node:vm';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { FakeEl, body, bySelector, makeGridApp, resetGridHarness } from './mocks/tile-grid-vm.js';
|
||||
import {
|
||||
FakeEl,
|
||||
body,
|
||||
bySelector,
|
||||
documentAddEventListener,
|
||||
makeGridApp,
|
||||
resetGridHarness,
|
||||
} from './mocks/tile-grid-vm.js';
|
||||
|
||||
type OpenSet = { source: string; ids: string[]; focusedId: string | null } | null;
|
||||
type Helpers = { tileGridOpenSet(p: Record<string, unknown>): OpenSet; TILE_GRID_MAX: number };
|
||||
@@ -137,6 +144,18 @@ describe('opening at once, in the app', () => {
|
||||
expect(app._tilesOwnTerminal()).toBe(true);
|
||||
});
|
||||
|
||||
it('a click elsewhere closes the picker; a click inside it does not', () => {
|
||||
const app = makeGridApp(IDS);
|
||||
const before = documentAddEventListener.mock.calls.length;
|
||||
app.openTilePicker({ preventDefault: vi.fn() });
|
||||
const calls = documentAddEventListener.mock.calls.slice(before) as Array<[string, (e: unknown) => void]>;
|
||||
const onClick = calls.find(([type]) => type === 'click')![1];
|
||||
onClick({ target: picker()!.children[0] });
|
||||
expect(picker()).not.toBeNull();
|
||||
onClick({ target: new FakeEl() });
|
||||
expect(picker()).toBeNull();
|
||||
});
|
||||
|
||||
it('a right-click opens the picker and keeps the browser menu away', () => {
|
||||
const app = makeGridApp(IDS);
|
||||
const ev = { preventDefault: vi.fn(), stopPropagation: vi.fn() };
|
||||
|
||||
Reference in New Issue
Block a user