Skip to content

Commit fbe6c11

Browse files
authored
Merge pull request #548 from markacianfrani/main
fix: allow typing negative numbers in tool parameter inputs
2 parents 6a8c831 + 9eb5e7b commit fbe6c11

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
@@ -173,12 +173,13 @@ const ToolsTab = ({
173173
name={key}
174174
placeholder={prop.description}
175175
value={(params[key] as string) ?? ""}
176-
onChange={(e) =>
176+
onChange={(e) => {
177+
const value = e.target.value;
177178
setParams({
178179
...params,
179-
[key]: Number(e.target.value),
180-
})
181-
}
180+
[key]: value === "" ? "" : Number(value),
181+
});
182+
}}
182183
className="mt-1"
183184
/>
184185
) : (

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)