diff --git a/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Services/UriHelper.ts b/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Services/UriHelper.ts index f5a797b340..350d78c5d4 100644 --- a/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Services/UriHelper.ts +++ b/src/Microsoft.AspNetCore.Blazor.Browser.JS/src/Services/UriHelper.ts @@ -23,7 +23,10 @@ registerFunction(`${registeredFunctionPrefix}.enableNavigationInterception`, () if (anchorTarget) { const href = anchorTarget.getAttribute('href'); const absoluteHref = toAbsoluteUri(href); - if (isWithinBaseUriSpace(absoluteHref)) { + //if the user wants to user some specific browser/OS feature, we dont handle it and let the browser/OS + const anyChangeBehaviorKeyHold = event.ctrlKey || event.shiftKey || event.altKey || event.metaKey; + if (isWithinBaseUriSpace(absoluteHref) && !anyChangeBehaviorKeyHold) + { event.preventDefault(); performInternalNavigation(absoluteHref); } diff --git a/test/Microsoft.AspNetCore.Blazor.E2ETest/Microsoft.AspNetCore.Blazor.E2ETest.csproj b/test/Microsoft.AspNetCore.Blazor.E2ETest/Microsoft.AspNetCore.Blazor.E2ETest.csproj index 7045e97bc6..86b67bc2e7 100644 --- a/test/Microsoft.AspNetCore.Blazor.E2ETest/Microsoft.AspNetCore.Blazor.E2ETest.csproj +++ b/test/Microsoft.AspNetCore.Blazor.E2ETest/Microsoft.AspNetCore.Blazor.E2ETest.csproj @@ -10,8 +10,8 @@ - - + + diff --git a/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/RoutingTest.cs b/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/RoutingTest.cs index 64ac6cc991..d2981abef9 100644 --- a/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/RoutingTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/RoutingTest.cs @@ -3,11 +3,13 @@ using System; using System.Linq; +using System.Runtime.InteropServices; using BasicTestApp; using BasicTestApp.RouterTest; using Microsoft.AspNetCore.Blazor.E2ETest.Infrastructure; using Microsoft.AspNetCore.Blazor.E2ETest.Infrastructure.ServerFixtures; using OpenQA.Selenium; +using OpenQA.Selenium.Interactions; using Xunit; using Xunit.Abstractions; @@ -83,6 +85,54 @@ namespace Microsoft.AspNetCore.Blazor.E2ETest.Tests AssertHighlightedLinks("Other", "Other with base-relative URL (matches all)"); } + [Fact] + public void CanFollowLinkToOtherPageWithCtrlClick() + { + var key = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? Keys.Command : Keys.Control; + try + { + SetUrlViaPushState($"{ServerPathBase}/RouterTest/"); + + var app = MountTestComponent(); + var button = app.FindElement(By.LinkText("Other")); + //on mac os build we need to hold the meta button not the control for openning a popup + + new Actions(Browser) + .KeyDown(Keys.Control) + .Click(button) + .Build() + .Perform(); + + Assert.Equal(2, Browser.WindowHandles.Count); + + //closing newly opened windows if a new one was opened + + Browser.SwitchTo().Window(Browser.WindowHandles.Last()); + Browser.Close(); + Browser.SwitchTo().Window(Browser.WindowHandles.First()); + } + finally + { + // leaving the ctrl key up + new Actions(Browser) + .KeyUp(key) + .Build() + .Perform(); + } + } + + [Fact] + public void CanFollowLinkToOtherPageDoesNotOpenNewWindow() + { + SetUrlViaPushState($"{ServerPathBase}/RouterTest/"); + + var app = MountTestComponent(); + + app.FindElement(By.LinkText("Other")).Click(); + + Assert.Single(Browser.WindowHandles); + } + [Fact] public void CanFollowLinkToOtherPageWithBaseRelativeUrl() {