TimePicker unusable in Cell Editor
I'm submitting a ... (check one with "x")
[x] bug report => Search github for a similar issue or PR before submitting
Plunkr Case (Bug Reports)
https://stackblitz.com/edit/resizable-breaks-calendar-edit
Current behavior On p-table component when resizableColumns is used with pEditableColumn the p-calendar component does not work as expected. Any clicks in the popup cause it to close due to the loss of focus from the table cell. (I think)
Expected behavior The calendar component should work as it does when resizableColumns is not used. Elements within the calendar should be clickable, and the user should be able to select a new date/time.
Minimal reproduction of the problem with instructions https://stackblitz.com/edit/resizable-breaks-calendar-edit
- Click one of the 'time' columns
- Try to use the spinners inside the calendar to change the time
- Note how the calendar popup closes on the first click, not allowing you to change all 3 options
- However, if you try the dropdown it works as expected
What is the motivation / use case for changing the behavior? I have data in a table, with dates and times, and my users want to inline edit.
I have attempted to switch to p-inplace instead of p-cellEditor. While it does resolve this specific issue because inplace does not revert state when the cell is blurred, it introduces a bunch of other issues I have to deal with like toggling state and handling the changes.
In an older version of PrimeNG/Angular (6.1-ish) this used to work without issue. https://stackblitz.com/edit/resizable-used-to-work
Please tell us about your environment: Windows 10, VS Code
-
Angular version: 7.1.1
-
PrimeNG version: 7.1.0
-
Browser: Chrome 71.0.3578.80
-
Language: TypeScript 3.1.6
-
Node (for AoT issues): 10.14.1
I see now that in the older version the state never reverts, so once you start editing you will always have a field in edit mode.
I found 2 issues where people were complaining about that https://github.com/primefaces/primeng/issues/5352 and https://github.com/primefaces/primeng/issues/1924
There is even a comment on one of them that explains how fixing the issue would cause the exact issue I am describing with calendar and dropdown. https://github.com/primefaces/primeng/issues/5352#issuecomment-395668175
So hopefully someone has a workaround or something.
For now we have implemented a check inside the TurboTable of our company's primeng fork, per the recommendation in this comment: https://github.com/primefaces/primeng/issues/5352#issuecomment-403472384
Edit: We're now using a HostListener, per iso3000's comment below. And using className instead of path, since it's more widely supported.
Added this to table.ts
@HostListener('document:click', ['$event'])
documentClick(event: any) {
let nodeInTree = this.isNodeInTree(event.target,"ui-datepicker");
if (nodeInTree) {
event.stopImmediatePropagation();
};
}
isNodeInTree(curNode: Element, searchNode:string): boolean {
for (; curNode; curNode = curNode.parentElement) {
if (curNode.className.toLowerCase().indexOf(searchNode.toLowerCase()) > -1) {return true;}
}
return false;
};
nodeName wouldn't work for us, since the node is appended to body (not wrapped by the component) and is just a div.
I'm using NgbInputDatepicker with TurboTable and it doesn't appear to matter if the columns are resizable or not- any click on the calendar would force it to close. This works for me:
@HostListener('document:click', ['$event'])
documentClick(event:any) {
let pathArr:HTMLElement[] = event.path;
if(pathArr.find(cP => cP.nodeName == "NGB-DATEPICKER")){
event.stopImmediatePropagation();
}
}
EDIT: Just occurred to me event.path doesn't fly in all browsers- here's another approach:
@HostListener('document:click', ['$event'])
documentClick(event: any) {
let nodeInTree = this.isNodeInTree(event.target,"NGB-DATEPICKER");
if (nodeInTree) {
event.stopImmediatePropagation();
};
}
isNodeInTree(curNode: Node, searchNode:string): boolean {
for (; curNode && curNode !== document; curNode = curNode.parentElement) {
if (curNode.nodeName.toUpperCase() == searchNode.toUpperCase()) return true;
}
return false;
};
There is the same problem with resizable columns as well. The problem is that when you click on something in the calendar the blur event of the inline editable cell is triggered and it destroys the input alongside the attached calendar.
I looks like the calendar month changing was fixed per https://github.com/primefaces/primeng/issues/7441
But this did not fix the timepicker, I've updated the original post and my comment with a fix.
Unable to replicate with PrimeNG 9, if the issue persists please create a new ticket with a test case reproducing the issue e.g. stackblitz or a github repo and it will be reviewed by our team once again.