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

[core] fix(Overlay): escape key closing behavior #5349

Merged
merged 3 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions packages/core/src/components/overlay/overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -657,10 +657,10 @@ export class Overlay extends AbstractPureComponent2<OverlayProps, IOverlayState>

private handleKeyDown = (e: React.KeyboardEvent<HTMLElement>) => {
const { canEscapeKeyClose, onClose } = this.props;
// HACKHACK: https://github.com/palantir/blueprint/issues/4165
/* eslint-disable-next-line deprecation/deprecation */
if (e.which === Keys.ESCAPE && canEscapeKeyClose) {
if (e.key === "Escape" && canEscapeKeyClose) {
onClose?.(e);
// prevent other overlays from closing
e.stopPropagation();
// prevent browser-specific escape key behavior (Safari exits fullscreen)
e.preventDefault();
}
Expand Down
6 changes: 3 additions & 3 deletions packages/core/test/alert/alertTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { mount, shallow, ShallowWrapper } from "enzyme";
import * as React from "react";
import { SinonStub, spy, stub } from "sinon";

import { Alert, Button, Classes, IAlertProps, IButtonProps, Icon, Intent, Keys } from "../../src";
import { Alert, Button, Classes, IAlertProps, IButtonProps, Icon, Intent } from "../../src";
import * as Errors from "../../src/common/errors";
import { findInPortal } from "../utils";

Expand Down Expand Up @@ -175,11 +175,11 @@ describe("<Alert>", () => {
);
const overlay = findInPortal(alert, "." + Classes.OVERLAY).first();

overlay.simulate("keydown", { which: Keys.ESCAPE });
overlay.simulate("keydown", { key: "Escape" });
assert.isTrue(onCancel.notCalled);

alert.setProps({ canEscapeKeyCancel: true });
overlay.simulate("keydown", { which: Keys.ESCAPE });
overlay.simulate("keydown", { key: "Escape" });
assert.isTrue(onCancel.calledOnce);

alert.unmount();
Expand Down
3 changes: 1 addition & 2 deletions packages/core/test/dialog/dialogTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import * as React from "react";
import { spy } from "sinon";

import { Button, Classes, Dialog, DialogProps, H4, Icon, IconSize } from "../../src";
import * as Keys from "../../src/common/keys";

describe("<Dialog>", () => {
it("renders its content correctly", () => {
Expand Down Expand Up @@ -93,7 +92,7 @@ describe("<Dialog>", () => {
{createDialogContents()}
</Dialog>,
);
dialog.simulate("keydown", { which: Keys.ESCAPE });
dialog.simulate("keydown", { key: "Escape" });
assert.isTrue(onClose.notCalled);
});

Expand Down
3 changes: 1 addition & 2 deletions packages/core/test/drawer/drawerTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import * as React from "react";
import { spy } from "sinon";

import { Button, Classes, Drawer, DrawerProps, Position } from "../../src";
import * as Keys from "../../src/common/keys";

describe("<Drawer>", () => {
let drawer: ReactWrapper<DrawerProps, any>;
Expand Down Expand Up @@ -197,7 +196,7 @@ describe("<Drawer>", () => {
{createDrawerContents()}
</Drawer>,
);
drawer.simulate("keydown", { which: Keys.ESCAPE });
drawer.simulate("keydown", { key: "Escape" });
assert.isTrue(onClose.notCalled);
});

Expand Down
5 changes: 2 additions & 3 deletions packages/core/test/overlay/overlayTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { spy } from "sinon";
import { dispatchMouseEvent } from "@blueprintjs/test-commons";

import { Classes, Overlay, OverlayProps, Portal, Utils } from "../../src";
import * as Keys from "../../src/common/keys";
import { findInPortal } from "../utils";

const BACKDROP_SELECTOR = `.${Classes.OVERLAY_BACKDROP}`;
Expand Down Expand Up @@ -224,7 +223,7 @@ describe("<Overlay>", () => {
{createOverlayContents()}
</Overlay>,
);
wrapper.simulate("keydown", { which: Keys.ESCAPE });
wrapper.simulate("keydown", { key: "Escape" });
assert.isTrue(onClose.calledOnce);
});

Expand All @@ -235,7 +234,7 @@ describe("<Overlay>", () => {
{createOverlayContents()}
</Overlay>,
);
overlay.simulate("keydown", { which: Keys.ESCAPE });
overlay.simulate("keydown", { key: "Escape" });
assert.isTrue(onClose.notCalled);
overlay.unmount();
});
Expand Down
3 changes: 1 addition & 2 deletions packages/core/test/popover/popoverTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { dispatchMouseEvent } from "@blueprintjs/test-commons";
import { Portal } from "../../src";
import * as Classes from "../../src/common/classes";
import * as Errors from "../../src/common/errors";
import * as Keys from "../../src/common/keys";
import { Overlay } from "../../src/components/overlay/overlay";
import { IPopoverProps, IPopoverState, Popover, PopoverInteractionKind } from "../../src/components/popover/popover";
import { PopoverArrow } from "../../src/components/popover/popoverArrow";
Expand Down Expand Up @@ -833,8 +832,8 @@ describe("<Popover>", () => {
};
wrapper.sendEscapeKey = () => {
wrapper!.findClass(Classes.OVERLAY_OPEN).simulate("keydown", {
key: "Escape",
nativeEvent: new KeyboardEvent("keydown"),
which: Keys.ESCAPE,
});
return wrapper!;
};
Expand Down
4 changes: 2 additions & 2 deletions packages/popover2/test/contextMenu2Tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { mount, ReactWrapper } from "enzyme";
import * as React from "react";
import { spy } from "sinon";

import { Classes as CoreClasses, Keys, Menu, MenuItem } from "@blueprintjs/core";
import { Classes as CoreClasses, Menu, MenuItem } from "@blueprintjs/core";

import {
Classes,
Expand Down Expand Up @@ -80,8 +80,8 @@ describe("ContextMenu2", () => {
.find(`.${CoreClasses.OVERLAY_OPEN}`)
.hostNodes()
.simulate("keydown", {
key: "Escape",
nativeEvent: new KeyboardEvent("keydown"),
which: Keys.ESCAPE,
});
assert.isFalse(ctxMenu.find(Popover2).prop("isOpen"));
});
Expand Down
4 changes: 2 additions & 2 deletions packages/popover2/test/popover2Tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { mount, ReactWrapper, shallow } from "enzyme";
import * as React from "react";
import * as sinon from "sinon";

import { Classes as CoreClasses, Keys, Menu, MenuItem, Overlay, Portal } from "@blueprintjs/core";
import { Classes as CoreClasses, Menu, MenuItem, Overlay, Portal } from "@blueprintjs/core";
import { dispatchMouseEvent } from "@blueprintjs/test-commons";

import { Classes, Errors } from "../src";
Expand Down Expand Up @@ -832,8 +832,8 @@ describe("<Popover2>", () => {
};
wrapper.sendEscapeKey = () => {
wrapper!.findClass(CoreClasses.OVERLAY_OPEN).simulate("keydown", {
key: "Escape",
nativeEvent: new KeyboardEvent("keydown"),
which: Keys.ESCAPE,
});
return wrapper!;
};
Expand Down