react-quill: Paste something will trigger the blur event.
Hi,
If you paste something, the onBlur
event is triggered immediately. It will then not fire after you clicked outside.
Example: https://codepen.io/anon/pen/qPVQGK?editors=0010#0
- Paste something
- See how the alert shows up onBlur
- click outside (expect the alert box to show, will not show)
React-Quill version
- master
- 0.4.1
- 1.0.0-beta-1
- 1.0.0-beta-2
- 1.0.0-beta-3
- 1.0.0-beta-4
- 1.0.0-beta-5
- 1.0.0-rc-1
- 1.0.0-rc-2
- 1.0.0-rc-3
- 1.0.0
- 1.1.0
- Other (fork)
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 8
- Comments: 21
const handleBlur = (event, source) =>{
/* If the user uses copy and paste second parameter “source” return a string ‘silent’ in the blur event listener, and when the user dispatch event, clicking outside the input element source returns a string “user” where you can do simple if the case. This is the case when you want to submit on blur, but you want to disable auto submitting when the user does copy-paste. */
if(source === ‘silent’) return;
//Submit When User Clicks }
This is the case in React, I really hope this will help someone. 😃
Hi @alexkrolick, did you have the chance to invest some time into this issue or get some feedback from @jhchen? I am currently struggling with this issue as well. @luofei2011’s solution is worth a try, but feels more like a workaround than an actual fix. Maybe you have some news for me/us.
Thanks for your help and time. 😃
Copy & Paste onBlur and onFocus issue
@luofei2011: My problem is the following (and it does not work with your solution … 😕 ): We want to hide the toolbar (via css, so no toolbar=false issue) when the editor lost it’s focus. And only show it again when the Editor is focused again.
But the following happens. When the user enters quill (onFocus) he can start typing. Then he copy & pastes something (for some reason onBlur is then triggered). I can still copy & paste but the toolbar does not appear again. Only when I type again.
===> Check out the examples below for a live demo.
Main Research
But it should work, because here is a working solution from quill (not react-quill’s implementation): https://codepen.io/DmitrySkripkin/pen/eeXpZB?editors=0010#0. I found it here, it was also mentioned by @alexkrolick previously.
I am not entirely sure, but maybe the issue is here somewhere. Maybe @zenoamaro can help us out here?
Some other links
onPaste
. I will keep you posted here in this comment.~ ==> Update: did not work, as there is no such function.Examples
I have created some examples here:
this.handleChange = this.handleChange.bind(null)
This will solve you this issue.following @luofei2011 example this works for me :
I met the same problem when i paste something into editor, and trigger
onBlur
event immediately.This is my solution:
I’ve found a solution. The
FocusEvent
hasrelativeTarget
property, which may refer to.ql-clipboard
element. So, all you need to do isThis checks if the current blur event is related with copy/paste event.
Perfect solution via CSS :focus-within with
content
property and resize observerThe
setTimeout
solutions work but can introduce other timing/ UX issues. I found a solution that works perfectly using the fact that CSS ::focus-within correctly captures whether quill is focused or not (regardless of the clipboard blur issue). I have built the solution via an Angular directive but it can easily be changed to fit any framework you are using. Just wanted to share my solution in case other people need a clean solution for this problem ❤️I know this is the
react-quill
repository so Angular code seems to not be useful here - this is just my reference implementation as a quick way to share my code, I am not a React dev so I cannot translate the code unfortunately.Has anyone considered attempting to re-focus after paste (command/ctrl + V)? It looks like the first paste is perfectly fine - the textarea blurs on second paste. I’m cautious that this could lead to performance throttling. Thoughts?
@natterstefan maybe you used wrong way, https://codepen.io/anon/pen/zJeEXV?editors=0010 is ok. @vinay72
.bind(null)
changed thethis
to null, callingthis.setState
will trigger error.