diff --git a/apps/desktop/src/components/grid/__tests__/DataGridConditionEditor.spec.ts b/apps/desktop/src/components/grid/__tests__/DataGridConditionEditor.spec.ts index b2a65cd11e..c3890cfb2a 100644 --- a/apps/desktop/src/components/grid/__tests__/DataGridConditionEditor.spec.ts +++ b/apps/desktop/src/components/grid/__tests__/DataGridConditionEditor.spec.ts @@ -195,6 +195,21 @@ describe("DataGridConditionEditor quote completion", () => { expect(value.value).toBe("name"); }); + it("selects the first WHERE field suggestion with Enter", async () => { + const { value, input } = mountEditor("where", "", { columns: ["customer_id", "customer_name"] }); + input.focus(); + input.value = "cus"; + input.setSelectionRange(3, 3); + 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"); + + input.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true, cancelable: true })); + await nextTick(); + expect(value.value).toBe("customer_id"); + }); + it("does not select a suggestion just because the dropdown appears under the mouse", async () => { const { value, input } = mountEditor("orderBy", "", { columns: ["name", "namespace"] }); input.focus(); diff --git a/apps/desktop/src/composables/__tests__/useDataGridConditionEditor.spec.ts b/apps/desktop/src/composables/__tests__/useDataGridConditionEditor.spec.ts index ece02c489c..bfa92cdada 100644 --- a/apps/desktop/src/composables/__tests__/useDataGridConditionEditor.spec.ts +++ b/apps/desktop/src/composables/__tests__/useDataGridConditionEditor.spec.ts @@ -33,7 +33,6 @@ describe("useDataGridConditionEditor", () => { value.value = "status = cust"; await nextTick(); await vi.waitFor(() => expect(editor.suggestions.value.map((item) => item.value)).toEqual(["customer_id", "customer_name"])); - expect(editor.navigate(1)).toBe(true); expect(editor.highlightedIndex.value).toBe(0); expect(editor.navigate(1)).toBe(true); expect(editor.highlightedIndex.value).toBe(1); diff --git a/apps/desktop/src/composables/useDataGridConditionEditor.ts b/apps/desktop/src/composables/useDataGridConditionEditor.ts index 57aea0741c..f34208c6f7 100644 --- a/apps/desktop/src/composables/useDataGridConditionEditor.ts +++ b/apps/desktop/src/composables/useDataGridConditionEditor.ts @@ -283,7 +283,7 @@ export function useDataGridConditionEditor(options: UseDataGridConditionEditorOp const providerValues = values ? [...new Set(values)] : undefined; suggestions.value = providerValues ? (providerValues.some((value) => value.toLowerCase() === target.token.toLowerCase()) ? [] : providerValues.slice(0, limit).map((suggestion) => ({ value: suggestion, kind: "column" }))) : defaultSuggestions(target).slice(0, limit); replacementRange.value = { from: target.from, to: target.to }; - highlightedIndex.value = -1; + highlightedIndex.value = options.kind === "where" && suggestions.value[0]?.kind === "column" ? 0 : -1; } catch (error) { if (!controller.signal.aborted && requestId === suggestionRequestId) { suggestions.value = [];