mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-04 13:49:57 -05:00
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:
parent
eead78007d
commit
20541d7184
3 changed files with 64 additions and 4 deletions
|
|
@ -1,8 +1,9 @@
|
|||
import React from 'react';
|
||||
import {render, screen, waitFor} from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import {DestinationForm} from './Download';
|
||||
import {createTestForm} from '../test-utils';
|
||||
import {DepthInputForm, DestinationForm} from './Download';
|
||||
import {useForm} from '../hooks/useForm';
|
||||
import {createTestForm, renderWithProviders} from '../test-utils';
|
||||
|
||||
// Mock DirectorySearch component - simplified to avoid useState/useEffect warnings
|
||||
jest.mock('./Common', () => {
|
||||
|
|
@ -251,3 +252,26 @@ describe('DestinationForm', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('NumberField', () => {
|
||||
// Renders a NumberField against a real useForm: the Mantine NumberInput passes a value (not an
|
||||
// event) to onChange, which used to reach `e.preventDefault()` and throw while typing.
|
||||
function DepthHarness({onData}) {
|
||||
const form = useForm({defaultFormData: {settings: {depth: ''}}, submitter: jest.fn()});
|
||||
onData(form.formData);
|
||||
return <DepthInputForm form={form}/>;
|
||||
}
|
||||
|
||||
it('typing into a NumberField updates the form without throwing', async () => {
|
||||
let latest = null;
|
||||
renderWithProviders(<DepthHarness onData={(d) => latest = d}/>);
|
||||
|
||||
const input = screen.getByRole('textbox', {name: /Depth/});
|
||||
await userEvent.type(input, '3');
|
||||
|
||||
await waitFor(() => {
|
||||
expect(latest.settings.depth).toBe(3);
|
||||
});
|
||||
expect(input).toHaveValue('3');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue