question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing selection-change event when editor loses focus by clicking a button

See original GitHub issue

Steps for Reproduction

  1. Visit https://codepen.io/medihack/pen/GBRYXw
  2. Select the editor to focus it. A selection-change event is correctly fired (see console).
  3. Click the “Click me” button below the editor. No selection event is fired.

Expected behavior:

A selection-change event should be fired with a null range when the editor loses focus when clicking a button somewhere else.

Actual behavior:

The selection-change event is not fired when the editor loses focus by clicking on a button.

Platforms:

Chrome (67.0.3396.99) on Windows 10.

Version:

Quill 1.3.6

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:3
  • Comments:8

github_iconTop GitHub Comments

8reactions
luthfimasruricommented, Mar 20, 2021

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();
});
5reactions
ashconnellcommented, Sep 20, 2019

We needed to know when the selection-change range changes to null so that we can send it off via WebSocket to sync cursors.

The documentation (https://quilljs.com/docs/api/#selection-change shown in the screenshot below) says that you can use this to be notified of selection loss but the event is never triggered when the editor is blurred.

image

To fix our problem we just got a hold of the editor element and listened for blur like so:

const quill = new Quill(/* config */)
quill.editor.scroll.domNode.addEventListener('blur', () => {
  // ... do stuff here, in our case we send cursor range:null to the server
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Javascript rich text editor, contenteditable area loses focus ...
Well the focus moves to the button so you need to cancel the click action so the focus is not lost in the...
Read more >
Grid Events - JavaScript Data Grid
This is a list of the events that the grid raises. ... Value has changed after editing (this event will not fire if...
Read more >
First button click is not executed in editor when window focus ...
First button click is not executed in editor when window focus is lost · 1. Open the user's attached project · 2. Open...
Read more >
End SfDatagrid edition when losing focus - WPF - Syncfusion
Thank you for using Syncfusion products. In TabControl.SelectionChanged event, you can end edit the current cell of SfDataGrid when swithching ...
Read more >
Blazor ComboBox - Events - Documentation - Telerik
The OnBlur event fires when the component loses focus. Handle the OnBlur event. Edit Preview. @* ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found