-
Notifications
You must be signed in to change notification settings - Fork 1k
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
RadioButton/Checkbox: onChange event is called for each click #3148
Comments
Confirmed with Reproducer: https://codesandbox.io/s/primereact-test-forked-hcj1zl?file=/src/index.js Same issue for RadioButton and Checkbox. |
I am surprised that this behaviour was considered a bug for the Checkbox component. |
I have a better fix if you don't mind testing it for your scenario? |
Happy to test, is there a PR/branch that I can check this out on? |
Yep PR here: #3223 |
Sad to say does not work, would suggest that the issue lies in having two sources of truth, both the inputRef.current.checked and the props.checked. Checkbox.js:34 Can make the component out of sync with the external state that is being passed into props.checked. |
can you put together a code sandbox showing the issue using this? https://codesandbox.io/s/q2u1lr that way i can see what the issue is? |
Have done: https://codesandbox.io/s/lucid-visvesvaraya-kcc8qt?file=/src/demo/CheckboxDemo.js |
I checked on the latest PrimeReact version and looks like the bug is still reproducible for clicking on radio-button. Clicking on its label works as expected. |
@mikejav please open a new ticket. |
Describe the bug
The nature of the radio button's onChange event is that they should call the onChange event only when its state is actually changed.
Steps to reproduce:
checked
prop set totrue
and addonChange
event handler that does something.Result:
The onChange event is called even if the state was not changed.
Expected behavior:
When the RadioButton is clicked multiple times and if its state is "checked" - it should not call onChange.
Reproducer
No response
PrimeReact version
7.2.1
React version
17.x
Language
TypeScript
Build / Runtime
Webpack
Browser(s)
Chrome 103.0.5060.134
The text was updated successfully, but these errors were encountered: