react-jsonschema-form
react-jsonschema-form copied to clipboard
Using a custom widget causes re-render and loses focus
trafficstars
Prerequisites
- [X] I have searched the existing issues
- [X] I understand that providing a SSCCE example is tremendously useful to the maintainers.
- [X] I have read the documentation
- [X] Ideally, I'm providing a sample JSFiddle, Codesandbox.io or preferably a shared playground link demonstrating the issue.
What theme are you using?
chakra-ui
Version
5.x
Current Behavior
I have added a custom widget. When I type in it in the form, it re-renders the field, which causes it to lose focus on the input field and moves the cursor's current position to the beginning of the input field. Note: If autofocus is not present in the input props, it completely loses focus and I can't type at all.
https://github.com/user-attachments/assets/aebf8d33-fb7a-4f80-ac65-e0707aeaf7e2
Expected Behavior
Ideally, it should work the same way the default input function works. It shouldn't lose focus and shouldn't rerender.
Steps To Reproduce
- Register a Custom Widget
- Use custom widget in a form
Environment
- OS: macOS Sonoma
- Node: v22.3.0
- npm: 10.8.1
Anything else?
I followed the code written in the docs here https://rjsf-team.github.io/react-jsonschema-form/docs/advanced-customization/custom-widgets-fields