Ignore editable-text blurs caused by window becoming inactive
Fixes #3588
This commit is contained in:
parent
6b1940cebb
commit
c10dabcbba
1 changed files with 16 additions and 0 deletions
|
@ -31,6 +31,8 @@
|
|||
|
||||
_textDirection = null;
|
||||
|
||||
_ignoredWindowInactiveBlur = false;
|
||||
|
||||
static observedAttributes = [
|
||||
'multiline',
|
||||
'readonly',
|
||||
|
@ -186,6 +188,13 @@
|
|||
input.addEventListener('input', handleInput);
|
||||
input.addEventListener('change', handleChange);
|
||||
input.addEventListener('focus', () => {
|
||||
// If the last blur was ignored because it was caused by the window becoming inactive,
|
||||
// ignore this focus event as well, so we don't reset initialValue
|
||||
if (this._ignoredWindowInactiveBlur) {
|
||||
this._ignoredWindowInactiveBlur = false;
|
||||
return;
|
||||
}
|
||||
|
||||
this.dispatchEvent(new CustomEvent('focus'));
|
||||
this.classList.add("focused");
|
||||
// Select all text if focused via keyboard
|
||||
|
@ -195,6 +204,13 @@
|
|||
this._input.dataset.initialValue = this._input.value;
|
||||
});
|
||||
input.addEventListener('blur', () => {
|
||||
// Ignore this blur if it was caused by the window becoming inactive (see above)
|
||||
if (Services.focus.activeWindow !== window) {
|
||||
this._ignoredWindowInactiveBlur = true;
|
||||
return;
|
||||
}
|
||||
this._ignoredWindowInactiveBlur = false;
|
||||
|
||||
this.dispatchEvent(new CustomEvent('blur'));
|
||||
this.classList.remove("focused");
|
||||
this._input.scrollLeft = 0;
|
||||
|
|
Loading…
Reference in a new issue