Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NgbDatepicker popup in shadow dom closes itself when clicking on it #3965

Open
lucbu01 opened this issue Jan 21, 2021 · 9 comments
Open

NgbDatepicker popup in shadow dom closes itself when clicking on it #3965

lucbu01 opened this issue Jan 21, 2021 · 9 comments

Comments

@lucbu01
Copy link

lucbu01 commented Jan 21, 2021

Hey, I'm using your datepicker component in a shadow dom and when I open the popup and click inside of it, for example to change the year, the popup closes itself. I don't really know how you detect if the click was made inside the popup, but I made a breakpoint and saw that when you use something like document.elementsFromPoint(event.clientX, event.clientY), it will return only elements before the shadow-root, where the component is inside:

image
image

@maxokorokov
Copy link
Member

We'll need a minimal reproduction scenario: StackBlitz or maybe a GitHub project in this case might be simpler. Otherwise not much we can do.

Autoclose implementaion we have is here → https://github.com/ng-bootstrap/ng-bootstrap/blob/master/src/util/autoclose.ts


Please take a look at the Getting Help section in documentation and use the appropriate support channel.

If you believe you've found a bug in this library then please:

  • fill in the issue template correctly
  • provide a minimal reproduction scenario in a StackBlitz

@lucbu01
Copy link
Author

lucbu01 commented Jan 21, 2021

Thanks for answering. I forked your example on Stackblitz:

Your Example: https://stackblitz.com/run?file=app/datepicker-popup.ts
My Fork: https://stackblitz.com/edit/angular-ddxygf?file=src/app/datepicker-popup.ts

Changed line:
image

@ashar340
Copy link

Would like this to be fixed soon, facing the same issue.

@vickieallen-certua
Copy link

We are also not able to use the Datepicker due to this issue.

@ghost
Copy link

ghost commented Aug 19, 2021

Do you have some updates to this issue? We plan using this component for long time inside of web-components.

@SkCodeRains
Copy link

i am also facing same issue when i enable shadowdom it just get closed on every click no matter where you click , without shadowdom it is working fine but not with shadowdom

@Thilo84
Copy link

Thilo84 commented May 6, 2022

The Problem is, that ng-bootstrap has an ngbAutoClose-Listener. Within this listener the event.target is used:
https://github.com/ng-bootstrap/ng-bootstrap/blob/master/src/util/autoclose.ts#L37

In ShadowDOM this event.target works different and return the shadowRoot element and not the clicked element. The problem is described here: https://tinytip.co/tips/js-event-composed-path/

Workaround Set autoClose to false and write your own Close-Handler.

@marcinmajkowski
Copy link

marcinmajkowski commented Jun 20, 2022

I was able to overcome the issue by changing event.target in https://github.com/ng-bootstrap/ng-bootstrap/blob/master/src/util/autoclose.ts#L37 to event.composedPath()[0] using patch-package. Not sure whether it is acceptable solution for the library though.

@vgoreiko
Copy link

vgoreiko commented Oct 2, 2023

Any updates on this?
I also have such issue related to the encapsulation: ViewEncapsulation.ShadowDom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants