diff --git a/packages/@react-aria/form/src/useFormValidation.ts b/packages/@react-aria/form/src/useFormValidation.ts index b4699bf8046..707984cbdac 100644 --- a/packages/@react-aria/form/src/useFormValidation.ts +++ b/packages/@react-aria/form/src/useFormValidation.ts @@ -145,7 +145,7 @@ function getNativeValidity(input: ValidatableElement): ValidationResult { function getFirstInvalidInput(form: HTMLFormElement): ValidatableElement | null { for (let i = 0; i < form.elements.length; i++) { let element = form.elements[i] as ValidatableElement; - if (!element.validity.valid) { + if (element.validity?.valid === false) { return element; } } diff --git a/packages/react-aria-components/test/Form.test.js b/packages/react-aria-components/test/Form.test.js index ad0d3642f91..b2b931f2e11 100644 --- a/packages/react-aria-components/test/Form.test.js +++ b/packages/react-aria-components/test/Form.test.js @@ -188,4 +188,50 @@ describe('Form', () => { let form = getByTestId('form'); expect(form).toHaveAttribute('data-custom', 'true'); }); + + it('should not throw when form contains elements without validity property', async () => { + function Test() { + return ( +
+ ); + } + + let {getByTestId, getByRole} = render(