diff --git a/source/features/dim-bots.tsx b/source/features/dim-bots.tsx index f5a28e29880a..53093b57c6e0 100644 --- a/source/features/dim-bots.tsx +++ b/source/features/dim-bots.tsx @@ -1,7 +1,7 @@ import './dim-bots.css'; import select from 'select-dom'; import * as pageDetect from 'github-url-detection'; -import delegate from 'delegate-it'; +import delegate, {DelegateEvent} from 'delegate-it'; import features from '../feature-manager.js'; import preserveScroll from '../helpers/preserve-scroll.js'; @@ -35,8 +35,14 @@ const prSelectors = [ const dimBots = features.getIdentifiers(import.meta.url); -function undimBots(event: Event): void { - const resetScroll = preserveScroll(event.target as HTMLElement); +function undimBots(event: DelegateEvent): void { + const target = event.target as HTMLElement; + // Only undim when clicking on empty areas + if (target.closest('a, button, input, [tabindex]')) { + return; + } + + const resetScroll = preserveScroll(target); for (const bot of select.all(dimBots.selector)) { bot.classList.add('rgh-interacted'); } @@ -58,9 +64,6 @@ function init(signal: AbortSignal): void { // Undim on mouse focus delegate(dimBots.selector, 'click', undimBots, {signal}); - - // Undim on keyboard focus - document.documentElement.addEventListener('navigation:keydown', undimBots, {once: true, signal}); } void features.add(import.meta.url, { diff --git a/source/features/hide-navigation-hover-highlight.tsx b/source/features/hide-navigation-hover-highlight.tsx index f67cc1007956..cafb13678117 100644 --- a/source/features/hide-navigation-hover-highlight.tsx +++ b/source/features/hide-navigation-hover-highlight.tsx @@ -7,7 +7,7 @@ const html = document.documentElement; function init(): void { html.setAttribute(attribute, ''); - html.addEventListener('navigation:focus', () => { + html.addEventListener('navigation:keydown', () => { html.removeAttribute(attribute); }, {once: true}); }