-
Notifications
You must be signed in to change notification settings - Fork 241
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
The dialog closes when removing the target DOM element of a click event #111
Comments
Hi @CaselIT function bubbleNonAncestorHandlerFactory(element: HTMLElement, handler: (event) => void) {
return (event) => {
let current = event.target;
do {
if ( current === element ) {
return;
}
} while ( current.parentNode && ( current = current.parentNode ) );
handler(event);
};
} You refer to the do/while here? You can have this tree: Say the click was on button, I have to go up button -> div -> DialogElement |
As for why it's closing, It happening because you remove the Button element before the event handler is invoked. The best solution is to stop the event from bubbling.
If Plunker: |
Yes that is what I figured. I guess there is no simple way to automate this use case. Maybe using elementFromPoint could work even in this case. Still it took me a while to figure out why it happened. Regarding the code I understood what you are doing function bubbleNonAncestorHandlerFactory(element: HTMLElement, handler: (event) => void) {
return (event) => {
if(element.contains(event.target))
return;
handler(event);
};
} This should be equivalent but faster since |
Regarding function bubbleNonAncestorHandlerFactory(element: HTMLElement, handler: (event) => void) {
return (event) => {
const el = document.elementFromPoint(event.clientX, event.clientY);
if(element.contains(el))
return;
handler(event);
};
} I haven't tested it, so I'm not sure it if works. ( also not sure if the position from |
One thing that will solve this easily is looking at so I didn't use it because I don't know the browser competability. I didn't find information in MDN, CanIUse and W3C. It's not clear. So I dropped it. Anyway, this doesn't impact performance, yes its O(n) but performance is noticed when n is very high, so if your tree's depth is 1,000,000 then it will be noticed, but in such case angular2-modal is the least of your problems :) |
The second version, with
Well of course, but since there is a native function that does the same thing (with less code in this case!) I think it should be preferred. |
I agree, everything you said it true. But it has to be tested against multiple browsers and on mobile, to make sure the element we get is the right one. After building So if i'm not sure I prefer taking the longer, yet safer route. |
I feel your pain! I could make a pr with the improved code checking if |
This is exactly the complexity I want to avoid. Having this will create an unexpected behaviour, sometimes removing a clicked button from the form will close the form, sometimes not... who knows? depends on the browser.
I prefer "forcing" the developer to "stopPropagation", the other option is to hide the bug from him, letting his users find out about it. |
I had not thought about it. I agree with you. |
It's better be a bug, just edit this issue to have a proper title |
How to fix this : Error parsing header X-XSS-Protection: 1; mode=block; report=https://www.google.com/appserve/security-bugs/log/youtube: insecure reporting URL for secure page at character position 22. The default protections will be applied. my openModel methode works fine and i get data of result. but i had the error above |
I've found a bug, when I remove an item on the onclick event the dialog closes.
See this example
I think I've found the issue also: outside-event-plugin.ts
The function does not find the target element inside the dialog, since it was removed, and runs the
clickOutside
routine.At the moment I'm bypassing the issue wrapping the
slice
in asetTimeout
Also, why use the
do while
cycle when you could just do as below? (This does not solve the problem btw)The text was updated successfully, but these errors were encountered: