Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(link): Allow email links without the external icon #1695

Merged
merged 2 commits into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions demo/app/components/link/link.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
<ts-card id="top">
<div>
<ts-link
[destination]="emailDestination"
[isExternal]="true"
tsVerticalSpacing
>support@terminus.com</ts-link>
</div>

<div>
<ts-link
[destination]="phoneDestination"
[isExternal]="true"
tsVerticalSpacing
>1800-423-4562</ts-link>
</div>

<div>
<ts-link
[destination]="localDestination"
Expand Down
2 changes: 2 additions & 0 deletions demo/app/components/link/link.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { Component } from '@angular/core';
})
export class LinkComponent {
localDestination = ['/components/copy'];
emailDestination = 'mailto:support@terminus.com';
phoneDestination = 'tel: 1800-423-4562';
externalDestination = `http://google.com`;
external = true;
}
4 changes: 3 additions & 1 deletion terminus-ui/link/src/link.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
>
<ng-template *ngTemplateOutlet="contentTemplate"></ng-template>

<ts-icon>
<ts-icon
*ngIf="showExternalIcon"
>
open_in_new
</ts-icon>
</a>
Expand Down
3 changes: 2 additions & 1 deletion terminus-ui/link/src/link.component.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ Wrap your link text and define a destination:

## External links

To signify a link will leave the current app or site, set `external` to true:
To signify a link will leave the current app or site, set `external` to true.
When the destination is a string and contains either `mailto` or `tel`, the external icon would not show.

```html
<ts-link
Expand Down
19 changes: 19 additions & 0 deletions terminus-ui/link/src/link.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ describe(`TsLinkComponent`, function() {
let component: TestHostComponent;
let fixture: ComponentFixture<TestHostComponent>;
let link: HTMLElement;
let emailLink: HTMLElement;
let linkComponent: TsLinkComponent;

beforeEach(async(() => {
Expand Down Expand Up @@ -117,6 +118,24 @@ describe(`TsLinkComponent`, function() {

});

describe(`showExternalIcon`, () => {

test(`should not show external icon when it is an email or phone`, () => {
component.destination = 'mailto: support@comcast.com';
component.isExternal = true;
fixture.detectChanges();
emailLink = fixture.debugElement.query(By.css('.c-link')).nativeElement;
expect(emailLink.classList).toContain('qa-link-external');

component.destination = 'tel: 18003256789';
fixture.detectChanges();
link = fixture.debugElement.query(By.css('.c-link')).nativeElement;
expect(link.classList).toContain('qa-link-external');

const externalLink = fixture.debugElement.query(By.css('.ts-icon'));
expect(externalLink).toBeFalsy();
});
});

describe(`tabIndex`, () => {

Expand Down
17 changes: 16 additions & 1 deletion terminus-ui/link/src/link.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Input,
ViewEncapsulation,
} from '@angular/core';
import { isString } from '@terminus/ngx-tools';
import { TsStyleThemeTypes } from '@terminus/ui/utilities';


Expand Down Expand Up @@ -56,11 +57,25 @@ export class TsLinkComponent {
*/
public localRoute = ['.'];

/**
* Decide whether an external icon should be shown
*/
public showExternalIcon = true;

/**
* Define the link's destination
*/
@Input()
public destination: string | string[] | undefined;
public set destination(value: string | string[] | undefined) {

This comment was marked as resolved.

if (isString(value) && (value.includes('mailto') || value.includes('tel'))) {
this.showExternalIcon = false;
}
this._destination = value;
}
public get destination(): string | string[] | undefined {
return this._destination;
}
public _destination: string | string[] | undefined;

/**
* Define the link's fragment
Expand Down