Skip to content

Commit ae3981a

Browse files
committed
Fix keyDown action
1 parent ca15a46 commit ae3981a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/react-electron-window-menu/ContextMenu.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,17 @@ class ContextMenu implements IREWMenu.IContextMenu {
206206
case 'ArrowRight':
207207
this.moveHoveredIndex('RIGHT');
208208
break;
209+
default:
210+
return; // Quit when this doesn't handle the key event.
211+
}
212+
};
213+
214+
onKeyUp = (e: KeyboardEvent) => {
215+
e.preventDefault();
216+
217+
switch (e.key) {
209218
case 'Enter':
210-
this.handleClickItem(e);
219+
setTimeout(() => this.handleClickItem(e));
211220
break;
212221
case 'Esc': // IE/Edge specific value
213222
case 'Escape':
@@ -242,9 +251,11 @@ class ContextMenu implements IREWMenu.IContextMenu {
242251
this.container.focus();
243252
document.body.addEventListener('mousedown', this.onMousedownBody);
244253
this.container.addEventListener('keydown', this.onKeyDown);
254+
this.container.addEventListener('keyup', this.onKeyUp);
245255
} else {
246256
document.body.removeEventListener('mousedown', this.onMousedownBody);
247257
this.container.removeEventListener('keydown', this.onKeyDown);
258+
this.container.removeEventListener('keyup', this.onKeyUp);
248259
this.container.blur();
249260
this.container.remove();
250261
}

0 commit comments

Comments
 (0)