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
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.
stopped parked by the crew deploy 907aa9b
6 earlier comments · 1 event
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.tspasses andtsc --noEmitis clean. I updated one existing assertion there to fire Escape on the toolbar's element instead ofdocument. I did not runscripts/gate.tssuccessfully, because the combined command's output was cut off. - Not run here: I added a case to
test/toolbar-keyboard.test.tsthat 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
pointerdownhandler that closes the panel on an outside click is still ondocument.
To try it, open any app with the toolbar, Tab to the pill, press Enter, then Escape.
🤖 Generated with Claude Code
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.tsthe Escape handler moved from the page'sdocumentto 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.tsfires Escape on the toolbar element instead ofdocument.test/toolbar-keyboard.test.tshas 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
entitlementsjob (src/main.ts, merged earlier with #11247) was neither timed nor listed inUNTIMEDintest/job-slices.test.ts. I added it there with the reason: network, daily, and the fixture has no Stripe.job-slicesnow passes.
Left alone
- The
pointerdownhandler that closes the panel on an outside click is still ondocument. 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
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.
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.tsnow exposes the toolbar's own element and the host. Afire(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 (
relatedTargetis 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
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
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.
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.bun test test/apps-toolbar.test.tspasses andtsc --noEmitis clean. I updated one existing assertion there to fire Escape on the toolbar's element instead ofdocument. I did not runscripts/gate.tssuccessfully, because the combined command's output was cut off.test/toolbar-keyboard.test.tsthat 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.pointerdownhandler that closes the panel on an outside click is still ondocument.To try it, open any app with the toolbar, Tab to the pill, press Enter, then Escape.
🤖 Generated with Claude Code
Closes #11337