fix(grid): stop filter autocomplete inserting column names

This commit is contained in:
高桥凉介 authored and GitHub committed 2026-09-29 21:06:14 +08:00
1 parent f6d2077561
commit aff43d7ba9
3 files changed
+193 -44

No files matched your search

@@ -277,19 +277,20 @@ describe("DataGridConditionEditor quote completion", () => {
});
it("passes the textarea caret range through when accepting a suggestion", async () => {
const { value, input } = mountEditor("where", "status = cus AND enabled = 1", { columns: ["customer_id"] });
const { value, input } = mountEditor("where", "", { columns: ["customer_id"] });
input.focus();
input.setSelectionRange(12, 12);
input.dispatchEvent(new Event("select", { bubbles: true }));
input.value = "status = 1 AND cus";
input.setSelectionRange(18, 18);
input.dispatchEvent(new Event("input", { bubbles: true }));
await nextTick();
await vi.waitFor(() => expect(document.querySelector('[role="option"]')?.textContent).toContain("customer_id"));
input.dispatchEvent(new KeyboardEvent("keydown", { key: "Tab", bubbles: true, cancelable: true }));
await nextTick();
expect(value.value).toBe("status = customer_id AND enabled = 1");
expect(input.selectionStart).toBe(20);
expect(input.selectionEnd).toBe(20);
expect(value.value).toBe("status = 1 AND customer_id");
expect(input.selectionStart).toBe(26);
expect(input.selectionEnd).toBe(26);
});
it("starts without an active suggestion and selects the first item on ArrowDown", async () => {
@@ -312,7 +313,7 @@ describe("DataGridConditionEditor quote completion", () => {
expect(value.value).toBe("name");
});
it("selects the first WHERE field suggestion with Enter", async () => {
it("keeps the first WHERE field suggestion unselected and only applies on Enter", async () => {
const { value, input } = mountEditor("where", "", { columns: ["customer_id", "customer_name"] });
input.focus();
input.value = "cus";
@@ -320,11 +321,13 @@ describe("DataGridConditionEditor quote completion", () => {
input.dispatchEvent(new Event("input", { bubbles: true }));
await vi.waitFor(() => expect(document.querySelectorAll('[role="option"]')).toHaveLength(2));
expect(document.querySelector('[role="option"][aria-selected="true"]')?.textContent).toContain("customer_id");
// 不再默认高亮:回车只用于应用筛选,不会把列名写进输入框(issue #10595)
expect(document.querySelector('[role="option"][aria-selected="true"]')).toBeNull();
input.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true, cancelable: true }));
await nextTick();
expect(value.value).toBe("customer_id");
expect(value.value).toBe("cus");
expect(document.querySelector('[role="listbox"]')).toBeNull();
});
it("does not select a suggestion just because the dropdown appears under the mouse", async () => {
@@ -361,8 +364,8 @@ describe("DataGridConditionEditor quote completion", () => {
it("keeps suggestions closed after Enter applies a complete condition", async () => {
const { input } = mountEditor("where", "", { columns: ["id", "order0", "status"] });
input.focus();
input.value = "id > 0";
input.setSelectionRange(6, 6);
input.value = "order";
input.setSelectionRange(5, 5);
input.dispatchEvent(new Event("input", { bubbles: true }));
await vi.waitFor(() => expect(document.querySelectorAll('[role="option"]')).toHaveLength(1));