From 690ce02f49d45c702872089b8855792ebea99de5 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Thu, 26 Nov 2020 13:53:45 +0100 Subject: [PATCH 1/2] Prevent `super.transitionTo()` call when Cmd+Click is used --- addon/link.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/addon/link.ts b/addon/link.ts index e4b27162..2de91f7a 100644 --- a/addon/link.ts +++ b/addon/link.ts @@ -272,8 +272,7 @@ export class UILink extends Link { private preventDefault(event?: Event | unknown) { if ( (this._params.preventDefault ?? true) && - typeof (event as Event)?.preventDefault === 'function' && - (!isMouseEvent(event) || isUnmodifiedLeftClick(event)) + typeof (event as Event)?.preventDefault === 'function' ) { (event as Event).preventDefault(); } @@ -286,6 +285,8 @@ export class UILink extends Link { */ @action transitionTo(event?: Event | unknown): Transition { + if (isMouseEvent(event) && !isUnmodifiedLeftClick(event)) return; + // Intentionally putting this *before* the assertion to prevent navigating // away in case of a failed assertion. this.preventDefault(event); @@ -301,6 +302,8 @@ export class UILink extends Link { */ @action replaceWith(event?: Event | unknown): Transition { + if (isMouseEvent(event) && !isUnmodifiedLeftClick(event)) return; + // Intentionally putting this *before* the assertion to prevent navigating // away in case of a failed assertion. this.preventDefault(event); From 4cbe990ac64335658f6aef2f4e992b5756f4d767 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Thu, 26 Nov 2020 14:01:02 +0100 Subject: [PATCH 2/2] Adjust `transitionTo()` return types --- addon/link.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addon/link.ts b/addon/link.ts index 2de91f7a..9c01bded 100644 --- a/addon/link.ts +++ b/addon/link.ts @@ -228,7 +228,7 @@ export default class Link { * Transition into the target route. */ @action - transitionTo(): Transition { + transitionTo(): Transition | undefined { assert( 'You can only call `transitionTo`, when the router is initialized, e.g. when using `setupApplicationTest`.', this._linkManager.isRouterInitialized @@ -242,7 +242,7 @@ export default class Link { * possible. */ @action - replaceWith(): Transition { + replaceWith(): Transition | undefined { assert( 'You can only call `replaceWith`, when the router is initialized, e.g. when using `setupApplicationTest`.', this._linkManager.isRouterInitialized @@ -284,7 +284,7 @@ export class UILink extends Link { * Optionally call `preventDefault()`, if an `Event` is passed in. */ @action - transitionTo(event?: Event | unknown): Transition { + transitionTo(event?: Event | unknown): Transition | undefined { if (isMouseEvent(event) && !isUnmodifiedLeftClick(event)) return; // Intentionally putting this *before* the assertion to prevent navigating @@ -301,7 +301,7 @@ export class UILink extends Link { * Optionally call `preventDefault()`, if an `Event` is passed in. */ @action - replaceWith(event?: Event | unknown): Transition { + replaceWith(event?: Event | unknown): Transition | undefined { if (isMouseEvent(event) && !isUnmodifiedLeftClick(event)) return; // Intentionally putting this *before* the assertion to prevent navigating