app: number fields no longer throw "e.preventDefault is not a function" (#735)

`useForm`'s input handlers called `e.preventDefault()` unconditionally, but the
Mantine-backed `NumberField` (Sleep between requests, Depth, Maximum Pages)
hands them a bare `{target}` object because NumberInput emits a value, not an
event.  Every keystroke in those fields threw.

`handleInputEvent` now only calls `preventDefault` when the argument actually
has one, and `getInputProps`' wrapper no longer repeats the call.  Audited every
other `preventDefault` call site: all are bound to real DOM/React events or a
guarded no-argument call.

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
lrnselfreliance 2026-09-26 17:41:15 -06:00 • committed by Roland
parent eead78007d
commit 20541d7184
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
3 changed files with 64 additions and 4 deletions

View file

@ -465,6 +465,39 @@ describe('useForm', () => {
expect(result.current.formData.sleep_requests).toBe(0.75);
});
it('handleInputEvent accepts a value-shaped event with no preventDefault (Mantine NumberInput)', () => {
// Mantine's NumberInput hands back the value, so NumberField wraps it in a bare
// {target} object. Typing must not throw "e.preventDefault is not a function".
const {result} = renderHook(() => useForm({
defaultFormData: {settings: {sleep_requests: ''}},
submitter: jest.fn(),
}));
act(() => {
result.current.handleInputEvent({
target: {type: 'number', value: 0.75, dataset: {path: 'settings.sleep_requests'}},
});
});
expect(result.current.formData.settings.sleep_requests).toBe(0.75);
});
it('getInputProps onChange accepts a value-shaped event with no preventDefault', async () => {
const {result} = renderHook(() => useForm({
defaultFormData: {settings: {depth: ''}},
submitter: jest.fn(),
}));
await act(async () => {
const [inputProps] = result.current.getInputProps({name: 'depth', path: 'settings.depth', type: 'number'});
await inputProps.onChange({
target: {type: 'number', value: 3, dataset: {path: 'settings.depth'}},
});
});
expect(result.current.formData.settings.depth).toBe(3);
});
it('handleInputEvent uses data-path attribute when available', () => {
const {result} = renderHook(() => useForm({
defaultFormData: {nested: {field: ''}},