Skip to content

Commit 2312eb5

Browse files
JiaLiPassionthePunderWoman
authored andcommitted
fix(platform-browser): KeyEventsPlugin should keep the same behavior (#49330)
Close #45698 KeyEventsPlugin now has different behavior with EventsPlugin, it will always run inside ngZone with ngZone.runGuarded() no matter the component is initialized inside or outside of NgZone, this PR make sure KeyEventsPlugin bahave the same with other events. PR Close #49330
1 parent 10ffd03 commit 2312eb5

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

packages/core/test/bundling/standalone_bootstrap/bundle.golden_symbols.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,6 @@
605605
{
606606
"name": "getCurrentTNodePlaceholderOk"
607607
},
608-
{
609-
"name": "getDOM"
610-
},
611608
{
612609
"name": "getDeclarationTNode"
613610
},

packages/platform-browser/src/dom/events/key_events.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,9 @@ export class KeyEventsPlugin extends EventManagerPlugin {
7878
override addEventListener(element: HTMLElement, eventName: string, handler: Function): Function {
7979
const parsedEvent = KeyEventsPlugin.parseEventName(eventName)!;
8080

81-
const outsideHandler =
82-
KeyEventsPlugin.eventCallback(parsedEvent['fullKey'], handler, this.manager.getZone());
81+
const outsideHandler = KeyEventsPlugin.eventCallback(parsedEvent['fullKey'], handler);
8382

84-
return this.manager.getZone().runOutsideAngular(() => {
85-
return getDOM().onAndCancel(element, parsedEvent['domEventName'], outsideHandler);
86-
});
83+
return this.manager.addEventListener(element, parsedEvent['domEventName'], outsideHandler);
8784
}
8885

8986
/**
@@ -178,10 +175,10 @@ export class KeyEventsPlugin extends EventManagerPlugin {
178175
* @param zone The zone in which the event occurred.
179176
* @returns A callback function.
180177
*/
181-
static eventCallback(fullKey: string, handler: Function, zone: NgZone): Function {
178+
static eventCallback(fullKey: string, handler: Function): Function {
182179
return (event: KeyboardEvent) => {
183180
if (KeyEventsPlugin.matchEventFullKeyCode(event, fullKey)) {
184-
zone.runGuarded(() => handler(event));
181+
handler(event);
185182
}
186183
};
187184
}

0 commit comments

Comments
 (0)