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

[RAC] <RadioGroup /> displays validation result in realtime when validate() is used #6096

Open
nwidynski opened this issue Mar 25, 2024 · 3 comments

Comments

@nwidynski
Copy link

nwidynski commented Mar 25, 2024

Provide a general summary of the issue here

When using validate() on a <RadioGroup />, the validation result is displayed in realtime. This behavior is inconsistent with the docs of validate() and also with the validation behavior of <CheckboxGroup />.

🤔 Expected Behavior?

Either <RadioGroup /> should display its validation result on submit or the docs need adjustment.

😯 Current Behavior

An invalid validation result is displayed in realtime.

💁 Possible Solution

Without much investigation, my bet is on this line being the culprit:

I am not entirely sure why we need to commit here. I've looked at the original PR which introduced this line, but it seemed to have made it past review. Maybe @devongovett can help here with further insight.

🔦 Context

No response

🖥️ Steps to Reproduce

  1. Visit the playground
  2. Click radio option 2 or 3
  3. Observe the invalid state displayed in realtime

Version

latest

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

OSX

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

@snowystinger
Copy link
Member

Possibly related #5693

@nwidynski
Copy link
Author

nwidynski commented Mar 26, 2024

Possibly related #5693

@snowystinger Yes they are. <Checkbox /> has the same issue, although only through keyboard selection. If im not missing anything, both issues stem from useFormValidation committing on every render. Additionally useRadioGroupState() also performs some additional commits which would have to be taken out.

I have also noticed, that an individual Radio doesn't receive the aria-invalid property but instead the div of the group does. I suppose this is intended behavior, but wanted to bring it up also.

Same goes for the onKeyDown event handler spread onto the group not being invoked at all in RAC <RadioGroup />.

Seems like there is a bit of cleanup to do in the radio hooks, but unsure whats required to stay for backwards compatibility. Fixing the commit issue without introducing breaking changes to useRadioGroupState() will require some more thought.

@nwidynski
Copy link
Author

@snowystinger If i understand #6079 (comment) correctly, then this issue should be closable. It might make sense to adjust the docs slightly to inform developers of the different behavior of validate depending on the timing of the native change event.

/**
* A function that returns an error message if a given value is invalid.
* Validation errors are displayed to the user when the form is submitted
* if `validationBehavior="native"`. For realtime validation, use the `isInvalid`
* prop instead.
*/

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

No branches or pull requests

2 participants