An experimental polyfill for the focusgroup proposal by the Open UI Community Group.
The polyfill waits for any focusin event before it starts to track focusgroups and their child elements. This is done to prevent possible observer overload on pages with thousands of shadow roots, where initialising lots of mutation observers could non-negligible performance impact1.
focusin- Deep search for the real focused element (in shadow roots) while attaching
focusinlisteners to each shadow root on the way to catch continuous events. Globalfocusinonly fires once per shadow root 2. - Check if target is a valid focusgroup candidate (not
focusgroup=none)
Footnotes
-
Peter Kroener, 100'000 MutationObserver vs. 100'000 Funktionen: https://www.peterkroener.de/100000-mutationobserver-vs-100000-funktionen/ ↩