fix(ivy): DebugElement.triggerEventHandler not picking up events registered via Renderer2 (#31845)

Fixes Ivy's `DebugElement.triggerEventHandler` to picking up events that have been registered through a `Renderer2`, unlike ViewEngine.

This PR resolves FW-1480.

PR Close #31845
This commit is contained in:
Kristiyan Kostadinov
2019-07-31 07:23:47 +03:00
committed by Alex Rickabaugh
parent a610d12266
commit 184d270725
5 changed files with 99 additions and 5 deletions

View File

@ -49,12 +49,20 @@ export function flattenStyles(
function decoratePreventDefault(eventHandler: Function): Function {
return (event: any) => {
// Ivy uses `Function` as a special token that allows us to unwrap the function
// so that it can be invoked programmatically by `DebugNode.triggerEventHandler`.
if (event === Function) {
return eventHandler;
}
const allowDefaultBehavior = eventHandler(event);
if (allowDefaultBehavior === false) {
// TODO(tbosch): move preventDefault into event plugins...
event.preventDefault();
event.returnValue = false;
}
return undefined;
};
}