diff --git a/src/index.tsx b/src/index.tsx index 94a940d..dfdf961 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -213,10 +213,6 @@ function invariant(value: any, message?: string) { const getInputId = (name: string, reactId: string) => `${name}--${reactId}`; const getErrorsId = (name: string, reactId: string) => `${name}-errors--${reactId}`; -const callAll = - (...fns: (Function | undefined)[]) => - (...args: any[]) => - fns.forEach((fn) => fn?.(...args)); const composeClassNames = (classes: Array) => classes.filter((v) => v).join(" "); const omit = ( @@ -510,10 +506,13 @@ export function useValidatedInput( id: getInputId(name, id), className: getClasses("input", attrs.className), defaultValue: serverFormInfo?.submittedFormData?.lastName, - onChange: callAll(onChange, (e: React.ChangeEvent) => { - setDirty(true); - setValue(e.target.value); - }), + onChange: (event: React.ChangeEvent) => { + onChange?.(event); + if (!event.defaultPrevented) { + setDirty(true); + setValue(event.target.value); + } + }, ...(showErrors ? { "aria-invalid": true,