onChange called when the readOnly option gets changed with a value update
Describe the bug Updating the value of the readOnly option while also updating the value programmatically causes onChange to be called.
To Reproduce
- Use a state value for the readOnly option and the value prop
- Update both the readOnly option and the value prop
- The onChange function should get called
I linked a working example below. https://codesandbox.io/s/cool-spence-ps2dwx?file=/src/App.js
Expected behavior I would expect onChange not to be called.
Desktop (please complete the following information):
- OS: MacOS
- Browser: Chrome
- Version: 114.0.5735.198
@christiangrothaus I don't think there is something about readOnly option. You change the value and onChange is being called. Am I missing something?
@christiangrothaus I don't think there is something about
readOnlyoption. You change the value andonChangeis being called. Am I missing something?
When updating the value of the editor programmatically and changing it to read only at the same time the onChange function is being called. I would expect that the onChange function is only called when a user input causes the change. In the CodeSandbox example if you click the button at the bottom the background should be staying red since the onChange function shouldn't be called. In my project, we got around this by preventing both of these changes happening in the same state batch. Here is an example that shows updating the two separately avoids the issue, https://codesandbox.io/s/staging-river-8m9mkj?file=/src/App.js. The only change is the addition of the flushSync.
@suren-atoyan I also encountered this issue. It appears that when the Editor's readOnly is set to true, updating the value triggers the onChange event. Here is the code that causes the bug.
https://codesandbox.io/p/sandbox/quirky-glitter-kvhjqm?file=%2Fsrc%2FApp.tsx
I have also created a PR (#605) for this fix. Please review it.
@togo5 If this PR is merged, it will result in a big breakChange, which is even harder to accept
This issue has been marked as stale due to inactivity. It will be closed in 7 days unless further activity occurs.
Closing due to inactivity. Feel free to reopen if needed.