Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
Performance update (#13)
Browse files Browse the repository at this point in the history
* removed after contentchecked

* added test
  • Loading branch information
Blackbaud-AlexKingman authored Nov 8, 2018
1 parent 4300f9f commit 7ec9163
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,21 @@ describe('Text Highlight', () => {
});
}));

it('should highlight on startup if search term is set in component', async(() => {
const expectedHtml =
getHtmlOutput('Here is some <mark class="sky-highlight-mark">test</mark> text.');

fixture = TestBed.createComponent(SkyTextHighlightTestComponent);
nativeElement = fixture.nativeElement as HTMLElement;
component = fixture.componentInstance;

component.searchTerm = 'test';
fixture.detectChanges();
containerEl = getContainerEl(fixture);

expect(containerEl.innerHTML.trim()).toBe(expectedHtml);
}));

it('should highlight search term', async(() => {
updateInputText(fixture, 'text');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
AfterContentChecked,
AfterViewInit,
Directive,
ElementRef,
Expand All @@ -17,7 +16,7 @@ const className = 'sky-highlight-mark';
selector: '[skyHighlight]'
})
export class SkyTextHighlightDirective
implements OnChanges, AfterViewInit, AfterContentChecked, OnDestroy {
implements OnChanges, AfterViewInit, OnDestroy {

@Input()
public skyHighlight: string = undefined;
Expand Down Expand Up @@ -103,10 +102,10 @@ export class SkyTextHighlightDirective
});

this.observeDom();
}

public ngAfterContentChecked(): void {
this.highlight();
if (this.skyHighlight) {
this.highlight();
}
}

public ngOnDestroy(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<input [(ngModel)]="normalSearchTerm" />
<div class="sky-text-highlight-demo">
<div
[skyHighlight]="normalSearchTerm"
Expand Down

0 comments on commit 7ec9163

Please sign in to comment.