feat(grid): preselect first WHERE field completion suggestion

This commit is contained in:
二丫讲梵 authored and GitHub committed 2026-09-03 11:49:18 +08:00
1 parent eec2e63667
commit 2c7a420ef6
3 files changed
+16 -2

No files matched your search

@@ -195,6 +195,21 @@ describe("DataGridConditionEditor quote completion", () => {
expect(value.value).toBe("name"); 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 () => { it("does not select a suggestion just because the dropdown appears under the mouse", async () => {
const { value, input } = mountEditor("orderBy", "", { columns: ["name", "namespace"] }); const { value, input } = mountEditor("orderBy", "", { columns: ["name", "namespace"] });
input.focus(); input.focus();
@@ -33,7 +33,6 @@ describe("useDataGridConditionEditor", () => {
value.value = "status = cust"; value.value = "status = cust";
await nextTick(); await nextTick();
await vi.waitFor(() => expect(editor.suggestions.value.map((item) => item.value)).toEqual(["customer_id", "customer_name"])); 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.highlightedIndex.value).toBe(0);
expect(editor.navigate(1)).toBe(true); expect(editor.navigate(1)).toBe(true);
expect(editor.highlightedIndex.value).toBe(1); expect(editor.highlightedIndex.value).toBe(1);
@@ -283,7 +283,7 @@ export function useDataGridConditionEditor(options: UseDataGridConditionEditorOp
const providerValues = values ? [...new Set(values)] : undefined; 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); 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 }; 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) { } catch (error) {
if (!controller.signal.aborted && requestId === suggestionRequestId) { if (!controller.signal.aborted && requestId === suggestionRequestId) {
suggestions.value = []; suggestions.value = [];