The design language that makes your AI harness better at design.
JavaScript
Fix: live prompt input loses focus to a modal focus trap (#851) (#920)
Abdul Wahab6c768d9baec2
diff --git a/skill/scripts/live-browser-dom.js b/skill/scripts/live-browser-dom.jsindex 63e222180..864694498 100644--- a/skill/scripts/live-browser-dom.js+++ b/skill/scripts/live-browser-dom.js@@ -242,6 +242,15 @@rootEl.addEventListener('focusin', stop);}+ // The half of the defang that cannot sit on the chrome: a focus trap (Radix /+ // Reka FocusScope) also hears the page's own focusout as focus leaves its+ // modal for our chrome, and pulls it back. Register on the document in+ // capture, ahead of the trap. The page's own focusout handlers miss that+ // one transition too; blur still fires.+ function stopFocusOutIntoChrome(e) {+ if (own(e.relatedTarget)) e.stopPropagation();+ }+return {own,pickable,@@ -261,6 +270,7 @@uiGetById,activeElementDeep,defangOutsideHandlers,+ stopFocusOutIntoChrome,};}diff --git a/skill/scripts/live-browser.js b/skill/scripts/live-browser.jsindex c4d229aff..c7eed77fb 100644--- a/skill/scripts/live-browser.js+++ b/skill/scripts/live-browser.js@@ -300,6 +300,7 @@uiGetById,activeElementDeep,defangOutsideHandlers,+ stopFocusOutIntoChrome,} = domHelpers;window.__IMPECCABLE_LIVE_CHROME_CORE__ = {@@ -12304,6 +12305,7 @@ void main() {document.removeEventListener('mousemove', handleMouseMove, true);document.removeEventListener('click', handleClick, true);document.removeEventListener('keydown', handleKeyDown, true);+ document.removeEventListener('focusout', stopFocusOutIntoChrome, true);window.removeEventListener('message', onDetectMessage);// Remove detection overlayswindow.postMessage({ source: 'impeccable-command', action: 'remove' }, '*');@@ -13489,6 +13491,7 @@ void main() {document.addEventListener('mousemove', handleMouseMove, true);document.addEventListener('click', handleClick, true);document.addEventListener('keydown', handleKeyDown, true);+ document.addEventListener('focusout', stopFocusOutIntoChrome, true);connectSSE();// Check for an active session to resume (variant wrapper already in DOM after HMR)diff --git a/tests/live-e2e.test.mjs b/tests/live-e2e.test.mjsindex 51ecd6d4a..7475859ee 100644--- a/tests/live-e2e.test.mjs+++ b/tests/live-e2e.test.mjs@@ -60,6 +60,7 @@ import {readComputedFontWeight,runLiveChromeBottomBarSmoke,setTuneRange,+ typeConfigurePrompt,waitForApplyDockHidden,waitForBarHidden,waitForComputedFontWeight,@@ -346,6 +347,8 @@ for (const { name, fixture } of fixtures) {t.diagnostic(`Bar after pick: ${JSON.stringify(barText)}`);}+ await typeConfigurePrompt(page, 'make it bolder');+t.diagnostic('Clicking Go');await clickGo(page);}diff --git a/tests/live-e2e/ui.mjs b/tests/live-e2e/ui.mjsindex 7b2bc259f..00cc8f680 100644--- a/tests/live-e2e/ui.mjs+++ b/tests/live-e2e/ui.mjs@@ -34,6 +34,7 @@ const DETECT_BADGE = '#impeccable-live-detect-badge';const DESIGN_TOGGLE = '#impeccable-live-design-toggle';const DESIGN_HOST = '#impeccable-live-design-host';const EXIT_BUTTON = '#impeccable-live-exit';+const CONFIGURE_INPUT_ID = '#impeccable-live-input';const INSERT_INPUT_ID = '#impeccable-live-insert-input';const INSERT_CREATE_ID = '#impeccable-live-insert-create';const ANNOTATION_ID = '#impeccable-live-annot';@@ -523,6 +524,28 @@ async function resetPickMode(page) {).catch(() => {});}+/**+ * Type the configure prompt the way a user does. The bar focuses its input+ * after a pick, so the keys land wherever focus really is: a host focus trap+ * that pulls focus back into its modal fails this (issue #851).+ */+export async function typeConfigurePrompt(page, prompt) {+ await page.waitForFunction(+ (sel) => {+ const input = window.__impeccableLiveQuery(sel);+ return Boolean(input) && window.__IMPECCABLE_LIVE_CHROME_CORE__?.activeElementDeep?.() === input;+ },+ CONFIGURE_INPUT_ID,+ { timeout: 5_000 },+ );+ await page.keyboard.type(prompt);+ await page.waitForFunction(+ ({ sel, value }) => window.__impeccableLiveQuery(sel)?.value === value,+ { sel: CONFIGURE_INPUT_ID, value: prompt },+ { timeout: 5_000 },+ );+}+/*** Set the variant count by clicking the count button (cycles 2 → 3 → 4 → 2).* Default is 3. If the desired count is already showing, this is a no-op.