Skip to content
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

fix(input, textarea): show error state after touch #26940

Merged
merged 14 commits into from
Mar 10, 2023
Merged

Conversation

liamdebeasi
Copy link
Contributor

@liamdebeasi liamdebeasi commented Mar 9, 2023

Pull request checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
    • Some docs updates need to be made in the ionic-docs repo, in a separate PR. See the contributing guide for details.
  • Build (npm run build) was run locally and any changes were pushed
  • Lint (npm run lint) has passed locally and any fixes were made for failures

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Issue URL: resolves #26939, resolves #21643

There are a couple issues with the form validation highlighting:

  1. The valid highlighting was always showing on a valid input, even when the input was blurred.
  2. The invalid error text was always showing on an invalid input, even when the input was untouched (touched = the user has focused and subsequently blurred the input)

Form validation highlighting is used to indicate that the user did something right/wrong, so having these states always show can be confusing.

What is the new behavior?

I updated the behavior as per the following table:

Validity State Touched State Focused State Validity Highlighting Shown
Valid Untouched Blurred ⚫️ None
Valid Touched Blurred ⚫️ None
Valid Untouched Focused 🟢 Valid
Valid Touched Focused 🟢 Valid
Invalid Untouched Blurred ⚫️ None
Invalid Touched Blurred 🔴 Invalid
Invalid Untouched Focused ⚫️ None
Invalid Touched Focused 🔴 Invalid

Reasoning for invalid state changes: An invalid state indicates the user entered malformed/incorrect data. As a result, having the invalid state show before the user has even interacted with the input can be confusing for the user. We show the input regardless of focus state once it has been touched. This is because users may need to correct data in order to submit a form. Showing the invalid highlight on both focus and blur lets users quickly identify which form controls need fixing.

Reasoning for the valid changes: A valid state indicates that the user entered correct data. As a result, we should give them that positive feedback as soon as their data is valid. We also show the valid state regardless of touched state because some forms may pre-populate data. Users may not necessarily want to change that pre-populated data if it is valid. Additionally, the user does not need to always know that an input is valid which is why we only show it on focus. This behavior also aligns with the behavior found in Ionic 6.

  • I found and removed duplicate code in the input and textarea stylesheets
  • I updated the input and textarea tests to check the correct valid/invalid conditions
  • I added validity state tests for select

Does this introduce a breaking change?

  • Yes
  • No

Other information

Dev build: 7.0.0-dev.11678373650.1975657a

@stackblitz
Copy link

stackblitz bot commented Mar 9, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@github-actions github-actions bot added the package: core @ionic/core package label Mar 9, 2023
Comment on lines -292 to -299
:host(.ion-touched.ion-invalid) {
--highlight-color: var(--highlight-color-invalid);
}

:host(.ion-touched.ion-valid) {
--highlight-color: var(--highlight-color-valid);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was duplicate code

Comment on lines -401 to -411
// Input Highlight
// ----------------------------------------------------------------

:host(.ion-touched.ion-invalid) {
--highlight-color: var(--highlight-color-invalid);
}

:host(.ion-touched.ion-valid) {
--highlight-color: var(--highlight-color-valid);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was duplicate code

@liamdebeasi liamdebeasi marked this pull request as ready for review March 9, 2023 15:25
@liamdebeasi liamdebeasi requested a review from a team as a code owner March 9, 2023 15:25
Copy link
Contributor

@sean-perkins sean-perkins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good.

The test templates (e.g. test/bottom-content/index.html) are a little confusing to reason about right now, unless you are aware of the extra classes that need to be appended to the host to make the error slot visible and/or the styling. Should we add a minimal implementation here with a button that adds the required classes to help with manually testing?

@liamdebeasi
Copy link
Contributor Author

Good catch! I updated those templates so ion-touched is added and the error styles show up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: core @ionic/core package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants