Skip to content

Commit 8eeef94

Browse files
fix(ui5-link): open new page in correct tab (#13120)
fixes: #13116
1 parent 98b851b commit 8eeef94

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

packages/main/cypress/specs/Link.cy.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ describe("General API", () => {
2222
.should("have.attr", "rel", "noreferrer noopener");
2323
});
2424

25+
it("should not add rel attribute for custom target", () => {
26+
cy.mount(<Link href="https://www.sap.com" target="my-target"></Link>);
27+
28+
cy.get("[ui5-link]")
29+
.shadow()
30+
.find(".ui5-link-root")
31+
.should("have.attr", "target", "my-target")
32+
.and("not.have.attr", "rel");
33+
});
34+
2535
it("should wrap the text of the link", () => {
2636
cy.mount(
2737
<>

packages/main/src/Link.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ class Link extends UI5Element implements ITabbable {
291291
}
292292

293293
onBeforeRendering() {
294-
const needsNoReferrer = this.target !== "_self"
294+
const needsNoReferrer = this.target === "_blank"
295295
&& this.href
296296
&& this._isCrossOrigin(this.href);
297297

packages/main/test/pages/Link.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ <h2>prevent-default</h2>
4747
<ui5-link href="https://www.google.com" target="_self" id="link-click-prevent-default">link click default prevented</ui5-link><span>native span</span>
4848
</section>
4949

50+
<section class="group">
51+
<h2>Custom target</h2>
52+
<ui5-link href="https://www.sap.com" target="my-target" id="custom-target-link">Custom target link (click multiple times - should reuse same tab)</ui5-link>
53+
</section>
54+
5055
<section class="group">
5156
<h2>overstyle-link</h2>
5257
<ui5-link href="https://www.google.com" target="_self" style="color: pink">link with different color</ui5-link><span>native span</span>

0 commit comments

Comments
 (0)