Elffuss BraidHub

utopia-ia/elffuss-claw public

coordinated: focus comes back after picking a brain, closing the Mind settings and locking the vault

Keyboard focus fell to <body> in three reworked controls:
- Choosing a brain disables the focused select while it loads, and focus
  never came back. modeloCargando() remembers that the select had focus and
  returns it when the load ends, unless the user moved on meanwhile.
- The ✕ of the Mind's settings panel left focus on <body> inside the modal
  Mind. It now returns focus to the settings button, like the history ✕.
- "Lock now" re-rendered the vault panel and lost focus. It now waits for
  the repaint the lock listener already does (no second paint) and focuses
  the master password field.

ux-modelo.mjs, ux-mente.mjs and ux-boveda.mjs drive each control with the
keyboard and check where focus lands; all three fail on the previous tree.
Changesetae80baa196ff421fd766c8b8c770f37e171f7118ca12aaf2e01b6e4adeaefa29
AuthorKikoCis <kikocisneros@gmail.com> · 2026-10-10 19:05 +02:00
CommitterKikoCis <kikocisneros@gmail.com> · 2026-10-11 17:51 +02:00
Parents12c4118caa51

Browse the files at this changeset

5 files changed

modified tests/ux-boveda.mjs +8 −0
@@ -4,6 +4,7 @@
44 // · 👁 enseña y vuelve a tapar (aria-pressed); el autobloqueo repinta el panel
55 // y tapa lo revelado; 🗑 pide confirmación con el nombre del secreto.
66 // · Un solo nombre por idioma: «Bóveda» en español.
7+// · «Bloquear ahora» con el teclado deja el foco en la contraseña.
78 //
89 // BASE=http://localhost:8743 node tests/ux-boveda.mjs
910 import { navegador, contexto, pagina, ok, hasta, espera, avisos, fin, OUT } from './ux-comun.mjs';
@@ -68,6 +69,13 @@
6869 p.__aceptar = true;
6970 await p.locator('#panel-vault .card', { hasText: 'correo' }).locator('button[aria-label^="Borrar"]').click();
7071 ok('y si dices que sí, se borra', await hasta(async () => !(await p.locator('#panel-vault .card b').allTextContents()).includes('correo')));
72+
73+// ── «Bloquear ahora» con el teclado: el foco va a la contraseña, no a <body> ─
74+await p.locator('#panel-vault button', { hasText: 'Bloquear ahora' }).focus();
75+await p.keyboard.press('Enter');
76+ok('«Bloquear ahora» con Enter deja el foco en la contraseña maestra', await hasta(() => p.evaluate(() =>
77+ document.activeElement?.id === 'vault-master' && document.querySelectorAll('#panel-vault form').length === 1)),
78+ await p.evaluate(() => document.activeElement?.id || document.activeElement?.tagName));
7179 if (OUT) await p.screenshot({ path: OUT + '/ux-boveda.png' });
7280 ok('sin errores de página', errores.length === 0, errores.slice(0, 3).join(' | '));
7381
modified tests/ux-mente.mjs +5 −1
@@ -113,7 +113,11 @@
113113 ok('los colores de perfil tienen nombre', await p.evaluate(() => [...document.querySelectorAll('.cp-color')].every(i => /^Color de /.test(i.getAttribute('aria-label') || ''))));
114114
115115 // ── ▶/⏸: siempre la verdad; Reprogramar no enciende ─────────────────────────
116-await p.click('#cfg-x');
116+await p.focus('#cfg-x');
117+await p.keyboard.press('Enter');
118+ok('✕ del panel ⚙ (con Enter) devuelve el foco a ⚙, no a <body>', await hasta(() => p.evaluate(() =>
119+ !document.getElementById('mind-cfg').classList.contains('show') && document.activeElement?.id === 'mind-config')),
120+ await p.evaluate(() => document.activeElement?.id || document.activeElement?.tagName));
117121 await p.click('#mind-playstop');
118122 ok('▶ enciende: el botón pasa a «pausar»', /pausar/.test(await p.locator('#mind-playstop').innerText()));
119123 await p.click('#mind-playstop');
modified tests/ux-modelo.mjs +7 −0
@@ -49,6 +49,13 @@
4949 ok('…mientras cargaba el selector estuvo desactivado y luego se reactivó', await p.evaluate(() =>
5050 window.__desactivado.includes(true) && !document.getElementById('model-select').disabled));
5151 ok('…y no te sacó de Ajustes para enseñar la descarga', await p.evaluate(() => document.querySelector('#tabs [aria-selected="true"]').dataset.tab === 'ajustes'));
52+// Con el teclado: el selector se desactiva mientras carga (y pierde el foco);
53+// al terminar, el foco vuelve a él (antes se quedaba en <body>).
54+await p.focus('#model-select');
55+await p.selectOption('#model-select', 'ext:openai');
56+ok('elegir cerebro con el teclado: al acabar la carga el foco vuelve al selector', await hasta(async () =>
57+ await listo() && await p.evaluate(() => !document.getElementById('model-select').disabled && document.activeElement?.id === 'model-select')),
58+ await p.evaluate(() => document.activeElement?.id || document.activeElement?.tagName));
5259 await escribir(p, 'hola');
5360 ok('el cerebro que funcionaba sigue contestando', await hasta(async () => /respuesta de ollama/.test(await p.locator('#log').innerText())));
5461 await reposo(p);
modified web/js/mind.js +2 −1
@@ -348,7 +348,8 @@
348348 '<div class="cfg-note">' + escHtml(t('mindCfgNote')) + '</div>';
349349 const x = cfg.querySelector('#cfg-x');
350350 x.setAttribute('aria-label', t('close'));
351- x.onclick = () => cfg.classList.remove('show');
351+ // El foco vuelve a ⚙ (antes se quedaba en <body>, dentro de la Mente modal).
352+ x.onclick = () => { cfg.classList.remove('show'); root.querySelector('#mind-config')?.focus(); };
352353 // Dónde escribe de verdad (en Claw, la primera carpeta autorizada).
353354 Promise.resolve().then(() => etiquetaAlma()).then(txt => {
354355 const l = cfg.querySelector('#cfg-dir-label'); if (l && txt) l.textContent = txt;
modified web/js/ui.js +21 −4
@@ -586,11 +586,11 @@
586586 // bóveda se cierra sola: antes seguía ofreciendo «Bloquear ahora» y un secreto
587587 // revelado se quedaba en claro.
588588 const VAULT_REVELADO_MS = 30000; // un secreto a la vista se vuelve a tapar solo
589-let vaultOyente = null;
589+let vaultOyente = null, vaultRepintado = Promise.resolve();
590590 const tabActiva = () => document.querySelector('#tabs button.active')?.dataset.tab;
591591 export async function refreshVault() {
592592 vaultOyente ||= vault.alBloquear(motivo => {
593- if (tabActiva() === 'vault') refreshVault();
593+ if (tabActiva() === 'vault') vaultRepintado = refreshVault();
594594 if (motivo === 'auto') toast(tr('vaultAutoLocked'));
595595 });
596596 const panel = $('panel-vault');
@@ -630,8 +630,15 @@
630630 }
631631
632632 const estado = el('div', 'row between');
633+ // Al bloquear el panel se repinta (y el botón desaparece): el foco va a la
634+ // contraseña, que es lo siguiente que se usa; antes caía a <body>.
633635 estado.append(el('span', 'muted', tr('vaultOpenState')),
634- btn(tr('vaultLockNow'), 'ghost', () => { vault.lock(); toast(tr('vaultLockedNow')); }));
636+ btn(tr('vaultLockNow'), 'ghost', async () => {
637+ vault.lock(); // el oyente de alBloquear repinta el panel…
638+ toast(tr('vaultLockedNow'));
639+ await vaultRepintado; // …y se espera a ese repintado, sin pintar dos veces
640+ $('panel-vault').querySelector('#vault-master')?.focus();
641+ }));
635642 panel.appendChild(estado);
636643
637644 const form = el('form', 'row');
@@ -807,11 +814,21 @@
807814 }
808815
809816 // Mientras carga un cerebro el selector se desactiva: elegir otro a la vez
810-// arrancaba una segunda carga en paralelo.
817+// arrancaba una segunda carga en paralelo. Un control desactivado pierde el
818+// foco (cae a <body>), así que se recuerda y, al terminar, el foco vuelve al
819+// selector si nadie lo ha llevado a otra parte mientras tanto.
820+let selectorTeniaFoco = false;
811821 export function modeloCargando(on) {
812822 const sel = $('model-select');
823+ if (on) selectorTeniaFoco = selectorTeniaFoco || document.activeElement === sel;
813824 sel.disabled = !!on;
814825 if (on) sel.setAttribute('aria-busy', 'true'); else sel.removeAttribute('aria-busy');
826+ if (!on && selectorTeniaFoco) {
827+ selectorTeniaFoco = false;
828+ if (!document.activeElement || document.activeElement === document.body) {
829+ try { sel.focus({ preventScroll: true }); } catch { /* — */ }
830+ }
831+ }
815832 }
816833
817834 // ⓘ junto al selector: la ficha del modelo cargado en Hugging Face (un