From 25f44eeabaa264f4b57b16c6953851e78bfee48f Mon Sep 17 00:00:00 2001 From: Tanguy Krotoff Date: Sun, 24 Sep 2023 16:53:36 +0200 Subject: [PATCH] #1092@patch: Simplifies KeyboardEvent. https://w3c.github.io/uievents/#interface-keyboardevent. --- .../src/event/events/KeyboardEvent.ts | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/packages/happy-dom/src/event/events/KeyboardEvent.ts b/packages/happy-dom/src/event/events/KeyboardEvent.ts index 6ff36a762..86348a1bb 100644 --- a/packages/happy-dom/src/event/events/KeyboardEvent.ts +++ b/packages/happy-dom/src/event/events/KeyboardEvent.ts @@ -9,15 +9,15 @@ export default class KeyboardEvent extends UIEvent { public static DOM_KEY_LOCATION_LEFT = 1; public static DOM_KEY_LOCATION_RIGHT = 2; public static DOM_KEY_LOCATION_NUMPAD = 3; - public readonly altKey: boolean = false; - public readonly code: string = ''; - public readonly ctrlKey: boolean = false; - public readonly isComposing: boolean = false; - public readonly key: string = ''; - public readonly location: number = 0; - public readonly metaKey: boolean = false; - public readonly repeat: boolean = false; - public readonly shiftKey: boolean = false; + public readonly altKey: boolean; + public readonly code: string; + public readonly ctrlKey: boolean; + public readonly isComposing: boolean; + public readonly key: string; + public readonly location: number; + public readonly metaKey: boolean; + public readonly repeat: boolean; + public readonly shiftKey: boolean; /** * Constructor. @@ -25,19 +25,17 @@ export default class KeyboardEvent extends UIEvent { * @param type Event type. * @param [eventInit] Event init. */ - constructor(type: string, eventInit: IKeyboardEventInit = null) { + constructor(type: string, eventInit: IKeyboardEventInit = {}) { super(type, eventInit); - if (eventInit) { - this.altKey = eventInit.altKey || false; - this.code = eventInit.code || ''; - this.ctrlKey = eventInit.ctrlKey || false; - this.isComposing = eventInit.isComposing || false; - this.key = eventInit.key || ''; - this.location = eventInit.location !== undefined ? eventInit.location : 0; - this.metaKey = eventInit.metaKey || false; - this.repeat = eventInit.repeat || false; - this.shiftKey = eventInit.shiftKey || false; - } + this.altKey = eventInit.altKey ?? false; + this.code = eventInit.code ?? ''; + this.ctrlKey = eventInit.ctrlKey ?? false; + this.isComposing = eventInit.isComposing ?? false; + this.key = eventInit.key ?? ''; + this.location = eventInit.location ?? 0; + this.metaKey = eventInit.metaKey ?? false; + this.repeat = eventInit.repeat ?? false; + this.shiftKey = eventInit.shiftKey ?? false; } }