Skip to content
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

Fixing Dialog Escape keypress behavior #831

Merged
merged 2 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/common/cluster-store.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { WorkspaceId, workspaceStore } from "./workspace-store";
import path from "path";
import { app, ipcRenderer, remote } from "electron";
import { unlink } from "fs-extra";
Expand All @@ -13,7 +12,7 @@ import { saveToAppFiles } from "./utils/saveToAppFiles";
import { KubeConfig } from "@kubernetes/client-node";
import _ from "lodash";
import move from "array-move";
import { is } from "immer/dist/internal";
import type { WorkspaceId } from "./workspace-store";

export interface ClusterIconUpload {
clusterId: string;
Expand Down
5 changes: 3 additions & 2 deletions src/renderer/components/dialog/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,16 @@ export class Dialog extends React.PureComponent<DialogProps, DialogState> {
this.props.onOpen();
if (!this.props.pinned) {
if (this.elem) this.elem.addEventListener('click', this.onClickOutside);
window.addEventListener('keydown', this.onEscapeKey);
// Using document.body target to handle keydown event before Drawer does
document.body.addEventListener('keydown', this.onEscapeKey);
Copy link
Member

@ixrock ixrock Sep 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add comment (to the code) why document.body is used and how it's related to Drawer's event(s).

}
}

onClose = () => {
this.props.onClose();
if (!this.props.pinned) {
if (this.elem) this.elem.removeEventListener('click', this.onClickOutside);
window.removeEventListener('keydown', this.onEscapeKey);
document.body.removeEventListener('keydown', this.onEscapeKey);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/renderer/components/drawer/drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class Drawer extends React.Component<DrawerProps> {
});

componentDidMount() {
// Using window target for events to make sure they will be catched after other places (e.g. Dialog)
window.addEventListener("mousedown", this.onMouseDown)
window.addEventListener("click", this.onClickOutside)
window.addEventListener("keydown", this.onEscapeKey)
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/layout/sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
div.logo-text {
position: absolute;
left: 42px;
top: 11.5px;
top: 11px;
}

.logo-icon {
Expand Down