Elffuss BraidHub

utopia-ia/elffuss-code public

Extensions panel: a dialog with its own name, Escape returns focus, the theme picker keeps it open

The Extensions panel is drawn in the box Settings and Skills use. Settings
gives that box role=dialog and aria-labelledby="settings-title" and never
removes them, and the panel has no element with that id: after Settings had
been opened once, the panel was announced as a dialog with no name, and before
that it had no dialog role at all. The panel now sets the role itself and
points aria-labelledby at its own heading ("Extensions · Open VSX").

Escape with focus outside the panel's controls (after clicking its text, focus
is on <body>) went to the page's Escape handler, which closed it through
Settings' close. That one does not know who opened the panel, so focus stayed
on <body>. The handler now closes the panel with the panel's own close, which
returns focus to its opener.

The Color Theme picker opened from the panel hangs from <body>, outside the
box, so the "click outside closes Settings" handler took any mouse click in it
(an option, or its search box) for an outside click and closed the panel
underneath; focus then fell to the editor, or to <body> on phones. Clicks in
the picker no longer count as outside.

tests/extensions.mjs: a mouse pick leaves the panel open with focus back on
the Color Theme button, a click in the picker's box does not close the panel,
the panel is a dialog named "Extensions · Open VSX" both before and after
opening Settings, and Escape with focus on <body> closes it and returns focus
to the Extensions button.
Changeset9e18172235f0bf4333d2a3ea8512b3d61e62f5e83b215904f3aba9adc15bed2d
AuthorKikoCis <kikocisneros@gmail.com> · 2026-10-11 17:34 +02:00
CommitterKikoCis <kikocisneros@gmail.com> · 2026-10-11 17:34 +02:00
Parents074b411115db

Browse the files at this changeset

3 files changed

modified tests/extensions.mjs +36 −0
@@ -189,6 +189,18 @@
189189 await p.click('#ext-themepick .tp-item[data-theme="vs"]');
190190 ok('selector: tema claro de serie elegido', await hasta(async () => (await fondo()) === 'rgb(255, 255, 254)'), await fondo());
191191 ok('…y la gramática se repinta con colores de Light+', await colorDe('spell', '#AF00DB'), JSON.stringify(await estilo('spell')));
192+// El selector cuelga de <body>, fuera de la caja del panel: el «clic fuera
193+// cierra Ajustes» tomaba cualquier clic en él por uno de fuera y cerraba el panel
194+// de debajo; el foco acababa en el editor (o en <body> en el móvil).
195+const trasElegir = () => p.evaluate(() => ({ panel: !document.getElementById('settings-panel').hidden && !!document.getElementById('ext-panel')?.isConnected, foco: document.activeElement?.id || document.activeElement?.className }));
196+ok('selector: elegir con el ratón deja el panel abierto y el foco vuelve a su botón', await hasta(async () => { const e = await trasElegir(); return e.panel && e.foco === 'ext-theme-btn'; }), JSON.stringify(await trasElegir()));
197+await p.click('#ext-theme-btn');
198+await p.waitForSelector('#ext-themepick');
199+await p.click('#ext-themepick input');
200+await sleep(200);
201+ok('selector: pinchar en su buscador tampoco cierra el panel', await p.evaluate(() => !document.getElementById('settings-panel').hidden && !!document.getElementById('ext-themepick')));
202+await p.keyboard.press('Escape');
203+await hasta(() => p.evaluate(() => !document.getElementById('ext-themepick')));
192204 // el ● de «sin guardar» con un tema claro (era casi blanco sobre blanco, y es
193205 // el único aviso: cerrar la pestaña no pregunta)
194206 await abre('app.js');
@@ -276,6 +288,30 @@
276288 await p.focus('#ext-q');
277289 await p.keyboard.press('Escape');
278290 ok('panel: Escape lo cierra y el foco vuelve al botón de Extensiones', await hasta(() => p.evaluate(() => document.getElementById('settings-panel').hidden && document.activeElement?.id === 'act-ext')), JSON.stringify(await activo()));
291+// J1b. Es un diálogo con nombre, se haya abierto Ajustes antes o no. La caja es
292+// la de Ajustes, y Ajustes le deja aria-labelledby a SU título, que aquí no
293+// existe: el panel era un diálogo sin nombre (o, sin pasar por Ajustes, ni
294+// siquiera un diálogo).
295+const dialogo = async () => ({
296+ ...(await p.evaluate(() => { const box = document.getElementById('settings-panel'); const lb = box.getAttribute('aria-labelledby'); return { role: box.getAttribute('role'), nombre: lb ? (document.getElementById(lb)?.textContent ?? 'NO EXISTE') : null }; })),
297+ arbol: (await p.locator('#settings-panel').ariaSnapshot()).split('\n')[0],
298+});
299+await abrePanel();
300+let d = await dialogo();
301+ok('panel: un diálogo que se llama «Extensions…»', d.role === 'dialog' && /^Extensions\b/.test(d.nombre || '') && /^- dialog "Extensions/.test(d.arbol), JSON.stringify(d));
302+await p.click('#settings-close');
303+await p.click('#btn-settings');
304+await p.waitForSelector('#settings-title');
305+await p.keyboard.press('Escape');
306+await abrePanel();
307+d = await dialogo();
308+ok('…también después de abrir y cerrar Ajustes (antes: un diálogo sin nombre)', d.role === 'dialog' && /^Extensions\b/.test(d.nombre || '') && /^- dialog "Extensions/.test(d.arbol), JSON.stringify(d));
309+// J1c. Escape con el foco fuera de los controles del panel (tras pinchar en su
310+// texto, el foco está en <body>): lo cierra el Escape general de la página, y el
311+// foco también vuelve a quien lo abrió (antes se quedaba en <body>).
312+await p.click('#ext-panel .ext-intro');
313+await p.keyboard.press('Escape');
314+ok('panel: Escape con el foco en <body> lo cierra y el foco vuelve al botón de Extensiones', await hasta(() => p.evaluate(() => document.getElementById('settings-panel').hidden && document.activeElement?.id === 'act-ext')), JSON.stringify(await activo()));
279315
280316 // J2. errores en el idioma de la interfaz, como alerta
281317 await abrePanel();
modified web/js/ext/panel.js +10 −0
@@ -63,6 +63,9 @@
6363 $('settings-panel').hidden = true;
6464 devuelveFoco(abridor, $('act-ext'), document.querySelector('#menubar button[data-menu="view"]'), enfocaEditor, $('prompt'));
6565 }
66+// Para el Escape global de main.js (la capa de más arriba): cerrar el panel de
67+// extensiones es esto, no cerrar Ajustes, que no sabe quién lo abrió.
68+export function close() { if ($('ext-panel')?.isConnected && !$('settings-panel').hidden) cierraPanel(); }
6669
6770 // ── mensajes legibles (exportados para las pruebas en Node) ──
6871 const ERRORES = {
@@ -165,6 +168,12 @@
165168 const box = $('settings-panel');
166169 box.hidden = false;
167170 box.replaceChildren();
171+ // Es un diálogo con su propio nombre. La caja la comparten Ajustes y Skills,
172+ // y Ajustes le deja role=dialog con aria-labelledby a su título: abierto
173+ // Ajustes antes, este panel quedaba como un diálogo sin nombre (ese título
174+ // aquí no existe), y si no, sin rol de diálogo.
175+ box.setAttribute('role', 'dialog');
176+ box.setAttribute('aria-labelledby', 'ext-title');
168177 const cerrar = el('button', null, '✕');
169178 cerrar.id = 'settings-close';
170179 cerrar.type = 'button';
@@ -177,6 +186,7 @@
177186 wrap.addEventListener('keydown', conEscape);
178187 cerrar.addEventListener('keydown', conEscape);
179188 const h3 = el('h3', null, tx('title') + ' ');
189+ h3.id = 'ext-title';
180190 h3.appendChild(el('span', 'muted', '· ' + tx('sub')));
181191 wrap.append(h3, el('p', 'muted ext-intro', tx('intro')));
182192 if (host.paused) wrap.appendChild(el('p', 'ext-paused', tx('paused')));
modified web/js/main.js +12 −4
@@ -2245,11 +2245,14 @@
22452245 if (!p.hidden) return cierraAjustes();
22462246 renderSettings();
22472247 });
2248-// clic fuera del panel (o ir a Archivo/chat) lo cierra — antes solo la X lo hacía
2248+// clic fuera del panel (o ir a Archivo/chat) lo cierra — antes solo la X lo hacía.
2249+// El selector de tema que se abre desde el panel de extensiones cuelga de
2250+// <body>, pero es del panel: elegir un tema con el ratón (o pinchar en su
2251+// buscador) cerraba el panel de debajo y el foco caía en el editor o en <body>.
22492252 document.addEventListener('pointerdown', e => {
22502253 const p = $('settings-panel');
22512254 if (p.hidden) return;
2252- if (p.contains(e.target) || e.target.closest('#btn-settings, #act-settings, #model-dot')) return;
2255+ if (p.contains(e.target) || e.target.closest('#btn-settings, #act-settings, #model-dot, #ext-themepick')) return;
22532256 p.hidden = true;
22542257 volverDeAjustes = null;
22552258 }, true);
@@ -2263,7 +2266,10 @@
22632266 { abierta: () => !$('topmenu').hidden, cerrar: () => cierraMenuBarra({ foco: true }) },
22642267 { abierta: () => !$('modos-menu')?.hidden, cerrar: () => cierraModos({ foco: true }) },
22652268 { abierta: () => !$('history-panel').hidden, cerrar: () => cierraHistorial() },
2266- { abierta: () => !$('settings-panel').hidden, cerrar: () => cierraAjustes() },
2269+ // El panel de extensiones se pinta en la misma caja que Ajustes: se cierra con
2270+ // lo suyo, que devuelve el foco a quien lo abrió (cierraAjustes no lo sabe y
2271+ // el foco caía en <body>).
2272+ { abierta: () => !$('settings-panel').hidden, cerrar: () => ($('ext-panel')?.isConnected && panelExt ? panelExt.close() : cierraAjustes()) },
22672273 { abierta: () => !$('view-overlay').hidden, cerrar: () => closeView({ foco: true }) },
22682274 { abierta: () => document.body.classList.contains('drawer-open'), cerrar: () => abreCajon(false) },
22692275 ];
@@ -3132,10 +3138,12 @@
31323138 // Extensiones de VS Code (temas, gramáticas, snippets, lenguajes): js/ext/.
31333139 // Nada de eso se carga hasta que se usa; el panel y el host llegan al pulsar.
31343140 function extTexto(es, en) { return uiLang() === 'es' ? es : en; }
3141+let panelExt = null; // el módulo del panel, una vez cargado (lo usa el Escape global)
31353142 async function openExtensions(opts = {}) {
31363143 const host = await loadExt();
31373144 if (!host) { $('statusbar').textContent = t('openProjFirst'); return; }
3138- (await import('./ext/panel.js')).open(host, opts);
3145+ panelExt = await import('./ext/panel.js');
3146+ panelExt.open(host, opts);
31393147 }
31403148 $('act-ext').innerHTML = ACTIVITY.extensions;
31413149 $('act-ext').title = extTexto('Extensiones (temas, gramáticas, snippets)', 'Extensions (themes, grammars, snippets)');