fix(grid): preserve IME composition when condition expands

This commit is contained in:
Freedom authored and GitHub committed 2026-07-20 13:51:05 +08:00
1 parent 9cf2ec4194
commit 8e8cb0f58c
3 files changed
+46 -4

No files matched your search

@@ -11,8 +11,8 @@ vi.stubGlobal("localStorage", {
clear: () => storage.clear(),
});
function keyboardEvent(key: string) {
return { key, shiftKey: false, preventDefault: vi.fn() } as unknown as KeyboardEvent;
function keyboardEvent(key: string, extras: Partial<KeyboardEvent> = {}) {
return { key, shiftKey: false, preventDefault: vi.fn(), ...extras } as unknown as KeyboardEvent;
}
describe("useDataGridConditionEditor", () => {
@@ -192,4 +192,21 @@ describe("useDataGridConditionEditor", () => {
expect(editor.handleKeydown(escape)).toBe("dismiss");
expect(editor.dropdownOpen.value).toBe(false);
});
it("ignores shortcut keys while an IME composition is active", async () => {
const value = ref("");
const editor = useDataGridConditionEditor({ kind: "where", value, columns: ["name"], historyScope: {} });
value.value = "na";
await nextTick();
await vi.waitFor(() => expect(editor.suggestions.value).toHaveLength(1));
const composingEnter = keyboardEvent("Enter", { isComposing: true });
expect(editor.handleKeydown(composingEnter)).toBeUndefined();
expect(composingEnter.preventDefault).not.toHaveBeenCalled();
expect(value.value).toBe("na");
const processEnter = keyboardEvent("Process");
expect(editor.handleKeydown(processEnter)).toBeUndefined();
expect(processEnter.preventDefault).not.toHaveBeenCalled();
});
});
@@ -183,6 +183,7 @@ export function useDataGridConditionEditor(options: UseDataGridConditionEditorOp
}
function handleKeydown(event: KeyboardEvent): "accept" | "apply" | "dismiss" | "navigate" | undefined {
if (event.isComposing || event.key === "Process" || event.keyCode === 229) return undefined;
if (dropdownOpen.value && event.key === "Escape") {
event.preventDefault();
dismiss();