fix(web-components): prevent double tab open on Ctrl+click in BaseAnchor#35745
Open
zoherghadyali wants to merge 5 commits intomicrosoft:masterfrom
Open
fix(web-components): prevent double tab open on Ctrl+click in BaseAnchor#35745zoherghadyali wants to merge 5 commits intomicrosoft:masterfrom
zoherghadyali wants to merge 5 commits intomicrosoft:masterfrom
Conversation
📊 Bundle size report✅ No changes found |
|
Pull request demo site: URL |
| @@ -170,6 +170,9 @@ export class BaseAnchor extends FASTElement { | |||
| public clickHandler(e: PointerEvent): boolean { | |||
There was a problem hiding this comment.
🕵🏾♀️ visual changes to review in the Visual Change Report
vr-tests-web-components/Badge 1 screenshots
| Image Name | Diff(in Pixels) | Image Type |
|---|---|---|
| vr-tests-web-components/Badge. - Dark Mode.normal.chromium.png | 443 | Changed |
vr-tests-web-components/MenuList 3 screenshots
| Image Name | Diff(in Pixels) | Image Type |
|---|---|---|
| vr-tests-web-components/MenuList. - Dark Mode.normal.chromium.png | 498 | Changed |
| vr-tests-web-components/MenuList. - RTL.2nd selected.chromium.png | 17 | Changed |
| vr-tests-web-components/MenuList. - RTL.normal.chromium_1.png | 39083 | Changed |
vr-tests-web-components/RadioGroup 1 screenshots
| Image Name | Diff(in Pixels) | Image Type |
|---|---|---|
| vr-tests-web-components/RadioGroup. - Dark Mode.2nd selected.chromium_3.png | 119 | Changed |
vr-tests-web-components/TextInput 1 screenshots
| Image Name | Diff(in Pixels) | Image Type |
|---|---|---|
| vr-tests-web-components/TextInput. - Dark Mode.normal.chromium_1.png | 288 | Changed |
There were 1 duplicate changes discarded. Check the build logs for more information.
Author
|
Hi @chrisdholt @radium-v @marchbox @davatron5000 — could you please review this fix? It addresses a bug where Ctrl+click (or Cmd+click on Mac) on anchor-based components ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Ctrl+clicking (or Cmd+clicking on Mac) a component that extends
BaseAnchor— such as<fluent-link>or<fluent-anchor-button>— opens two tabs instead of one.Root Cause
BaseAnchor.clickHandlercallshandleNavigation(true)which invokeswindow.open(href, '_blank'), but does not calle.preventDefault(). The proxy<a>element (positioned withposition: absolute; inset: 0over the component) also receives the native Ctrl+click, causing the browser to open a second tab via its built-in modifier-click behavior.On Ctrl+click, two navigations fire:
<a href="...">clickHandler, which callswindow.openFix
Call
e.preventDefault()inclickHandlerwhen the modifier key is held (ctrlKeyon Windows/Linux,metaKeyon Mac), before callinghandleNavigation(). This lets the component handle new-tab navigation exclusively and prevents the native duplicate.Changed File
packages/web-components/src/anchor-button/anchor-button.base.ts— addede.preventDefault()guard inclickHandlerTesting
<fluent-link>now opens exactly one tabanchor-button.spec.tsCtrl+click Playwright test should continue to pass (it waits for one new page viacontext.waitForEvent('page'))