Skip to content

fix(ui): use explicit type="button" on ToolsSection buttons#1852

Open
kimsehwan96 wants to merge 3 commits into
kagent-dev:mainfrom
kimsehwan96:fix/ui-tools-section-form-submit
Open

fix(ui): use explicit type="button" on ToolsSection buttons#1852
kimsehwan96 wants to merge 3 commits into
kagent-dev:mainfrom
kimsehwan96:fix/ui-tools-section-form-submit

Conversation

@kimsehwan96
Copy link
Copy Markdown

Fixes #1851

AS-IS

2026-05-12.4.45.36.mov

TO-BE

2026-05-12.4.43.58.mov

Changes

Explicit type="button" on all 4 <Button> elements in ToolsSection.tsx

Tests

Added ui/src/components/create/__tests__/ToolsSection.test.tsx

Buttons inside ToolsSection had no explicit type. When rendered inside
the <form> on /agents/new they fell back to HTML's submit default, so
clicking 'Add Tools & Agents' or a remove (X) button ran handleSaveAgent
and navigated to /agents (creating a half-configured Agent on success).

Signed-off-by: kimsehwan96 <sktpghks138@gmail.com>
Copilot AI review requested due to automatic review settings May 12, 2026 08:25
@kimsehwan96 kimsehwan96 requested a review from peterj as a code owner May 12, 2026 08:25
@github-actions github-actions Bot added the bug Something isn't working label May 12, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes UI bug #1851 where clicking “Add Tools & Agents” (and related icon buttons) inside the agent form unintentionally submits the surrounding <form> by ensuring the relevant buttons explicitly use type="button".

Changes:

  • Add type="button" to all four <Button> elements in ToolsSection.tsx to prevent implicit form submission.
  • Add a Jest/RTL regression test suite to ensure key ToolsSection interactions do not trigger form submit.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
ui/src/components/create/ToolsSection.tsx Sets explicit type="button" on ToolsSection buttons to avoid unintended form submission.
ui/src/components/create/tests/ToolsSection.test.tsx Adds regression tests verifying ToolsSection buttons don’t submit a surrounding <form>.
Comments suppressed due to low confidence (1)

ui/src/components/create/ToolsSection.tsx:195

  • The icon-only remove (X) button has no accessible name. Add an aria-label (and consider setting the <X /> icon to aria-hidden) so screen readers can announce it and tests can target it reliably. This matches existing UI patterns (e.g. FragmentEntriesEditor uses aria-label="Remove fragment").
                    <Button
                      type="button"
                      variant="ghost"
                      size="sm"
                      className="h-8 w-8 shrink-0 p-0"
                      onClick={() => handleRemoveTool(parentToolIdentifier, mcpToolName)}
                      disabled={isSubmitting}
                    >
                      <X className="h-4 w-4" />
                    </Button>

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ui/src/components/create/ToolsSection.tsx Outdated
Comment thread ui/src/components/create/__tests__/ToolsSection.test.tsx Outdated

expect(onSubmit).not.toHaveBeenCalled();
expect(setSelectedTools).toHaveBeenCalledTimes(1);
});
Match aria-label + aria-hidden patterns used elsewhere. Target remove
buttons by accessible name in tests. Add a regression case for the
MCP-tool remove path.

Signed-off-by: kimsehwan96 <sktpghks138@gmail.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread ui/src/components/create/ToolsSection.tsx Outdated
Signed-off-by: kimsehwan96 <sktpghks138@gmail.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] (UI) Clicking 'Add Tools & Agents' submits the agent form

2 participants