diff --git a/webview-ui/src/components/chat/AutoApproveMenu.tsx b/webview-ui/src/components/chat/AutoApproveMenu.tsx index 35c24830ac..707ddcf4f5 100644 --- a/webview-ui/src/components/chat/AutoApproveMenu.tsx +++ b/webview-ui/src/components/chat/AutoApproveMenu.tsx @@ -251,13 +251,26 @@ const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => { }}> Max Requests: { - const value = parseInt((e.target as HTMLInputElement).value) + const input = e.target as HTMLInputElement + // Remove any non-numeric characters + input.value = input.value.replace(/[^0-9]/g, "") + const value = parseInt(input.value) if (!isNaN(value) && value > 0) { updateMaxRequests(value) } }} + onKeyDown={(e) => { + // Prevent non-numeric keys (except for backspace, delete, arrows) + if ( + !/^\d$/.test(e.key) && + !["Backspace", "Delete", "ArrowLeft", "ArrowRight"].includes(e.key) + ) { + e.preventDefault() + } + }} style={{ flex: 1 }} />