-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
423c942
commit 2839945
Showing
11 changed files
with
71 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { CHROME_VERSION, isFocused } from '../core/dom.js'; | ||
|
||
/** @param {typeof import('../core/CustomElement.js').default} Base */ | ||
export default function DelegatesFocusMixin(Base) { | ||
return Base | ||
.set({ | ||
delegatesFocus: true, | ||
}) | ||
.extend(CHROME_VERSION >= 111 | ||
? (BaseClass) => BaseClass | ||
: (BaseClass) => class extends BaseClass { | ||
get tabIndex() { | ||
return super.tabIndex; | ||
} | ||
|
||
set tabIndex(value) { | ||
if (value === super.tabIndex && value !== -1) { | ||
// Non -1 value already set | ||
return; | ||
} | ||
|
||
if (this.delegatesFocus && isFocused(this)) { | ||
if (this.getAttribute('tabindex') === value.toString()) { | ||
// Skip if possible | ||
return; | ||
} | ||
|
||
// Chrome blurs on tabindex changes with delegatesFocus | ||
// https://bugs.chromium.org/p/chromium/issues/detail?id=1346606 | ||
/** @type {EventListener} */ | ||
const listener = (e) => { | ||
e.stopImmediatePropagation(); | ||
e.stopPropagation(); | ||
if (e.type === 'blur') { | ||
console.warn('Chromium bug 1346606: Tabindex change caused blur. Giving focusing back.', this); | ||
this.focus(); | ||
} else { | ||
console.warn(`Chromium bug 1346606: Blocking ${e.type} event.`, this); | ||
} | ||
}; | ||
for (const type of ['blur', 'focus', 'focusout', 'focusin']) { | ||
this.addEventListener(type, listener, { capture: true, once: true }); | ||
} | ||
super.tabIndex = value; | ||
for (const type of ['blur', 'focus', 'focusout', 'focusin']) { | ||
this.removeEventListener(type, listener, { capture: true }); | ||
} | ||
return; | ||
} | ||
|
||
super.tabIndex = value; | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters