Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(web): keep settings escape within focused forms

Tin5bbe6df13858
diff --git a/apps/web/src/components/settings/nav/should-leave-on-escape.test.ts b/apps/web/src/components/settings/nav/should-leave-on-escape.test.ts
index d919b5008..a7a2a8e06 100644
--- a/apps/web/src/components/settings/nav/should-leave-on-escape.test.ts
+++ b/apps/web/src/components/settings/nav/should-leave-on-escape.test.ts
@@ -39,6 +39,28 @@ describe("shouldLeaveOnEscape", () => {
expect(shouldLeaveOnEscape(escapeFrom(input), document)).toBe(false);
});
+ it.each(["switch", "checkbox", "radio"])(
+ "leaves Escape to a focused %s control",
+ (role) => {
+ const control = document.createElement("button");
+ control.setAttribute("role", role);
+ const child = document.createElement("span");
+ control.append(child);
+ document.body.append(control);
+ expect(shouldLeaveOnEscape(escapeFrom(control), document)).toBe(false);
+ expect(shouldLeaveOnEscape(escapeFrom(child), document)).toBe(false);
+ },
+ );
+
+ it("leaves Escape to buttons within a settings form", () => {
+ const form = document.createElement("form");
+ const button = document.createElement("button");
+ form.append(button);
+ document.body.append(form);
+ expect(shouldLeaveOnEscape(escapeFrom(button), document)).toBe(false);
+ expect(shouldLeaveOnEscape(escapeFrom(document.body), document)).toBe(true);
+ });
+
it("leaves Escape to open dialogs and popups", () => {
const dialog = document.createElement("div");
dialog.setAttribute("role", "dialog");
diff --git a/apps/web/src/components/settings/nav/should-leave-on-escape.ts b/apps/web/src/components/settings/nav/should-leave-on-escape.ts
index c5f753034..dc3f9009a 100644
--- a/apps/web/src/components/settings/nav/should-leave-on-escape.ts
+++ b/apps/web/src/components/settings/nav/should-leave-on-escape.ts
@@ -1,5 +1,5 @@
// Escape belongs to whatever is open on top of the page (dialogs, menus,
-// selects, the mobile nav sheet) and to text fields; only a bare Escape on
+// selects, the mobile nav sheet) and to forms and controls; only a bare Escape on
// the settings page itself leaves settings. Closed Base UI popups can stay
// mounted (hidden, with data-closed), so only count the open ones.
const OVERLAY_SELECTOR = [
@@ -37,6 +37,9 @@ export function shouldLeaveOnEscape(event: KeyboardEvent, root: ParentNode) {
if (
target instanceof HTMLElement &&
(target.isContentEditable ||
+ target.closest(
+ 'form, [role="switch"], [role="checkbox"], [role="radio"]',
+ ) ||
target.tagName === "INPUT" ||
target.tagName === "TEXTAREA" ||
target.tagName === "SELECT")