Skip to content

Commit f5dba84

Browse files
fix: allow typing negative numbers in tool parameter inputs
Number inputs were immediately converting values to Number() on every keystroke, which prevented users from typing negative numbers since the intermediate "-" character cannot be converted to a valid number. Now the input stores the raw string value and only converts to Number when the value is non-empty, allowing proper negative number entry.
1 parent 2ef41ab commit f5dba84

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

client/src/components/ToolsTab.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,13 @@ const ToolsTab = ({
163163
name={key}
164164
placeholder={prop.description}
165165
value={(params[key] as string) ?? ""}
166-
onChange={(e) =>
166+
onChange={(e) => {
167+
const value = e.target.value;
167168
setParams({
168169
...params,
169-
[key]: Number(e.target.value),
170-
})
171-
}
170+
[key]: value === "" ? "" : Number(value),
171+
});
172+
}}
172173
className="mt-1"
173174
/>
174175
) : (

client/src/components/__tests__/ToolsTab.test.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,27 @@ describe("ToolsTab", () => {
111111
});
112112
});
113113

114+
it("should allow typing negative numbers", async () => {
115+
renderToolsTab({
116+
selectedTool: mockTools[0],
117+
});
118+
119+
const input = screen.getByRole("spinbutton") as HTMLInputElement;
120+
121+
// Complete the negative number
122+
fireEvent.change(input, { target: { value: "-42" } });
123+
expect(input.value).toBe("-42");
124+
125+
const submitButton = screen.getByRole("button", { name: /run tool/i });
126+
await act(async () => {
127+
fireEvent.click(submitButton);
128+
});
129+
130+
expect(defaultProps.callTool).toHaveBeenCalledWith(mockTools[0].name, {
131+
num: -42,
132+
});
133+
});
134+
114135
it("should disable button and change text while tool is running", async () => {
115136
// Create a promise that we can resolve later
116137
let resolvePromise: ((value: unknown) => void) | undefined;

0 commit comments

Comments
 (0)