-
Notifications
You must be signed in to change notification settings - Fork 10
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
Clear field error state if the field is cleared #2424
Conversation
… "Select all" shortcuts are used
… error when the field is cleared (including when using the clear button in the SearchField or backspacing the value until it's clear)
…ic value instead of an empty field since errors are cleared for empty fields
…r textfield, textarea, and searchfield
…ld: Clear error state when field is cleared and it is not required
🦋 Changeset detectedLatest commit: a993ea9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Size Change: +14 B (+0.01%) Total Size: 96.5 kB
ℹ️ View Unchanged
|
A new build was pushed to Chromatic! 🚀https://5e1bf4b385e3fb0020b7073c-ynbxygwart.chromatic.com/ Chromatic results:
|
@@ -357,10 +357,12 @@ const MultiSelect = (props: Props) => { | |||
.filter((option) => !!option && !option.props.disabled) | |||
.map((option) => option.props.value); | |||
onChange(selected); | |||
onSelectedValuesChangeValidation(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the values change when the Select none
/ Select all
options are picked, we call the onSelectedValuesChangeValidation
handler
@@ -729,10 +729,10 @@ describe("Required LabeledTextField", () => { | |||
"test-labeled-text-field-field", | |||
); | |||
textField.focus(); | |||
await userEvent.clear(textField); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we now clear the error state when the field is cleared, this test case can be updated with an example where we update the input value instead of clear it
GeraldRequired Reviewers
Don't want to be involved in this pull request? Comment |
npm Snapshot: Published🎉 Good news!! We've packaged up the latest commit from this PR (bb2a588) and published all packages with changesets to npm. You can install the packages in webapp by running: ./services/static/dev/tools/deploy_wonder_blocks.js --tag="PR2424" Packages can also be installed manually by running: yarn add @khanacademy/wonder-blocks-<package-name>@PR2424 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! thanks for including all these tests to cover that 🚢
@@ -141,6 +142,17 @@ export const useFieldValidation = ({ | |||
} | |||
}); | |||
|
|||
React.useEffect(() => { | |||
// If it is not required, clear the error when the value is now empty | |||
if (!required && prevValue.current !== value && value.length === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: I wonder if you need to use trim()
here to cover the case where the user only types spaces (e.g. " "
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great question! We don't need to use trim
here to cover the " "
case since the error should only be cleared if the field is completely empty so any validation errors are still shown!
I'm testing the npm snapshot in webapp PR is now passing with only the dropdown changes! |
…earchField: Clear error state when field is cleared and it is not required" This reverts commit d8e0485.
…eared for textfield, textarea, and searchfield" This reverts commit b5fb688.
This reverts commit c7ce167.
…a specific value instead of an empty field since errors are cleared for empty fields" This reverts commit 7eca261.
…lears an error when the field is cleared (including when using the clear button in the SearchField or backspacing the value until it's clear)" This reverts commit 7800d39.
I will release and deploy these changes with the LabeledField feature branch! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for including the snapshot release results. These recent changes make sense!
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2424 +/- ##
============================
============================
Continue to review full report in Codecov by Sentry.
|
Summary:
Previously, if a MultiSelect component had shortcuts enabled, if it was in an error state, the "select all" and "select none" options do not clear the error state. Changing the selected values using these shortcuts now clear the error.
Issue: WB-1846
Test plan:
MultiSelect
Select none
?path=/story/packages-dropdown-multiselect--error-from-validation
and confirm that the shortcuts control is enabledSelect all
?path=/story/packages-dropdown-multiselect--error-from-validation
and confirm that the shortcuts control is enabled