From eb2215e58dfec5fa09c947b293369cfe66891fc3 Mon Sep 17 00:00:00 2001 From: Derrick Reimer Date: Mon, 24 Jun 2024 15:51:31 -0500 Subject: [PATCH 1/2] Skip intercepting auxiliary (middle) clicks on links --- packages/core/src/shouldIntercept.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/core/src/shouldIntercept.ts b/packages/core/src/shouldIntercept.ts index f26903029..0425f3c20 100644 --- a/packages/core/src/shouldIntercept.ts +++ b/packages/core/src/shouldIntercept.ts @@ -1,4 +1,4 @@ -export default function shouldIntercept(event: KeyboardEvent): boolean { +export default function shouldIntercept(event: MouseEvent | KeyboardEvent): boolean { const isLink = (event.currentTarget as HTMLElement).tagName.toLowerCase() === 'a' return !( (event.target && (event?.target as HTMLElement).isContentEditable) || @@ -7,6 +7,10 @@ export default function shouldIntercept(event: KeyboardEvent): boolean { (isLink && event.altKey) || (isLink && event.ctrlKey) || (isLink && event.metaKey) || - (isLink && event.shiftKey) + (isLink && event.shiftKey) || + // The auxiliary button (middle button) was pressed. All major browsers + // except Safari trigger the `auxclick` instead of `click`, so this is to + // ensure we do not intercept middle clicks in Safari. + (isLink && 'button' in event && event.button === 1) ) } From 7526daa664ab23dcb75fda410a76721043c9798d Mon Sep 17 00:00:00 2001 From: Derrick Reimer Date: Tue, 25 Jun 2024 10:18:49 -0500 Subject: [PATCH 2/2] Skip intercepting all non-left button clicks --- packages/core/src/shouldIntercept.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/core/src/shouldIntercept.ts b/packages/core/src/shouldIntercept.ts index 0425f3c20..c46b9b5c2 100644 --- a/packages/core/src/shouldIntercept.ts +++ b/packages/core/src/shouldIntercept.ts @@ -8,9 +8,6 @@ export default function shouldIntercept(event: MouseEvent | KeyboardEvent): bool (isLink && event.ctrlKey) || (isLink && event.metaKey) || (isLink && event.shiftKey) || - // The auxiliary button (middle button) was pressed. All major browsers - // except Safari trigger the `auxclick` instead of `click`, so this is to - // ensure we do not intercept middle clicks in Safari. - (isLink && 'button' in event && event.button === 1) + (isLink && 'button' in event && event.button !== 0) ) }