1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fixing Dialog Escape keypress behavior (#831)

* Replacing dialog keypress target

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Adding explanatory comments

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2020-09-10 09:31:23 +03:00 committed by GitHub
parent 8d1f0efe80
commit e11cbc19fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 5 deletions

View File

@ -1,4 +1,3 @@
import { WorkspaceId, workspaceStore } from "./workspace-store";
import path from "path"; import path from "path";
import { app, ipcRenderer, remote } from "electron"; import { app, ipcRenderer, remote } from "electron";
import { unlink } from "fs-extra"; import { unlink } from "fs-extra";
@ -13,7 +12,7 @@ import { saveToAppFiles } from "./utils/saveToAppFiles";
import { KubeConfig } from "@kubernetes/client-node"; import { KubeConfig } from "@kubernetes/client-node";
import _ from "lodash"; import _ from "lodash";
import move from "array-move"; import move from "array-move";
import { is } from "immer/dist/internal"; import type { WorkspaceId } from "./workspace-store";
export interface ClusterIconUpload { export interface ClusterIconUpload {
clusterId: string; clusterId: string;

View File

@ -92,7 +92,8 @@ export class Dialog extends React.PureComponent<DialogProps, DialogState> {
this.props.onOpen(); this.props.onOpen();
if (!this.props.pinned) { if (!this.props.pinned) {
if (this.elem) this.elem.addEventListener('click', this.onClickOutside); 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);
} }
} }
@ -100,7 +101,7 @@ export class Dialog extends React.PureComponent<DialogProps, DialogState> {
this.props.onClose(); this.props.onClose();
if (!this.props.pinned) { if (!this.props.pinned) {
if (this.elem) this.elem.removeEventListener('click', this.onClickOutside); if (this.elem) this.elem.removeEventListener('click', this.onClickOutside);
window.removeEventListener('keydown', this.onEscapeKey); document.body.removeEventListener('keydown', this.onEscapeKey);
} }
} }

View File

@ -40,6 +40,7 @@ export class Drawer extends React.Component<DrawerProps> {
}); });
componentDidMount() { 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("mousedown", this.onMouseDown)
window.addEventListener("click", this.onClickOutside) window.addEventListener("click", this.onClickOutside)
window.addEventListener("keydown", this.onEscapeKey) window.addEventListener("keydown", this.onEscapeKey)

View File

@ -40,7 +40,7 @@
div.logo-text { div.logo-text {
position: absolute; position: absolute;
left: 42px; left: 42px;
top: 11.5px; top: 11px;
} }
.logo-icon { .logo-icon {