I'm using the following to prevent text selection when a label is double-clicked:
label.addEventListener('mousedown', (event) => {
if (!event.defaultPrevented && event.detail > 1) {
event.preventDefault();
}
})
The code works as intended, and text is not selected when the label is double-clicked. However, I have noticed that in Firefox, if I check for window.getSelection()
after double-clicking the label, the label text is still selected within JavaScript (this isn't the case in Chrome).
When I remove the conditional statement that checks for !event.defaultPrevented && event.detail > 1
, the window.getSelection()
call no longer returns the label's text as selected.
It seems very strange that even though the condition is passed, the behaviour between the 2 is different.
I have created a fiddle to demonstrate the issue: link.
My question is: Is this a bug or intended behaviour in Firefox? And are there any workarounds for this issue?