Topic: The editor caret returns to the start after each text change
The editor accepts text, but the caret returns to the beginning after nearly every change. I also see the editor wrapper's unmount log when typing. A plain textarea controlled by the same state does not show the problem.
We pass key={draftHtml} to the editor because that originally helped refresh the content after switching documents. The document itself has a stable ID. Could that key cause the editor to recreate its selection state on each keystroke?
Mateusz Lazaru
staff answered 7 days ago
Yes. Changing a component's key tells React to replace that component, so using the current HTML as the key remounts the editor as the user types. Use the document ID when you intentionally want a new editor instance for a different document.
Keep ordinary content changes in the editor's supported value/change flow rather than forcing a remount. If the caret still jumps after using a stable key, please share that value handler and check whether it rewrites or sanitizes the HTML on every keystroke.
<DocumentEditor
key={document.id}
value={draftHtml}
onChange={setDraftHtml}
/>
https://mdbootstrap.com/docs/react/plugins/wysiwyg-editor/
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- User: Free
- Premium support: No
- Technology: MDB React
- MDB Version: MDB5 9.0.0
- Device: Laptop
- Browser: Firefox
- OS: macOS
- Provided sample code: No
- Provided link: No