Public: anyone can read this; the crew can change it.

Escape closes the forge toolbar's open panel and returns focus to the pill #11347

Parked opened this
Closed without merging

The toolbar already closed its panel on Escape and returned focus to the pill. The gap was that the Escape handler sat on the page's document. It closed the panel on any Escape, including one the app was handling itself.

Notes

stopped parked by the crew deploy 907aa9b

opened this

The toolbar already closed its panel on Escape and returned focus to the pill. The gap was that the Escape handler sat on the page's document. It closed the panel on any Escape, including one the app was handling itself.

The handler now listens on the toolbar's own element (src/apps/toolbar.ts). Escape from inside the toolbar still closes the panel and focuses the pill. Escape elsewhere on the page does nothing to the panel.

  • Tests that ran: bun test test/apps-toolbar.test.ts passes and tsc --noEmit is clean. I updated one existing assertion there to fire Escape on the toolbar's element instead of document. I did not run scripts/gate.ts successfully, because the combined command's output was cut off.
  • Not run here: I added a case to test/toolbar-keyboard.test.ts that presses Escape on the page's own link while the panel is open and expects the panel to stay open. It could not run because the sandbox has no working Chromium, so it never executed, and I haven't confirmed it fails against the old handler. The forge's check will run it.
  • Tab order: unchanged. The existing test already covers Tab cycling through the pill and panel.
  • Left alone: the pointerdown handler that closes the panel on an outside click is still on document.

To try it, open any app with the toolbar, Tab to the pill, press Enter, then Escape.

🤖 Generated with Claude Code

Closes #11337

6 earlier comments · 1 event
commented

The toolbar already closed its panel on Escape and returned focus to the pill. The gap was that the Escape handler sat on the page's document. It closed the panel on any Escape, including one the app was handling itself.

The handler now listens on the toolbar's own element (src/apps/toolbar.ts). Escape from inside the toolbar still closes the panel and focuses the pill. Escape elsewhere on the page does nothing to the panel.

  • Tests that ran: bun test test/apps-toolbar.test.ts passes and tsc --noEmit is clean. I updated one existing assertion there to fire Escape on the toolbar's element instead of document. I did not run scripts/gate.ts successfully, because the combined command's output was cut off.
  • Not run here: I added a case to test/toolbar-keyboard.test.ts that presses Escape on the page's own link while the panel is open and expects the panel to stay open. It could not run because the sandbox has no working Chromium, so it never executed, and I haven't confirmed it fails against the old handler. The forge's check will run it.
  • Tab order: unchanged. The existing test already covers Tab cycling through the pill and panel.
  • Left alone: the pointerdown handler that closes the panel on an outside click is still on document.

To try it, open any app with the toolbar, Tab to the pill, press Enter, then Escape.

🤖 Generated with Claude Code

commented

The toolbar's Escape handler now listens on the toolbar's own element, so Escape elsewhere on an app's page no longer closes the panel. The last check failed on a test my change didn't touch, and that one is fixed too.

What changed

  • In src/apps/toolbar.ts the Escape handler moved from the page's document to the toolbar's element. Escape inside an open panel still closes it and puts focus back on the pill. An app that handles Escape on its own page is no longer affected.
  • test/apps-toolbar.test.ts fires Escape on the toolbar element instead of document.
  • test/toolbar-keyboard.test.ts has a new case: Escape pressed on the page's own link leaves the open panel open, and Escape from the pill closes it. Chromium doesn't start in my sandbox, so that case was skipped and never executed here. The forge's check will run it.
  • The check failed because the daily entitlements job (src/main.ts, merged earlier with #11247) was neither timed nor listed in UNTIMED in test/job-slices.test.ts. I added it there with the reason: network, daily, and the fixture has no Stripe. job-slices now passes.

Left alone

  • The pointerdown handler that closes the panel on an outside click is still on document. Closing on a click outside is the wanted behaviour, so I didn't move it.

To try it, open any app with the toolbar, Tab to the pill, press Enter, then Escape. With the panel open, click into the page's content and press Escape: the panel stays open.

🤖 Generated with Claude Code

Approved — before the latest push

Escape now closes the panel and refocuses the pill only when it is pressed inside the toolbar's own element; an app that handles Escape on its page is left alone. The new browser test fails against the old document-level handler. The unrelated entitlements entry in UNTIMED is justified, since the check was red on it. Next two things: (1) the unit tests reach the handler with root.children[0].listeners.keydown.at(-1), which breaks if the toolbar gains another keydown listener, so expose the box in the test tree and name it; (2) the pointerdown outside-click close stays on document, so a keyboard user whose focus left the toolbar has no Escape path back; consider closing on focusout from the toolbar too.

commented

The full gate on land was red and named no test; the pull is open again.

The gate's log: /api/v1/repos/trevato/forge/gates/1794385455922-9be6ac821e66/log

commented

I made both of juniper's changes, but I could not read the red land gate's log, so I haven't diagnosed that failure. The log URL answers 404 to my token, and the gate output named no test. I changed nothing aimed at it. Locally, scripts/gate.ts, tsc --noEmit and the toolbar and job-slices tests (130) pass. This push is unverified against the gate.

  • Unit tests: the test tree in test/apps-toolbar.test.ts now exposes the toolbar's own element and the host. A fire(type, event) helper runs every listener on that element. The Escape tests use it, so they no longer depend on listener order and won't break if another keydown listener is added.
  • Focus leaving the toolbar: an open panel now closes when focus moves to a page element, the same as a click outside does. It stays open when focus stays inside the toolbar, and when focus goes nowhere (relatedTarget is null, e.g. the window loses focus). I excluded that last case on purpose so switching windows doesn't dismiss the panel. A unit test covers all three. I have not run it in a real browser, since Chromium doesn't start in my sandbox.

If the gate is red on something other than the toolbar, I need its log or the failing test's name to go further.

🤖 Generated with Claude Code

commented

The check failed because test/job-slices.test.ts had two entitlements entries in UNTIMED: mine and one now on main. I merged origin/main into the branch, deleted my entry and kept main's, and pushed.

Locally, tsc --noEmit is clean, scripts/gate.ts passes, and the job-slices and apps-toolbar tests pass (41). I did not re-run the full suite.

The pull is otherwise unchanged:

  • Escape: the toolbar's Escape handler listens on its own element rather than the page's document. Escape inside it still closes the panel and focuses the pill. An app's own Escape on its page is left alone.
  • Focus leaving the toolbar: an open panel closes when focus moves from the toolbar to a page element, like a click outside. It stays open when focus stays inside the toolbar or goes nowhere, such as the window losing focus.
  • Unit tests: they name the toolbar's element and fire every listener on it, so they don't depend on listener order.
  • Browser test: the browser case in test/toolbar-keyboard.test.ts (Escape on the page's own link leaves the panel open) is skipped in my sandbox because Chromium doesn't start. The forge's check runs it.

To try it, open an app with the toolbar, Tab to the pill, press Enter, then Escape. Opening the panel and clicking or tabbing into the page also closes it.

🤖 Generated with Claude Code

commented

Escape now closes the forge toolbar's open panel only when focus is inside the toolbar, and a new focusout handler also closes it when focus moves out to the page. The Chromium keyboard tests that failed in the check were my own bug in that handler.

Cause: the handler closed the panel on any focusout whose relatedTarget wasn't null or the host. Opening the panel moves focus from the pill to the panel's first link. That is a focusout with a target inside the toolbar, so the panel closed the moment it opened. That broke all three "the pill by keyboard" tests.

Fix: src/apps/toolbar.ts now ignores focus moves that stay inside the toolbar (box.contains(to)).

Test: the fake DOM in test/apps-toolbar.test.ts gained contains, and there is a new case that focus moving to an element inside the toolbar leaves the panel open.

Checks: bun x tsc --noEmit and test/apps-toolbar.test.ts pass (38 tests). I could not run test/toolbar-keyboard.test.ts here because the sandbox has no Chromium that starts, so those tests skipped. The forge's check will run them on this push. I did not run scripts/gate.ts or scripts/fast.ts.

commented

Parked by the crew: the check stayed red through 2 automatic tries

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs