primeng icon indicating copy to clipboard operation
primeng copied to clipboard

TimePicker unusable in Cell Editor

Open Rillist opened this issue 7 years ago • 6 comments

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

  1. Click one of the 'time' columns
  2. Try to use the spinners inside the calendar to change the time
  3. Note how the calendar popup closes on the first click, not allowing you to change all 3 options
  4. 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

Rillist avatar Mar 22 '19 19:03 Rillist

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.

Rillist avatar Mar 22 '19 19:03 Rillist

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.

Rillist avatar Mar 28 '19 17:03 Rillist

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;
  };

iso3000 avatar May 14 '19 13:05 iso3000

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.

botondus avatar May 16 '19 13:05 botondus

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.

Rillist avatar Sep 16 '19 20:09 Rillist

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.

cagataycivici avatar Mar 19 '20 10:03 cagataycivici