-
Notifications
You must be signed in to change notification settings - Fork 2
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
keyDown
, 'keyPress and friends do not support
altKey or
ctrlKey` values on the events
#5
Comments
A possible patch for the simulator. Index: src/simulator.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/simulator.ts (revision c73295345ac4f90ba6f295ee3b9c6a9a493bd2ff)
+++ src/simulator.ts (revision )
@@ -67,13 +67,6 @@
return <any>result;
};
-let createKeyEvent = (which: number, target: any): KeyboardEvent => {
- let event = <any>createEvent(target);
- event.which = which;
- event.keyCode = which;
- return event;
-};
-
let createMouseEvent = (target: any, parameters?: MouseEventParameters): MouseEvent => {
let event = <any>createEvent(target);
if (parameters) {
@@ -92,16 +85,34 @@
};
export let createSimulator = (vnode: VNode, defaultFakeDomNode?: Object): Simulator => {
+ let ctrlKeyPressed = false;
+ let altKeyPressed = false;
+
+ let createKeyEvent = (which: number, target: any): KeyboardEvent => {
+ let event = <any>createEvent(target);
+ event.which = which;
+ event.keyCode = which;
+ event.ctrlKey = ctrlKeyPressed;
+ event.altKey = altKeyPressed;
+ return event;
+ };
+
let properties = vnode.properties;
return {
keyDown: (keyCode: number | string, fakeDomNode?: Object) => {
+ ctrlKeyPressed = keyCode === 17 ? true : ctrlKeyPressed;
+ altKeyPressed = keyCode === 18 ? true : altKeyPressed;
+
let event = createKeyEvent(getKeyCode(keyCode), fakeDomNode || defaultFakeDomNode);
properties.onkeydown(event);
return event;
},
keyUp: (keyCode: number | string, fakeDomNode?: Object) => {
+ ctrlKeyPressed = keyCode === 17 ? false : ctrlKeyPressed;
+ altKeyPressed = keyCode === 18 ? false : altKeyPressed;
+
let event = createKeyEvent(getKeyCode(keyCode), fakeDomNode || defaultFakeDomNode);
properties.onkeyup(event);
return event; |
It is technically possible for the user to have the ctrl down, before an element or the page gains the focus. This means the element would not receive the keydown for the ctrl key, but still, the event.ctrlKey would be set. A better approach would be to either invoke |
For now, I've fallen back to using the |
The control or alt key are not taken into account when handling a keyDown or keyPress.
Example test scenario / API:
This would require the simulator to remember the state.
Issue in current implementation:
nodeQuery.simulate
is done, a new simulator is created.Issues when one simulator per query is created:
Other possible solution would be to allow some event data in the keyDown/keyPress calls:
but this does not make a really nice API or corresponds on how the keys are handles by the browser (it would not help you making sure you can handle a keyDown event for only the control key).
The text was updated successfully, but these errors were encountered: