Elffuss BraidHub

utopia-ia/elffuss-claw public

The typed "/" menu is a combobox, and commands answer to English names

Typing "/" put aria-activedescendant on the prompt, pointing at
role=menuitem rows of a separate role=menu that the prompt neither
owned nor controlled. That is not a valid ARIA pattern, and screen
readers announced it unreliably.

The prompt is now a combobox (aria-controls=cmd-menu, aria-expanded,
aria-autocomplete=list). When the menu is opened by typing, it is a
listbox with role=option rows, the active one marked aria-selected and
pointed at by aria-activedescendant. Opened from the "/" button, with
focus inside it, it stays a role=menu with menuitems, and the prompt is
not marked expanded.

On non-Spanish pages the commands only existed as Spanish words, so
/settings, /tasks or /clear found nothing. Each command now also has an
English name, shown on non-Spanish pages; both names filter. When no
name matches, the menu searches the words of what each command does
(/keyb finds /shortcuts).

ux-teclado.mjs checks the combobox and listbox attributes while typing,
arrow keys and Escape, the menu role when opened from the button, and
the English names and filters on an en-US page. The new checks fail on
the previous code.
Changesetbbb632dbf8f468bb3e99d0f173d9cb1febd63330d78488352668e8a5b6e3c2a7
AuthorKikoCis <kikocisneros@gmail.com> · 2026-10-11 20:47 +02:00
CommitterKikoCis <kikocisneros@gmail.com> · 2026-10-11 20:47 +02:00
Parents3a574525cee8

Browse the files at this changeset

2 files changed

modified tests/ux-teclado.mjs +49 −0
@@ -3,6 +3,12 @@
33 // entra, ↑/↓ se mueven, Escape cierra y devuelve el foco.
44 // · Escribiendo «/sk» filtra, Enter ejecuta el marcado y la caja queda limpia y
55 // con el foco; un «/» suelto no se manda nunca; /modelo lleva al selector.
6+// · Escribiendo, la caja es un combobox (aria-controls, aria-expanded) y el
7+// menú una lista con su opción marcada (aria-selected), que la caja señala
8+// con aria-activedescendant; con el botón, el menú es un role=menu.
9+// · En inglés los comandos se llaman en inglés (/settings, /tasks, /clear…) y
10+// los nombres en español siguen valiendo; si ningún nombre empieza así, se
11+// busca en lo que hace cada uno.
612 // · «?» fuera de la caja enseña los atajos; «/» fuera de la caja abre el menú.
713 // · Chips: botones, seis, sin repetidos, en el idioma de la página; «Autoriza
814 // una carpeta» abre el selector en el propio clic.
@@ -36,9 +42,32 @@
3642 ok('↓ pasa a la siguiente opción', await p.evaluate(() => document.activeElement?.textContent.startsWith('/carpeta')));
3743 await p.keyboard.press('Escape');
3844 ok('Escape cierra el menú y devuelve el foco al botón', !(await menuAbierto()) && await foco() === 'btn-slash');
45+ok('…abierto con el botón, la caja de texto no se da por desplegada', await p.getAttribute('#prompt', 'aria-expanded') === 'false');
3946
4047 // ── escribiendo «/» ─────────────────────────────────────────────────────────
4148 await p.focus('#prompt');
49+const aria = () => p.evaluate(() => {
50+ const c = document.getElementById('prompt'), m = document.getElementById('cmd-menu');
51+ const ad = c.getAttribute('aria-activedescendant');
52+ const sel = ad ? document.getElementById(ad) : null;
53+ return { role: c.getAttribute('role'), expanded: c.getAttribute('aria-expanded'), controls: c.getAttribute('aria-controls'),
54+ autocomplete: c.getAttribute('aria-autocomplete'), menu: m.getAttribute('role'), ad,
55+ dentro: !!sel && m.contains(sel), opcion: sel?.getAttribute('role'), elegida: sel?.getAttribute('aria-selected'),
56+ otras: [...m.querySelectorAll('[role=option]')].filter(o => o !== sel && o.getAttribute('aria-selected') !== 'false').length,
57+ texto: sel?.querySelector('b')?.textContent };
58+});
59+ok('en reposo la caja es un combobox plegado que controla el menú', await aria().then(a => a.role === 'combobox' && a.expanded === 'false'
60+ && a.controls === 'cmd-menu' && a.autocomplete === 'list' && !a.ad));
61+await p.keyboard.type('/');
62+const a1 = await aria();
63+ok('escribiendo «/»: la caja se despliega y señala una opción de la lista (listbox/option, aria-selected)', a1.expanded === 'true'
64+ && a1.menu === 'listbox' && a1.dentro && a1.opcion === 'option' && a1.elegida === 'true' && a1.otras === 0 && a1.texto === '/reloj', JSON.stringify(a1));
65+await p.keyboard.press('ArrowDown');
66+const a2 = await aria();
67+ok('…↓ mueve la opción señalada y su aria-selected', a2.texto === '/carpeta' && a2.elegida === 'true' && a2.otras === 0 && a2.ad !== a1.ad, JSON.stringify(a2));
68+await p.keyboard.press('Escape');
69+ok('…y Escape la pliega (sin opción señalada)', await aria().then(a => a.expanded === 'false' && !a.ad), JSON.stringify(await aria()));
70+await p.fill('#prompt', '');
4271 await p.keyboard.type('/sk');
4372 ok('«/sk» filtra: solo /skills', await hasta(async () => (await p.locator('#cmd-menu .cmd-item b').allTextContents()).join(',') === '/skills'));
4473 await p.keyboard.press('Enter');
@@ -84,6 +113,26 @@
84113 const es = ['Hazme un reloj', 'Crea una app de notas', 'Autoriza una carpeta', 'Créame una skill para organizar mis descargas', 'Busca fotos de auroras boreales', 'Abre https://example.com'];
85114 ok('en inglés: seis chips en inglés', en.length === 6 && !en.some(t => es.includes(t)) && en[0] === 'Make me a clock', JSON.stringify(en));
86115 ok('en inglés el botón «/» se llama «Commands and skills»', await e.getAttribute('#btn-slash', 'aria-label') === 'Commands and skills');
116+ const busca = async q => {
117+ await e.fill('#prompt', '');
118+ await e.focus('#prompt');
119+ await e.keyboard.type(q);
120+ await espera(100);
121+ const r = await e.$$eval('#cmd-menu .cmd-item b', bs => bs.map(x => x.textContent));
122+ await e.keyboard.press('Escape');
123+ return r;
124+ };
125+ const r = { settings: await busca('/settings'), tasks: await busca('/tasks'), clear: await busca('/clear'), ajustes: await busca('/ajustes'),
126+ todos: await busca('/'), teclado: await busca('/keyb') };
127+ ok('en inglés los comandos se llaman en inglés y /settings, /tasks y /clear los encuentran', r.settings.join() === '/settings'
128+ && r.tasks.join() === '/tasks' && r.clear.join() === '/clear' && r.todos.includes('/clock') && !r.todos.includes('/reloj'), JSON.stringify(r));
129+ ok('…el nombre en español sigue valiendo (/ajustes → /settings)', r.ajustes.join() === '/settings', JSON.stringify(r.ajustes));
130+ ok('…y si ningún nombre empieza así, busca en lo que hace cada uno (/keyb → /shortcuts)', r.teclado.join() === '/shortcuts', JSON.stringify(r.teclado));
131+ await e.fill('#prompt', '');
132+ await e.focus('#prompt');
133+ await e.keyboard.type('/settings');
134+ await e.keyboard.press('Enter');
135+ ok('…y Enter en /settings abre Settings', await hasta(() => e.evaluate(() => document.getElementById('panel-ajustes').classList.contains('active'))));
87136 await c2.close();
88137 }
89138
modified web/js/ui.js +45 −19
@@ -1757,49 +1757,71 @@
17571757 // Enter ejecuta el marcado; un «/» suelto nunca se manda al modelo. Después
17581758 // de ejecutar, la caja queda limpia y con el foco.
17591759 const verPanel = tab => { selectTab(tab, { push: true }); if (isMobile()) flipTo('viz'); };
1760+ // Cada comando tiene su nombre en español y en inglés. Se ENSEÑA el de la
1761+ // página (español en español, inglés en los demás) y, escribiendo, valen los
1762+ // dos: en inglés, /settings, /tasks o /clear no encontraban nada. Si ningún
1763+ // nombre empieza así, se busca en lo que hace cada uno (su pista).
17601764 const cmds = [
1761- { label: '/reloj', hint: tr('cmClock'), run: () => onSend(tr('pClock')) },
1762- { label: '/carpeta', hint: tr('cmFolder'), run: () => onPickFolder() }, // el selector nativo se abre en el gesto
1763- { label: '/skills', hint: tr('cmSkills'), run: () => verPanel('skills') },
1764- { label: '/modelo', hint: tr('cmModel'), run: () => enfocarSelectorModelo(), foco: false },
1765- { label: '/ajustes', hint: tr('cmSettings'), run: () => verPanel('ajustes') },
1766- { label: '/tareas', hint: tr('cmTasks'), run: () => verPanel('tareas') },
1767- { label: '/vault', hint: tr('cmVault'), run: () => verPanel('vault') },
1768- { label: '/limpiar', hint: tr('cmClear'), run: () => $('btn-clear').click() },
1769- { label: '/atajos', hint: tr('cmKeys'), run: () => mostrarAtajos(), foco: false },
1765+ { label: '/reloj', en: '/clock', hint: tr('cmClock'), run: () => onSend(tr('pClock')) },
1766+ { label: '/carpeta', en: '/folder', hint: tr('cmFolder'), run: () => onPickFolder() }, // el selector nativo se abre en el gesto
1767+ { label: '/skills', en: '/skills', hint: tr('cmSkills'), run: () => verPanel('skills') },
1768+ { label: '/modelo', en: '/model', hint: tr('cmModel'), run: () => enfocarSelectorModelo(), foco: false },
1769+ { label: '/ajustes', en: '/settings', hint: tr('cmSettings'), run: () => verPanel('ajustes') },
1770+ { label: '/tareas', en: '/tasks', hint: tr('cmTasks'), run: () => verPanel('tareas') },
1771+ { label: '/vault', en: '/vault', hint: tr('cmVault'), run: () => verPanel('vault') },
1772+ { label: '/limpiar', en: '/clear', hint: tr('cmClear'), run: () => $('btn-clear').click() },
1773+ { label: '/atajos', en: '/shortcuts', hint: tr('cmKeys'), run: () => mostrarAtajos(), foco: false },
17701774 ];
1775+ const nombreCmd = c => (uiLang() === 'es' ? c.label : c.en);
17711776 const cmdMenu = $('cmd-menu');
17721777 const slash = $('btn-slash');
17731778 const caja = $('prompt');
1774- cmdMenu.setAttribute('role', 'menu');
17751779 cmdMenu.setAttribute('aria-label', tr('cmdMenuL'));
17761780 slash.setAttribute('aria-haspopup', 'menu');
17771781 slash.setAttribute('aria-controls', 'cmd-menu');
17781782 slash.setAttribute('aria-expanded', 'false');
17791783 slash.title = tr('cmdMenuL');
17801784 slash.setAttribute('aria-label', tr('cmdMenuL'));
1785+ // Dos formas, dos patrones de ARIA. Escribiendo «/» el foco se queda en la caja:
1786+ // la caja es un combobox (aria-controls, aria-expanded) y el menú una lista
1787+ // (listbox) con su opción marcada (aria-selected), que la caja señala con
1788+ // aria-activedescendant. Antes la caja señalaba elementos de un role=menu que
1789+ // no era suyo, y los lectores de pantalla lo anunciaban mal o nada. Con el botón
1790+ // «/» el foco entra en el menú: ese sí es un role=menu con menuitems.
1791+ caja.setAttribute('role', 'combobox');
1792+ caja.setAttribute('aria-autocomplete', 'list');
1793+ caja.setAttribute('aria-controls', 'cmd-menu');
1794+ caja.setAttribute('aria-expanded', 'false');
17811795 const sinTilde = x => x.normalize('NFD').replace(/[̀-ͯ]/g, '').toLowerCase();
1782- let visibles = [], activo = -1;
1796+ let visibles = [], activo = -1, comoLista = false;
17831797 const filas = () => [...cmdMenu.querySelectorAll('.cmd-item')];
17841798 const marcar = i => {
17851799 const fs = filas();
17861800 activo = fs.length ? (i + fs.length) % fs.length : -1;
1787- fs.forEach((f, j) => f.classList.toggle('activo', j === activo));
1788- if (activo >= 0) { caja.setAttribute('aria-activedescendant', fs[activo].id); fs[activo].scrollIntoView({ block: 'nearest' }); }
1801+ fs.forEach((f, j) => {
1802+ f.classList.toggle('activo', j === activo);
1803+ if (comoLista) f.setAttribute('aria-selected', j === activo ? 'true' : 'false');
1804+ });
1805+ if (activo >= 0 && comoLista) caja.setAttribute('aria-activedescendant', fs[activo].id);
17891806 else caja.removeAttribute('aria-activedescendant');
1807+ if (activo >= 0) fs[activo].scrollIntoView({ block: 'nearest' });
17901808 };
17911809 const pintarMenu = (filtro = '/') => {
17921810 const f = sinTilde(filtro);
1793- visibles = cmds.filter(c => sinTilde(c.label).startsWith(f));
1811+ const porNombre = cmds.filter(c => [c.label, c.en].some(n => sinTilde(n).startsWith(f)));
1812+ const palabra = f.replace(/^\//, '');
1813+ visibles = porNombre.length || palabra.length < 3 ? porNombre
1814+ : cmds.filter(c => sinTilde(c.hint).split(/[^\p{L}\p{N}]+/u).some(w => w.startsWith(palabra)));
1815+ cmdMenu.setAttribute('role', comoLista ? 'listbox' : 'menu');
17941816 cmdMenu.replaceChildren();
17951817 visibles.forEach((c, i) => {
17961818 const row = document.createElement('button');
17971819 row.type = 'button';
17981820 row.className = 'cmd-item';
17991821 row.id = 'cmd-' + i;
1800- row.setAttribute('role', 'menuitem');
1822+ row.setAttribute('role', comoLista ? 'option' : 'menuitem');
18011823 row.tabIndex = -1;
1802- const b = document.createElement('b'); b.textContent = c.label;
1824+ const b = document.createElement('b'); b.textContent = nombreCmd(c);
18031825 const h = document.createElement('span'); h.textContent = c.hint;
18041826 row.append(b, h);
18051827 row.onclick = () => ejecutar(c);
@@ -1808,15 +1830,19 @@
18081830 if (!visibles.length) cmdMenu.appendChild(el('div', 'cmd-vacio', tr('cmNone')));
18091831 marcar(0);
18101832 };
1811- const abrirMenu = (filtro = '/') => {
1833+ // `lista`: abierto escribiendo (el foco sigue en la caja); si no, con el botón.
1834+ const abrirMenu = (filtro = '/', { lista = true } = {}) => {
1835+ comoLista = lista;
18121836 pintarMenu(filtro);
18131837 cmdMenu.hidden = false;
1814- slash.setAttribute('aria-expanded', 'true');
1838+ slash.setAttribute('aria-expanded', lista ? 'false' : 'true');
1839+ caja.setAttribute('aria-expanded', lista ? 'true' : 'false');
18151840 };
18161841 const cerrarMenu = ({ foco = null } = {}) => {
18171842 if (cmdMenu.hidden) return;
18181843 cmdMenu.hidden = true;
18191844 slash.setAttribute('aria-expanded', 'false');
1845+ caja.setAttribute('aria-expanded', 'false');
18201846 caja.removeAttribute('aria-activedescendant');
18211847 activo = -1;
18221848 foco?.focus();
@@ -1829,7 +1855,7 @@
18291855 };
18301856 slash.addEventListener('click', () => {
18311857 if (!cmdMenu.hidden) { cerrarMenu({ foco: slash }); return; }
1832- abrirMenu('/');
1858+ abrirMenu('/', { lista: false });
18331859 filas()[0]?.focus();
18341860 });
18351861 // Dentro del menú (abierto con el botón): flechas, Inicio/Fin, Escape.