Skip to content
Prev Previous commit
Next Next commit
ControlWithError: Show validating state when transitioning from error…
… state
  • Loading branch information
mirka committed Aug 19, 2025
commit 1046981d3ce1ca62afb06656d8945e6b76b2fc25
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ function UnforwardedControlWithError< C extends React.ReactElement >(
case 'validating': {
// Wait before showing a validating state.
const timer = setTimeout( () => {
validityTarget?.setCustomValidity( '' );
setErrorMessage( validityTarget?.validationMessage );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe in this case we want to setErrorMessage( undefined )? There is no error while validation is running.

The use case is interaction of the onValidate custom (server-side) validation with client-side validation, e.g., when there is something like <input type="email"> and the value is not email.

In that case, when additional custom validation is in flight, and status is validating, do we want errorMessage to show the "not email" error or not.

I'm not sure if we even support this combination of custom and native validation.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll be adding tests soon to help document these intended behaviors, but yes, we do support the combination of attribute-based and customValidity. I tried to match how the native APIs handle it, in that the customValidity message will be prioritized when it's a non-empty string, but otherwise the rest of the attribute-based validation errors will remain. It also matches the native browser logic of how errors messages are displayed — there can be multiple errors but only one error message is shown at a time.

In that case, when additional custom validation is in flight, and status is validating, do we want errorMessage to show the "not email" error or not.

That's a good question. I'm not sure if there's a universally better behavior, but I think in the general case, yes, we do want to show the "not email" error without waiting for the custom validator result.

Let's say there's a 50/50 chance of the custom async validator responding as error, and we wait for the async result before notifying the user about the "not email" error. This means that 50% of the time we made the user wait for no reason, because we already knew about the "not email" error.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Turns out, in practice it did feel better to make the user wait in all cases 😅 Going with setErrorMessage( undefined ) as in your suggestion.


setStatusMessage( {
type: 'validating',
message: customValidity.message,
Expand Down
Loading