Skip to content

Commit

Permalink
Merge pull request #3645 from IgniteUI/ddimitrov/fix-3637-7.1.x
Browse files Browse the repository at this point in the history
Fix search highlight after entering edit mode - 7.1.x
  • Loading branch information
kdinev authored Jan 17, 2019
2 parents 08695fd + 5b41712 commit 382080f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,15 @@ export class IgxTextHighlightDirective implements AfterViewInit, OnDestroy, OnCh
if (this._observer === null) {
const callback = (mutationList) => {
mutationList.forEach((mutation) => {
const removedNodes = new Array(... mutation.removedNodes);
const removedNodes = Array.from(mutation.removedNodes);
removedNodes.forEach((n) => {
if (n === this._container) {
this._nodeWasRemoved = true;
this.clearChildElements(false);
}
});

const addedNodes = new Array(... mutation.addedNodes);
const addedNodes = Array.from(mutation.addedNodes);
addedNodes.forEach((n) => {
if (n === this.parentElement.firstElementChild && this._nodeWasRemoved) {
this._container = this.parentElement.firstElementChild;
Expand Down
17 changes: 9 additions & 8 deletions projects/igniteui-angular/src/lib/grids/cell.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,15 @@ export class IgxGridCellComponent implements OnInit, AfterViewInit {
*/
get inEditMode(): boolean {
const editableCell = this.gridAPI.get_cell_inEditMode(this.gridID);
if (editableCell) {
return this.cellID.rowID === editableCell.cellID.rowID &&
this.cellID.columnID === editableCell.cellID.columnID;
} else {
return false;
const result = editableCell ? this.cellID.rowID === editableCell.cellID.rowID &&
this.cellID.columnID === editableCell.cellID.columnID : false;

if (result && !this._inEditMode && this.highlight && this.grid.lastSearchInfo.searchText) {
this.highlight.observe();
}
this._inEditMode = result;

return result;
}

/**
Expand All @@ -289,9 +292,6 @@ export class IgxGridCellComponent implements OnInit, AfterViewInit {
if (this.column.editable && value) {
this.focused = true;
this.gridAPI.set_cell_inEditMode(this.gridID, this);
if (this.highlight && this.grid.lastSearchInfo.searchText) {
this.highlight.observe();
}
this.editValue = this.value;
} else {
this.gridAPI.escape_editMode(this.gridID, this.cellID);
Expand Down Expand Up @@ -498,6 +498,7 @@ export class IgxGridCellComponent implements OnInit, AfterViewInit {
private cellSelectionID: string;
private prevCellSelectionID: string;
private previousCellEditMode = false;
private _inEditMode: boolean;

constructor(
public gridAPI: GridBaseAPIService<IgxGridBaseComponent>,
Expand Down
15 changes: 8 additions & 7 deletions projects/igniteui-angular/src/lib/grids/grid/grid.search.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,7 @@ describe('IgxGrid - search API', () => {
expect(isInView(3, grid.rowList.first.virtDirRow.state)).toBeTruthy();
});

it('should keep the active highlight when active cell enters and exits edit mode', () => {
pending('When the cell enters edit mode, the highlight stays and the content is doubled! Happens in tests only!');
it('should keep the active highlight when active cell enters and exits edit mode', async () => {
const rv = fix.debugElement.query(By.css(CELL_CSS_CLASS)).nativeElement;
const cell = grid.getCellByColumn(0, 'ID');
const initialValue = rv.textContent;
Expand All @@ -724,31 +723,32 @@ describe('IgxGrid - search API', () => {

cell.column.editable = true;
fix.detectChanges();
await wait(16);

grid.findNext('1');

activeHighlight = rv.querySelector('.' + component.activeClass);
expect(activeHighlight).not.toBeNull();

cell.inEditMode = true;
await wait(16);
fix.detectChanges();

expect(cell.inEditMode).toBe(true);
activeHighlight = rv.querySelector('.' + component.activeClass);
expect(activeHighlight).toBeNull();

cell.inEditMode = false;
await wait(16);
fix.detectChanges();

expect(rv.textContent).toBe(initialValue);
expect(rv.innerText).toBe(initialValue);
expect(rv.querySelectorAll('.' + component.highlightClass).length).toBe(1);
activeHighlight = rv.querySelector('.' + component.activeClass);
expect(activeHighlight).not.toBeNull();
});

it('should update highlights when a new value is entered', () => {
pending('When the cell enters edit mode, the highlight stays and the content is doubled! Happens in tests only!');

it('should update highlights when a new value is entered', async () => {
const rv = fix.debugElement.query(By.css(CELL_CSS_CLASS));
const cell = grid.getCellByColumn(0, 'ID');
cell.column.editable = true;
Expand All @@ -774,8 +774,9 @@ describe('IgxGrid - search API', () => {

cell.update(inputElem.value);
fix.detectChanges();
await wait(16);

expect(rv.nativeElement.textContent).toBe('11');
expect(rv.nativeElement.innerText).toBe('11');
activeHighlight = rv.nativeElement.querySelector('.' + component.activeClass);
const highlights = rv.nativeElement.querySelectorAll('.' + component.highlightClass);
expect(highlights.length).toBe(2);
Expand Down

0 comments on commit 382080f

Please sign in to comment.