Skip to content

Commit

Permalink
fix(search): move highlight in afterViewChecked #3631
Browse files Browse the repository at this point in the history
  • Loading branch information
DiyanDimitrov committed Jan 17, 2019
1 parent 0019348 commit 2d96d44
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
OnDestroy,
Output,
Renderer2,
SimpleChanges
SimpleChanges,
AfterViewChecked
} from '@angular/core';
import { takeUntil } from 'rxjs/operators';
import { Subject } from 'rxjs';
Expand All @@ -32,7 +33,7 @@ export interface IActiveHighlightInfo {
@Directive({
selector: '[igxTextHighlight]'
})
export class IgxTextHighlightDirective implements AfterViewInit, OnDestroy, OnChanges {
export class IgxTextHighlightDirective implements AfterViewInit, AfterViewChecked, OnDestroy, OnChanges {
private static onActiveElementChanged = new EventEmitter<string>();
public static highlightGroupsMap = new Map<string, IActiveHighlightInfo>();

Expand All @@ -42,6 +43,7 @@ export class IgxTextHighlightDirective implements AfterViewInit, OnDestroy, OnCh
private _nodeWasRemoved = false;
private _forceEvaluation = false;
private _activeElementIndex = -1;
private _oldValue: any;

/**
* Determines the `CSS` class of the highlight elements.
Expand Down Expand Up @@ -221,11 +223,6 @@ export class IgxTextHighlightDirective implements AfterViewInit, OnDestroy, OnCh
* @hidden
*/
ngOnChanges(changes: SimpleChanges) {
if (changes.value && !changes.value.firstChange) {
this.highlight(this._lastSearchInfo.searchedText, this._lastSearchInfo.caseSensitive, this._lastSearchInfo.exactMatch);
this.activateIfNecessary();
}

if ((changes.row !== undefined && !changes.row.firstChange) ||
(changes.column !== undefined && !changes.column.firstChange) ||
(changes.page !== undefined && !changes.page.firstChange)) {
Expand Down Expand Up @@ -261,6 +258,17 @@ export class IgxTextHighlightDirective implements AfterViewInit, OnDestroy, OnCh
this._container = this.parentElement.firstElementChild;
}

/**
* @hidden
*/
ngAfterViewChecked() {
if (this.value !== this._oldValue) {
this.highlight(this._lastSearchInfo.searchedText, this._lastSearchInfo.caseSensitive, this._lastSearchInfo.exactMatch);
this.activateIfNecessary();
this._oldValue = this.value;
}
}

/**
* Clears the existing highlight and highlights the searched text.
* Returns how many times the element contains the searched text.
Expand Down

0 comments on commit 2d96d44

Please sign in to comment.