feat(nav): peel overlays with esc, close the book on a second esc

This commit is contained in:
pj committed 2026-08-10 18:37:23 +05:30
1 parent 2e15dc2dc9
commit fe39274ed7
12 files changed
+130 -59

No files matched your search

+7 -5
View File
@@ -1,5 +1,6 @@
import { useEffect, useRef, useState } from "react";
import { PAGE_TYPES } from "../model/book";
import { useEscapeLayer } from "../escape";
import { Icon } from "./Icon";
interface AddPageMenuProps {
@@ -44,12 +45,13 @@ export function AddPageMenu({ onAdd, onAddPart }: AddPageMenuProps) {
popRef.current?.querySelector<HTMLElement>(".add-page-item")?.focus();
}, [open]);
useEscapeLayer(open, () => {
setOpen(false);
btnRef.current?.focus();
});
const onMenuKeyDown = (e: React.KeyboardEvent) => {
if (e.key === "Escape") {
e.preventDefault();
setOpen(false);
btnRef.current?.focus();
} else if (e.key === "ArrowDown" || e.key === "ArrowUp") {
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
e.preventDefault();
const items = Array.from(popRef.current?.querySelectorAll<HTMLElement>(".add-page-item") ?? []);
const idx = items.indexOf(document.activeElement as HTMLElement);