Skip to content

Commit

Permalink
fix: Angular Onpush will reRender table cause input blur
Browse files Browse the repository at this point in the history
  • Loading branch information
scarqin committed Jan 21, 2022
1 parent 6e86f95 commit 835a125
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/app/eoui/table/eo-table/eo-table.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<input nz-input type="text" [(ngModel)]="test" id="mytext" />
<nz-table
#basicTable
#filterTable
Expand Down
24 changes: 15 additions & 9 deletions src/app/eoui/table/eo-table/eo-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import {
Output,
EventEmitter,
OnInit,
ViewChild,
} from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd/message';
import { addKeyInTree, findDataInTree, flatData } from '../../../utils/tree';
import { CellDirective } from './cell.directive';

type Column = {
title: string;
key?: string;
Expand Down Expand Up @@ -104,16 +104,22 @@ export class EoTableComponent implements OnInit, OnChanges, AfterContentInit {
this.slotMap[cellName] = templateRef;
});
}

handleEditData(data, nodeKey, key) {
console.log(data)
document.getElementById("mytext").focus();
// data.relatedTarget.focus()
data.path[0].focus();
this.data = this.listOfMapData.map((it) => findDataInTree(it, data.target.value, { id: nodeKey, key }));
handleEditData(event, nodeKey, key) {
this.data = this.listOfMapData.map((it) => findDataInTree(it, event.target.value, { id: nodeKey, key }));
let elLocation = event.relatedTarget.getBoundingClientRect();
this.dataChange.emit(this.data);
/**
* ! Angular Onpush will reRender table cause input blur
* TODO use native dom to refator this component
*/
setTimeout(() => {
let dom = document.elementFromPoint(elLocation.x, elLocation.y);
if (dom.tagName !== 'INPUT') {
dom = dom.getElementsByClassName('ant-input')[0];
}
(dom as HTMLInputElement).focus();
}, 0);
}

handleCopy(value) {
if (navigator.clipboard) {
navigator.clipboard.writeText(value);
Expand Down

0 comments on commit 835a125

Please sign in to comment.