Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
fix(home): keep the keyboard on a control that is busy, not on the document
nirholase900f98ddab9
diff --git a/public/home-scene.css b/public/home-scene.cssindex cd5652b84..c754d4871 100644--- a/public/home-scene.css+++ b/public/home-scene.css@@ -125,10 +125,19 @@cursor: pointer;transition: background var(--duration-fast) var(--ease-standard), border-color var(--duration-fast) var(--ease-standard), transform var(--duration-fast) var(--ease-standard);}-.hs-btn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--stroke-strong); }-.hs-btn:active:not(:disabled) { transform: translateY(1px); }+.hs-btn:hover:not(:disabled):not([aria-disabled='true']) { background: var(--surface-3); border-color: var(--stroke-strong); }+.hs-btn:active:not(:disabled):not([aria-disabled='true']) { transform: translateY(1px); }.hs-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }-.hs-btn:disabled { opacity: 0.5; cursor: not-allowed; }+/*+ * `aria-disabled` reads and looks exactly like `disabled`, and behaves like it+ * on click, but stays in the tab order and can still hold focus. A control that+ * is busy for the length of a network round trip must not vanish from under a+ * keyboard user's fingers, which the `disabled` property does: the browser+ * blurs it, the keyboard lands on the document, and the person has to tab the+ * whole house again to get back to the lamp they just pressed.+ */+.hs-btn:disabled,+.hs-btn[aria-disabled='true'] { opacity: 0.5; cursor: not-allowed; }.hs-btn[aria-pressed='true'] { background: var(--surface-3); border-color: var(--stroke-strong); }.hs-btn--primary { background: var(--ink); color: var(--bg-0); border-color: transparent; font-weight: var(--weight-semibold); }.hs-btn--primary:hover:not(:disabled) { background: #fff; }@@ -521,9 +530,10 @@cursor: pointer;transition: background var(--duration-fast) var(--ease-standard), border-color var(--duration-fast) var(--ease-standard);}-.hs-item-act:hover:not(:disabled) { background: var(--surface-3); border-color: var(--stroke-strong); }+.hs-item-act:hover:not(:disabled):not([aria-disabled='true']) { background: var(--surface-3); border-color: var(--stroke-strong); }.hs-item-act:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }-.hs-item-act:disabled { opacity: 0.5; cursor: progress; }+.hs-item-act:disabled,+.hs-item-act[aria-disabled='true'] { opacity: 0.5; cursor: progress; }.hs-card-readouts {display: grid;diff --git a/src/home/scene-fallback.js b/src/home/scene-fallback.jsindex 09155d946..13a92bdd3 100644--- a/src/home/scene-fallback.js+++ b/src/home/scene-fallback.js@@ -228,14 +228,21 @@ export function createHomeFallback(container, options = {}) {// is answered and the node it was opened from has gone.button.dataset.actFor = object.entityId;button.dataset.actService = `${domain}.${service}`;- button.textContent = busy.has(object.entityId) ? t('home_scene.working', 'Working') : label;- button.disabled = busy.has(object.entityId);+ const working = busy.has(object.entityId);+ button.textContent = working ? t('home_scene.working', 'Working') : label;+ // aria-disabled, not the disabled property. A disabled button cannot+ // hold focus, so the browser blurs it the instant the request starts+ // and a keyboard user is dropped at the top of the document for the+ // length of a round trip. This reads as disabled to a screen reader,+ // looks disabled, refuses the press below, and keeps the keyboard.+ if (working) button.setAttribute('aria-disabled', 'true');// The device's name and its room's name are the user's own words, so// they are interpolated rather than concatenated into a translatable// sentence: a catalog string with "Front Door" baked into it would be// machine-translated on the next run.button.setAttribute('aria-label', t('home_scene.act_aria', '{{action}} {{name}} in {{room}}', { action: label, name: object.name, room: room.name }));button.addEventListener('click', () => {+ if (button.getAttribute('aria-disabled') === 'true') return;options.onAct?.({ entityId: object.entityId, domain, service, name: object.name, roomId: room.id });});row.appendChild(button);diff --git a/src/home/scene.js b/src/home/scene.jsindex 6328cddd9..eb74792ce 100644--- a/src/home/scene.js+++ b/src/home/scene.js@@ -850,11 +850,17 @@ function renderInspector() {// dismissConfirm: the node itself does not.button.dataset.actFor = object.entityId;button.dataset.actService = `${action.domain}.${action.service}`;- button.textContent = state.busy.has(object.entityId) ? t('home_scene.working', 'Working') : action.label;- button.disabled = state.busy.has(object.entityId);- button.addEventListener('click', () =>- act({ entityId: object.entityId, domain: action.domain, service: action.service, name: object.name, roomId: roomOf(object.entityId)?.id }),- );+ const working = state.busy.has(object.entityId);+ button.textContent = working ? t('home_scene.working', 'Working') : action.label;+ // aria-disabled rather than the disabled property, for the same reason+ // the flat house uses it: a disabled control is blurred by the browser,+ // and losing the keyboard for the length of a round trip is not an+ // acceptable cost of pressing a button.+ if (working) button.setAttribute('aria-disabled', 'true');+ button.addEventListener('click', () => {+ if (button.getAttribute('aria-disabled') === 'true') return;+ act({ entityId: object.entityId, domain: action.domain, service: action.service, name: object.name, roomId: roomOf(object.entityId)?.id });+ });row.appendChild(button);}el.inspector.appendChild(row);@@ -916,6 +922,12 @@ function actionsFor(object) {async function act(request, { confirmed = false, remember = false } = {}) {const room = request.roomId ? state.model?.rooms.find((r) => r.id === request.roomId) : roomOf(request.entityId);+ // Where the keyboard is RIGHT NOW, before anything below moves it. Read here+ // rather than in the refusal branch because the lines that follow mark the+ // device busy and re-render it, and the control that started this action is+ // replaced by its working state in the process. By the time the gate answers+ // there is nothing useful left to read off document.activeElement.+ const returnTo = document.activeElement instanceof HTMLElement ? document.activeElement : null;state.busy.add(request.entityId);state.renderer?.setBusy?.([...state.busy]);state.renderer?.setActing?.({ roomId: room?.id || null, entityId: request.entityId });@@ -939,21 +951,22 @@ async function act(request, { confirmed = false, remember = false } = {}) {// The gate fired. Ask, next to the thing it would move.state.pending = { request, message: err.message, risk: err.pending?.risk || 'physical', entityId: err.pending?.entityId || request.entityId };pushLog({ text: t('home_scene.log_entry', '{{action}} {{name}}', { action: serviceLabel(request.service), name: request.name }), outcome: 'refused' });- // Where the keyboard was when the gate fired. Cancelling or pressing- // Escape puts it back there, so a keyboard user is returned to the- // control they pressed instead of to the top of the document.+ // Where the keyboard was when this action started. Cancelling or+ // pressing Escape puts it back there, so a keyboard user is returned+ // to the control they pressed instead of to the top of the document.//// Both the node AND what it is, because the node does not survive.- // This same call's `finally` runs setBusy, which rebuilds the flat- // house's whole list, so by the time anyone answers the question the- // button they pressed has been replaced by an identical one and the- // original is detached. Holding only the reference sent the keyboard- // to the top of the document on every Escape: caught by the- // no-mouse journey in tests/e2e/home-a11y.spec.js.- state.confirmReturn = document.activeElement instanceof HTMLElement ? document.activeElement : null;- state.confirmReturnKey = state.confirmReturn?.dataset?.actFor- ? { entityId: state.confirmReturn.dataset.actFor, service: state.confirmReturn.dataset.actService || '' }- : null;+ // The busy render above rebuilds the flat house's whole list, so the+ // button they pressed has already been replaced by an identical one+ // and the original is detached. Holding only the reference sent the+ // keyboard to the top of the document on every Escape: caught by the+ // no-mouse journey in tests/e2e/home-a11y.spec.js. The request itself+ // is the last resort, and it always names the right control.+ state.confirmReturn = returnTo;+ state.confirmReturnKey = {+ entityId: returnTo?.dataset?.actFor || request.entityId,+ service: returnTo?.dataset?.actService || `${request.domain}.${request.service}`,+ };renderConfirm();} else {pushLog({ text: t('home_scene.log_entry', '{{action}} {{name}}', { action: serviceLabel(request.service), name: request.name }), outcome: 'failed' });