dangerouslyPasteHTML may steal the input focus
See original GitHub issuedangerouslyPasteHTML
sets the focus to the Quill editor element.
In a setting with concurrent HTML changes, where the edited content receives external updates of the HTML, dangerouslyPasteHTML
leads to unwanted loss of focus, if the current focus is not on the Quill editor.
Steps for Reproduction
- Visit https://codepen.io/anon/pen/Yvrwme?editors=0010
- Try typing in the JS code box (i.e. not within the Quill editor) for 2 seconds
This example simulates updated HTML from an “external” source every 1 second.
Expected behavior:
The input focus is kept in the JS code box. This could be:
- an API which allows to update from HTML, without changing focus
- make
dangerouslyPasteHTML
not change the input focus
Actual behavior:
The input focus is lost
Platforms:
OSX Chrome, Win 10 IE 11
Version:
1.3.6
Issue Analytics
- State:
- Created 5 years ago
- Reactions:24
- Comments:8
Top Results From Across the Web
Prevent input box from stealing focus - Stack Overflow
I was able to solve this by moving my content to another part of the DOM (to be exactly: Directly under the <body/>...
Read more >Clipboard Module - Quill Rich Text Editor
Quill is a free, open source WYSIWYG editor built for the modern web. Completely customize it for any need with its modular architecture...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This way you can set HTML content without changing the focus:
That is don’t use
pasteHTML
but convert your HTML to a delta and usesetContents
instead. It works for me. Focus does not change.I think the Quill docs do not mention
quill.clipboard.convert
. But I found it here: https://codepen.io/iice/pen/vQKrWYFor our specific use case, (which is to prevent the on-screen keyboard from suddenly popping-up due to editor receiving focus) a quick disable & enable did the trick. Simplified example :
We now try our best to disable the editor while it’s not in use, and re-enable it right before it’s ready for use to work around some of these edge-cases.
And this way, if you’re addicted to danger & adrenaline like I do, you can continue to use your favorite
dangerouslyPasteHTML
instead of thesetContents
🎉