From 7b3a71374933d51a85dfb9d337fe181285277045 Mon Sep 17 00:00:00 2001 From: Desislava Dincheva <34240583+ddincheva@users.noreply.github.com> Date: Mon, 7 Jan 2019 15:23:31 +0200 Subject: [PATCH] fix(IgxColumnMovingDropDirective): focus last active cell on column moving #3407 (#3524) --- .../src/lib/grids/grid.common.ts | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/projects/igniteui-angular/src/lib/grids/grid.common.ts b/projects/igniteui-angular/src/lib/grids/grid.common.ts index 419f62a948c..a971122b072 100644 --- a/projects/igniteui-angular/src/lib/grids/grid.common.ts +++ b/projects/igniteui-angular/src/lib/grids/grid.common.ts @@ -177,6 +177,12 @@ export class IgxColumnMovingService { rowID: any }; + public activeElement: { + tag: string, + column: IgxColumnComponent, + rowIndex: number + }; + get column(): IgxColumnComponent { return this._column; } @@ -275,6 +281,20 @@ export class IgxColumnMovingDragDirective extends IgxDragDirective { rowID: currSelection.rowID }; } + // tslint:disable-next-line:no-bitwise + if (document.activeElement.compareDocumentPosition(this.column.grid.nativeElement) & Node.DOCUMENT_POSITION_CONTAINS) { + if (parseInt(document.activeElement.getAttribute('data-visibleIndex'), 10) !== this.column.visibleIndex) { + (document.activeElement as HTMLElement).blur(); + return; + } + this.cms.activeElement = { + tag: document.activeElement.tagName.toLowerCase() === 'igx-grid-summary-cell' ? + document.activeElement.tagName.toLowerCase() : '', + column: this.column, + rowIndex: parseInt(document.activeElement.getAttribute('data-rowindex'), 10) + }; + (document.activeElement as HTMLElement).blur(); + } const args = { source: this.column @@ -528,12 +548,13 @@ export class IgxColumnMovingDropDirective extends IgxDropDirective implements On rowID: this.cms.selection.rowID, columnID: this.column.grid.columnList.toArray().indexOf(this.cms.selection.column) }])); - - const cell = this.column.grid.getCellByKey(this.cms.selection.rowID, this.cms.selection.column.field); - - if (cell) { - cell.nativeElement.focus(); - } + } + if (this.cms.activeElement) { + const gridEl = this.column.grid.nativeElement; + const activeEl = gridEl.querySelector(`${this.cms.activeElement.tag}[data-rowindex="${this.cms.activeElement.rowIndex}"]` + + `[data-visibleIndex="${this.cms.activeElement.column.visibleIndex}"]`); + if (activeEl) { activeEl.focus(); } + this.cms.activeElement = null; } this.column.grid.draggedColumn = null;