From 7e48be8061df62b0c181cf8096fc33f83d761b81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouzbeh=E2=80=A0?= <78313022+rqzbeh@users.noreply.github.com> Date: Sat, 22 Aug 2026 03:36:18 +0330 Subject: [PATCH] feat(dashboard): trigger key validation on Enter in AddApiKeyModal (#10995) (#11056) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ⭐5 — onKeyDown Enter no input de chave da AddApiKeyModal dispara a validação. TDD. Fecha #10995. --- .../[id]/components/modals/AddApiKeyModal.tsx | 6 +++++ .../ui/add-api-key-modal-enter-key.test.ts | 26 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 tests/unit/ui/add-api-key-modal-enter-key.test.ts diff --git a/src/app/(dashboard)/dashboard/providers/[id]/components/modals/AddApiKeyModal.tsx b/src/app/(dashboard)/dashboard/providers/[id]/components/modals/AddApiKeyModal.tsx index f3e652425b..71dc8456f7 100644 --- a/src/app/(dashboard)/dashboard/providers/[id]/components/modals/AddApiKeyModal.tsx +++ b/src/app/(dashboard)/dashboard/providers/[id]/components/modals/AddApiKeyModal.tsx @@ -757,6 +757,12 @@ export default function AddApiKeyModal({ type="password" value={formData.apiKey} onChange={(e) => setFormData({ ...formData, apiKey: e.target.value })} + onKeyDown={(e) => { + if (e.key === "Enter" && !validating && !saving) { + e.preventDefault(); + handleValidate(); + } + }} className="flex-1" placeholder={apiCredentialPlaceholder} hint={apiCredentialHint} diff --git a/tests/unit/ui/add-api-key-modal-enter-key.test.ts b/tests/unit/ui/add-api-key-modal-enter-key.test.ts new file mode 100644 index 0000000000..2532eb297e --- /dev/null +++ b/tests/unit/ui/add-api-key-modal-enter-key.test.ts @@ -0,0 +1,26 @@ +import { describe, it } from "node:test"; +import assert from "node:assert/strict"; +import fs from "node:fs"; +import path from "node:path"; + +describe("AddApiKeyModal Enter key submit (#10995)", () => { + it("AddApiKeyModal attaches onKeyDown Enter handler to the API Key input", () => { + const modalPath = path.resolve( + process.cwd(), + "src/app/(dashboard)/dashboard/providers/[id]/components/modals/AddApiKeyModal.tsx" + ); + const content = fs.readFileSync(modalPath, "utf8"); + assert.ok( + content.includes("onKeyDown"), + "AddApiKeyModal must contain onKeyDown event handler for Enter key validation" + ); + assert.ok( + content.includes('e.key === "Enter"'), + "onKeyDown handler must check for Enter key press" + ); + assert.ok( + content.includes("handleValidate()"), + "Enter key press must invoke handleValidate()" + ); + }); +});