Skip to content

fix(text-input): validation error appears even if field is not changed, add validateOnChange prop #388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 8, 2025

Conversation

avi-alpert
Copy link
Collaborator

@avi-alpert avi-alpert commented Jul 7, 2025

Problem

There are two issues with how validation works on TextInput

  • Validation error only appears onBlur. On single-item forms this leads to a confusing UX since submit button is disabled but no error message is shown (see recording)
  • Validation error message appears onBlur even when the field hasn't been changed. When a field's autofocus is true, and user clicks X to exit the form, an error message shows up. (see recording)

Solution

  • Add optional validateOnChange prop to TextInput. This allows consumers to opt-in to validation happening onChange for a specific field
  • Only show validation error onBlur if user has touched the field

Screen recording before fix:

Screen.Recording.2025-07-07.at.2.24.45.PM.mov

Screen recording after fix:

Screen.Recording.2025-07-07.at.2.25.31.PM.mov

Tests

  • I have tested this change on VSCode
  • I have tested this change on JetBrains
  • I have added/updated the documentation (if applicable)

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@avi-alpert avi-alpert requested a review from a team as a code owner July 7, 2025 18:27
@avi-alpert avi-alpert merged commit 45b0834 into aws:main Jul 8, 2025
4 of 5 checks passed
@avi-alpert avi-alpert deleted the aalpert/fix-custom-form branch July 8, 2025 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants