fix: preserve drawer on dialog escape
This commit is contained in:
@@ -112,7 +112,7 @@ export function createFavoritesDrawer(
|
||||
};
|
||||
|
||||
const onDocumentKeydown = (event: KeyboardEvent) => {
|
||||
if (event.key !== "Escape" || !isOpen) {
|
||||
if (event.key !== "Escape" || !isOpen || event.defaultPrevented) {
|
||||
return;
|
||||
}
|
||||
if (document.querySelector("[data-sces-favorite-folder-dialog]")) {
|
||||
|
||||
@@ -484,6 +484,28 @@ describe("favorites-drawer", () => {
|
||||
expect(document.activeElement).toBe(restoredSearch);
|
||||
});
|
||||
|
||||
test("keeps a remounted drawer open after an earlier dialog handles Escape", async () => {
|
||||
const first = createHarness();
|
||||
first.controller.render(createState());
|
||||
readTab().click();
|
||||
|
||||
const dialogResult = promptForFavoriteFolderName(document, {
|
||||
title: "新建收藏夹"
|
||||
});
|
||||
first.controller.dispose();
|
||||
|
||||
const remounted = createHarness();
|
||||
remounted.controller.render(createState());
|
||||
readTab().click();
|
||||
document.dispatchEvent(
|
||||
new KeyboardEvent("keydown", { cancelable: true, key: "Escape" })
|
||||
);
|
||||
|
||||
await expect(dialogResult).resolves.toBeNull();
|
||||
expect(readDrawer().hidden).toBe(false);
|
||||
expect(readTab().getAttribute("aria-expanded")).toBe("true");
|
||||
});
|
||||
|
||||
test("calls create, rename, and delete handlers with the matching folder id", async () => {
|
||||
const onCreateFolder = vi.fn(async () => {});
|
||||
const onRenameFolder = vi.fn(async (_folderId: string) => {});
|
||||
|
||||
Reference in New Issue
Block a user