Open abinay opened 7 years ago
We worked around this (with the bubble theme) by trapping mousedown
on .ql-formats button
and executing preventDefault()
to stop the buttons from taking focus on click. It seems like something that the bubble theme would ideally handle itself.
@eamodio Have you reflected it in the git code ?? I did npm install ng2-quill-editor --save again and try to achieve the same above funtionality but its not working . Any help ??
@abinay I haven't made any changes in the quill code -- just modified our application code to add eventlisteners to the buttons.
@eamodio Trapping the mousedown on .ql-toolbar
and calling e.preventDefault() fixes this. Preventing default on the parent seems to work best as it takes care of preventing blur for all buttons and dropdowns. Any reason why just the buttons?
@jhchen Trapping mousedown and calling e.preventDefault() on .ql-toolbar works well for me and chrome and firefox. Seems to be a solution as long as it works in Edge or IE. This fixes the selection from being removed while using the formatting toolbar even when clicking the dropdowns like for font or paragraph align. This is very simple change for big improvement, any reason it has not been implemented other than time?
I do recall trying preventDefault() on mousedown and recall it not working in enough cases to not use it. I do not recall exactly what without spending time digging in but think it had to do with non-input elements on some browsers. I think the other concern is this would only affect buttons. Dropdowns and link input should not be prevented and focus should shift otherwise they won't work.
@jhchen hmm I tested in chrome, firefox, safari, and edge and I cannot notice any issues.
I prevent default on mousedown on the entire ql-toolbar. And so far the dropdowns work and even the link input works. I can select fonts, colors etc all with this fix and the selection stays nicely.
I am deploying this fix to production and am going to see if anyone has issues. I will let you know what I find. If no issues arise maybe we can revisit this fix and see if it is appropriate now.
@sferoze Sounds good please let us know how it goes.
@sferoze Hello, do you have any news for us?
@sferoze Hi, do you have any news on this, please? Thanks!
@pematt @natterstefan I have been using this fix in production for some time and no one has had any issues.
@sferoze Thank you so much, that is great news! Would you mind sharing the code needed to do this, please? Thanks!
Yeah, that would great @sferoze.
Hi,
Im new to quilljs and im having the same issue.
can anyone please share a snippet how to do the fixed mentioned above?
Trapping the mousedown on .ql-toolbar and calling e.preventDefault() fixes
Is there a non-jQuery solution to this issue?
Try this code.. It works better for me.. document.querySelector('.ql-picker-label').addEventListener("click", function(e){ e.stopPropagation(); });
Dropdowns and link input should not be prevented and focus should shift otherwise they won't work. Facing the exact same issue, not sure how it works for others @sferoze
this how to detect a toolbar click using promises with stats `
const onToolBar = ()=>{
return new Promise((resolve)=> {
document.querySelector('.ql-toolbar').addEventListener("click", (e) => {
resolve(true);
})
setTimeout(()=>{
resolve(false);
},50);
});
}
const onEditorBlur = () => {
onToolBar().then((onToolBar)=>{
if (!onToolBar)
setFocus(false) ;
})
}`
Solved using below this
const blurWrapper = () => { if(!props.onBlur) return; let okayToCallBlur = true; if (!props.disabled) { let _RTEinstance = document.getElementById(uniqueRTEid); let qlPickerLabels = _RTEinstance?.getElementsByClassName('ql-picker-label') || []; for (let i = 0; i < qlPickerLabels.length; i++) { if (document.activeElement === qlPickerLabels[i]) { okayToCallBlur = false; } } } if (!props.disabled && okayToCallBlur) props.onBlur() }
I am making a custom toolbar with Quill editor and the issue has happened when I clicked the dropdowns by vue-select component.
Trapping the event click
or mousedown
and calling e.preventDefault() didn't work.
Any idea for me?
Problem: loses selection when i click some toolbar menus, especially the dropdown one
Solution: Trapping the mousedown
on toolbar
container and calling e.preventDefault()
quill.getModule("toolbar").container.addEventListener("mousedown", (e) => {
e.preventDefault();
});
I had similar problem and I created a custom event: quill-focusout, which is dispatched only when focus leaves from toolbar, editor and tooltip (link editor). Now instead of blur I just listen to quill-focusout events.
const q = new Quill(node, {...});
// root element contains toolbar, editor and tooltip
const root = node.parentElement;
// add dummy href for link action anchor elements
// so that these are visible in focusout.relatedTarget
const action = root.getElementsByClassName('ql-action')[0];
action.href="";
const remove = root.getElementsByClassName('ql-remove')[0];
remove.href="";
const focusoutListener = event => {
if (!root.contains(event.relatedTarget) &&
event.target !== action) {
node.dispatchEvent(new CustomEvent('quill-focusout', {bubbles: true}));
}
}
root.addEventListener('focusout', focusoutListener);
The idea is that quill-focusout is dispatched from focusout only when focusout.relatedTarget is not inside quill root element. Property focusout.relatedTarget contains the element which obtains the focus.
http://www.google.com
Hello there, I am still facing a similar issue when trying to trigger the toolbar tooltip.edit()
form a custom link button I am building where the tooltip would disappear
Hii I am making a rich text editor using quill APIs. Following is the funcitonality I am trying to achieve -
So what I am doing is that when range of selection-change is null I treat it as blur event(as given in Quill documentation) and emit an event to make the editor disappear.
BLOCKER- When I click on the empty space of toolbar or any menu of toolbar with multi dropdown options range of selection-change gets null and the editor disappears.
Click on toolbar must not make the range of selection-change as null because toolbar is also a part of the editor.Other text editors like TinyMCE do not treat click on toolbar as blur event,hence this kind of problem does not appear.
Any help in this regard?? I am stuck int this for quite some time now . When can I expect quill to provide APIs for blur and focus detection. ???