Skip to content

Commit

Permalink
capricorn86#1092@patch: Simplifies KeyboardEvent.
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrotoff committed Sep 24, 2023
1 parent fb67c3d commit 25f44ee
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions packages/happy-dom/src/event/events/KeyboardEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,33 @@ 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.
*
* @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;
}
}

0 comments on commit 25f44ee

Please sign in to comment.