Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: preserve native keyboard control behavior

Adam Eivye4937a260d95
diff --git a/client/src/components/Drawer.browser.test.js b/client/src/components/Drawer.browser.test.js
index 55c1651594..0549094946 100644
--- a/client/src/components/Drawer.browser.test.js
+++ b/client/src/components/Drawer.browser.test.js
@@ -16,7 +16,7 @@ const chrome = [process.env.CHROME_PATH, chromium.executablePath(),
// Native :disabled includes inherited fieldset state and the first-legend
// exception. Happy DOM does not model it, so exercise actual browser tab order.
-describe.skipIf(!chrome && !auditCdp)('Drawer native disabled-state focus boundaries', () => {
+describe.skipIf(!chrome && !auditCdp)('modal native keyboard boundaries', () => {
let fixture;
let browser;
let page;
@@ -31,7 +31,7 @@ describe.skipIf(!chrome && !auditCdp)('Drawer native disabled-state focus bounda
root: fileURLToPath(new URL('../..', import.meta.url)),
cacheDir: join(temp, 'vite-cache'),
// Pre-bundle only what this fixture renders, not the whole app's graph.
- optimizeDeps: { entries: ['src/components/Drawer.jsx'], include: ['react', 'react-dom/client'] },
+ optimizeDeps: { entries: ['src/components/Drawer.jsx', 'src/components/RapidReader.jsx'], include: ['react', 'react-dom/client'] },
plugins: [react(), {
name: 'drawer-focus-fixture',
resolveId(id) { if (id === '/drawer-fixture.jsx') return '\0drawer-fixture.jsx'; },
@@ -41,15 +41,23 @@ describe.skipIf(!chrome && !auditCdp)('Drawer native disabled-state focus bounda
import React, { useState } from 'react';
import { createRoot } from 'react-dom/client';
import Drawer from '/src/components/Drawer.jsx';
+ import { RapidReaderModal } from '/src/components/RapidReader.jsx';
const h = React.createElement;
function Editor() {
const [open, setOpen] = useState(false);
const [saving, setSaving] = useState(true);
+ const [readerOpen, setReaderOpen] = useState(false);
+ const disclosures = new URLSearchParams(location.search).has('disclosures');
return h(React.Fragment, null,
h('button', { id: 'opener', onClick: () => setOpen(true) }, 'Open editor'),
h('button', { id: 'outside' }, 'Outside'),
+ h('button', { id: 'reader-opener', onClick: () => setReaderOpen(true) }, 'Open reader'),
+ h(RapidReaderModal, { open: readerOpen, text: 'Synthetic accessible reading passage.',
+ autoPlay: false, onClose: () => setReaderOpen(false) }),
h(Drawer, { open, title: 'Edit draft', onClose: () => setOpen(false) },
- h('fieldset', { disabled: saving },
+ disclosures ? h('details', null,
+ h('summary', null, 'Advanced'),
+ h('button', { id: 'detail-action' }, 'Detail action')) : h('fieldset', { disabled: saving },
h('legend', null, 'Draft ', h('button', { id: 'cancel', onClick: () => setSaving(false) }, 'Cancel save')),
h('input', { 'aria-label': 'Title' }),
h('button', { id: 'save', tabIndex: 0 }, 'Save draft'))));
@@ -78,6 +86,8 @@ describe.skipIf(!chrome && !auditCdp)('Drawer native disabled-state focus bounda
}
}
if (!page) throw new Error('Dedicated PortOS audit target is missing');
+ const session = await page.context().newCDPSession(page);
+ await session.send('Emulation.setFocusEmulationEnabled', { enabled: true });
} else {
page = await browser.newPage();
}
@@ -121,4 +131,45 @@ describe.skipIf(!chrome && !auditCdp)('Drawer native disabled-state focus bounda
await page.keyboard.press('Escape');
expect(await opener.evaluate(el => el === document.activeElement)).toBe(true);
}, 30000);
+
+ it('includes native summaries and excludes content of closed disclosures from wrap boundaries', async () => {
+ await page.goto(`${origin}drawer-test?disclosures`);
+ const opener = page.getByRole('button', { name: 'Open editor' });
+ await opener.focus();
+ await page.keyboard.press('Enter');
+ const close = page.getByRole('button', { name: 'Close settings' });
+ const summary = page.locator('summary');
+ const action = page.getByRole('button', { name: 'Detail action' });
+ await close.waitFor();
+ await page.keyboard.press('Shift+Tab');
+ expect(await summary.evaluate(el => el === document.activeElement)).toBe(true);
+ await page.keyboard.press('Tab');
+ expect(await close.evaluate(el => el === document.activeElement)).toBe(true);
+ await page.keyboard.press('Tab');
+ expect(await summary.evaluate(el => el === document.activeElement)).toBe(true);
+ await page.keyboard.press('Enter');
+ await page.keyboard.press('Tab');
+ expect(await action.evaluate(el => el === document.activeElement)).toBe(true);
+ await page.keyboard.press('Tab');
+ expect(await close.evaluate(el => el === document.activeElement)).toBe(true);
+ await page.keyboard.press('Escape');
+ expect(await opener.evaluate(el => el === document.activeElement)).toBe(true);
+ }, 30000);
+
+ it('reaches the Rapid Reader transcript and opens it with Space without starting playback', async () => {
+ await page.goto(`${origin}drawer-test`);
+ const opener = page.getByRole('button', { name: 'Open reader' });
+ await opener.focus();
+ await page.keyboard.press('Enter');
+ await page.getByRole('button', { name: 'Show two words at a time' }).focus();
+ await page.keyboard.press('Tab');
+ const summary = page.locator('summary');
+ expect(await summary.evaluate(el => el === document.activeElement)).toBe(true);
+ await page.keyboard.press('Space');
+ expect(await page.locator('details').evaluate(el => el.open)).toBe(true);
+ expect(await page.getByText('Synthetic accessible reading passage.', { exact: true }).isVisible()).toBe(true);
+ expect(await page.getByRole('button', { name: 'Play', exact: true }).count()).toBe(1);
+ await page.keyboard.press('Escape');
+ expect(await opener.evaluate(el => el === document.activeElement)).toBe(true);
+ }, 30000);
});
diff --git a/client/src/components/EntityCombobox.jsx b/client/src/components/EntityCombobox.jsx
index 3efc069c91..eba84c589c 100644
--- a/client/src/components/EntityCombobox.jsx
+++ b/client/src/components/EntityCombobox.jsx
@@ -130,8 +130,13 @@ export default function EntityCombobox({
if (u) { onPick(u); setOpen(false); }
e.preventDefault();
} else if (showCreateOption) {
- onCreate();
- setOpen(false);
+ // The virtually focused option is a disabled button while busy.
+ // Keep Enter consistent with pointer activation and consume it so it
+ // cannot fall through to a surrounding form's submit action.
+ if (!busy) {
+ onCreate();
+ setOpen(false);
+ }
e.preventDefault();
}
}
diff --git a/client/src/components/EntityCombobox.test.jsx b/client/src/components/EntityCombobox.test.jsx
index db64caf551..8efed3e37b 100644
--- a/client/src/components/EntityCombobox.test.jsx
+++ b/client/src/components/EntityCombobox.test.jsx
@@ -12,6 +12,33 @@ const items = [
];
describe('EntityCombobox', () => {
+ it('keeps keyboard creation disabled while busy without submitting the surrounding form', async () => {
+ const user = userEvent.setup();
+ const onCreate = vi.fn();
+ const onSubmit = vi.fn(event => event.preventDefault());
+ const picker = busy => (
+ <form onSubmit={onSubmit}>
+ <EntityCombobox items={[]} value="Synthetic world" onChange={() => {}}
+ onPick={() => {}} onCreate={onCreate} busy={busy} inputId="busy-picker" />
+ <button type="submit">Save</button>
+ </form>
+ );
+ const { rerender } = render(picker(true));
+ const input = screen.getByRole('combobox');
+ await user.click(input);
+ expect(screen.getByRole('option')).toBeDisabled();
+ await user.keyboard('{Enter}');
+ expect(onCreate).not.toHaveBeenCalled();
+ expect(onSubmit).not.toHaveBeenCalled();
+ expect(input).toHaveFocus();
+ expect(input).toHaveAttribute('aria-expanded', 'true');
+ rerender(picker(false));
+ await user.keyboard('{Enter}');
+ expect(onCreate).toHaveBeenCalledTimes(1);
+ expect(onSubmit).not.toHaveBeenCalled();
+ expect(input).toHaveAttribute('aria-expanded', 'false');
+ });
+
it('keeps keyboard focus and Enter aligned through navigation, filtering and reopening', async () => {
const user = userEvent.setup();
const onPick = vi.fn();
diff --git a/client/src/components/ui/OverflowMenu.browser.test.js b/client/src/components/ui/OverflowMenu.browser.test.js
index ebe8562361..0397688435 100644
--- a/client/src/components/ui/OverflowMenu.browser.test.js
+++ b/client/src/components/ui/OverflowMenu.browser.test.js
@@ -15,18 +15,21 @@ const { chromium } = require(require.resolve('playwright-core', { paths: [
fileURLToPath(new URL('../../..', import.meta.url)),
fileURLToPath(new URL('../../../../server', import.meta.url)),
] }));
+const auditCdp = process.env.PORTOS_AUDIT_CDP;
const chrome = [process.env.CHROME_PATH, chromium.executablePath(),
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
'/usr/bin/google-chrome', '/usr/bin/chromium', '/usr/bin/chromium-browser',
].find(path => path && existsSync(path));
-describe.skipIf(!chrome)('overflow menu keyboard focus', () => {
+describe.skipIf(!chrome && !auditCdp)('overflow menu keyboard focus', () => {
let browser;
let fixture;
let origin;
+ let auditPage;
beforeAll(async () => {
// Each startup phase is bounded and cleaned up inside the hook (#10543).
- fixture = await startBrowserFixture({ name: 'overflow-chrome', createServer, chromium,
+ fixture = await startBrowserFixture({ name: 'overflow-chrome', createServer,
+ chromium: auditCdp ? { launch: () => chromium.connectOverCDP(auditCdp) } : chromium,
launchOptions: { executablePath: chrome, args: ['--mute-audio'] }, viteConfig: temp => ({
configFile: false,
// Concurrent fixtures and linked worktrees must not replace each other's
@@ -48,6 +51,8 @@ describe.skipIf(!chrome)('overflow menu keyboard focus', () => {
createRoot(document.getElementById('root')).render(
React.createElement(React.Fragment, null,
React.createElement('button', { id: 'before' }, 'Before'),
+ React.createElement('div', { style: { display: 'none' } },
+ React.createElement('button', null, 'Hidden desktop action')),
React.createElement(OverflowMenu, {
label: 'More actions',
items: [
@@ -56,6 +61,11 @@ describe.skipIf(!chrome)('overflow menu keyboard focus', () => {
{ id: 'delete', label: 'Delete' },
],
}),
+ React.createElement('button', { tabIndex: -1 }, 'Programmatic action'),
+ React.createElement('fieldset', { disabled: true },
+ React.createElement('button', null, 'Disabled by fieldset')),
+ React.createElement('div', { inert: true },
+ React.createElement('button', null, 'Inert action')),
React.createElement('button', { id: 'after' }, 'After'))
);
`;
@@ -71,11 +81,28 @@ describe.skipIf(!chrome)('overflow menu keyboard focus', () => {
server: { host: '127.0.0.1', port: 0 },
}) });
({ browser, origin } = fixture);
+ if (auditCdp) {
+ for (const candidate of browser.contexts().flatMap(context => context.pages())) {
+ if (await candidate.evaluate(() => window.name === 'portos-ui-quality-audit')) {
+ auditPage = candidate;
+ break;
+ }
+ }
+ if (!auditPage) throw new Error('Dedicated PortOS audit target is missing');
+ const session = await auditPage.context().newCDPSession(auditPage);
+ await session.send('Emulation.setFocusEmulationEnabled', { enabled: true });
+ }
}, BROWSER_FIXTURE_STARTUP_MS);
- afterAll(() => fixture?.close());
+ afterAll(async () => {
+ if (auditPage) await auditPage.evaluate(() => {
+ window.name = 'portos-ui-quality-audit';
+ document.title = 'PortOS UI Audit';
+ });
+ await fixture?.close();
+ });
it.each(['ArrowDown', 'Enter'])('enters after %s, keeps focus on reflow, and exits relative to the trigger', async (key) => {
- const page = await browser.newPage();
+ const page = auditPage || await browser.newPage();
try {
await page.goto(`${origin}overflow-test`);
const trigger = page.getByRole('button', { name: 'More actions' });
@@ -114,7 +141,7 @@ describe.skipIf(!chrome)('overflow menu keyboard focus', () => {
expect(await page.getByRole('menu').count()).toBe(0);
await focused(page.locator('#before'));
} finally {
- await page.close();
+ if (!auditPage) await page.close();
}
}, 60000);
});
diff --git a/client/src/components/ui/OverflowMenu.jsx b/client/src/components/ui/OverflowMenu.jsx
index 5ddeaab71f..ec7c3579d9 100644
--- a/client/src/components/ui/OverflowMenu.jsx
+++ b/client/src/components/ui/OverflowMenu.jsx
@@ -29,7 +29,6 @@ const TONES = {
};
const ITEM_SELECTOR = '[role="menuitem"]:not(:disabled)';
-const TABBABLE_SELECTOR = 'a[href],button:not(:disabled),input:not(:disabled),select:not(:disabled),textarea:not(:disabled),[tabindex]:not([tabindex="-1"])';
const MENU_WIDTH = 176;
export default function OverflowMenu({ label, items = [], className = '', triggerRef: externalTriggerRef }) {
@@ -73,18 +72,6 @@ export default function OverflowMenu({ label, items = [], className = '', trigge
next?.focus();
};
- // Move focus to the element that would follow (or precede) the trigger in the
- // document's tab order, ignoring the menu's own items. Falls back to the
- // trigger when it's at the end of the sequence.
- const focusPastTrigger = (backwards) => {
- const trigger = triggerRef.current;
- const nodes = Array.from(document.querySelectorAll(TABBABLE_SELECTOR))
- .filter(el => !popoverRef.current?.contains(el));
- const idx = nodes.indexOf(trigger);
- const next = idx === -1 ? null : nodes[idx + (backwards ? -1 : 1)];
- (next || trigger)?.focus();
- };
-
const handleMenuKeyDown = (e) => {
if (e.key === 'ArrowDown') {
e.preventDefault();
@@ -93,13 +80,10 @@ export default function OverflowMenu({ label, items = [], className = '', trigge
e.preventDefault();
moveFocus(-1);
} else if (e.key === 'Tab') {
- // Tab leaves the menu. The default move can't be relied on — the focused
- // item unmounts in the same interaction, which strands focus on <body> —
- // so drive it explicitly: continue the tab sequence from the trigger, as
- // if the menu had never been open.
- e.preventDefault();
- focusPastTrigger(e.shiftKey);
- setOpen(false);
+ // Restore the trigger before unmounting the focused item, then let the
+ // browser perform this Tab's default action. Native tab order accounts
+ // for hidden/inert controls, negative tabindex and disclosure state.
+ close(true);
}
};
diff --git a/client/src/hooks/useFocusTrap.js b/client/src/hooks/useFocusTrap.js
index 3aa1fae7d1..cd25e0e387 100644
--- a/client/src/hooks/useFocusTrap.js
+++ b/client/src/hooks/useFocusTrap.js
@@ -30,6 +30,7 @@ const FOCUSABLE_SELECTOR = [
'textarea:not([disabled]):not([tabindex="-1"])',
'input:not([disabled]):not([type="hidden"]):not([tabindex="-1"])',
'select:not([disabled]):not([tabindex="-1"])',
+ 'details > summary:first-of-type:not([tabindex="-1"])',
'[tabindex]:not([tabindex="-1"])',
].join(',');
@@ -47,6 +48,12 @@ function isTabbable(el, container) {
for (let node = el; node && node !== container; node = node.parentElement) {
if (node.nodeType !== 1) return false;
if (node.hasAttribute('hidden')) return false;
+ // Closed disclosures keep their descendants in the DOM and computed
+ // styles, but only their summary participates in native keyboard focus.
+ if (node.tagName === 'DETAILS' && !node.open) {
+ const summary = Array.from(node.children).find(child => child.tagName === 'SUMMARY');
+ if (!summary?.contains(el)) return false;
+ }
const style = typeof getComputedStyle === 'function' ? getComputedStyle(node) : null;
if (style && (style.display === 'none' || style.visibility === 'hidden' || style.visibility === 'collapse')) {
return false;
diff --git a/client/src/lib/a11yKeyboard.js b/client/src/lib/a11yKeyboard.js
index 9698fe748a..3c9079a31a 100644
--- a/client/src/lib/a11yKeyboard.js
+++ b/client/src/lib/a11yKeyboard.js
@@ -80,8 +80,8 @@ export function clickableProps(handler, { role = 'button', disabled = false } =
}
/**
- * True when a keystroke is a Space press on a focused button-like element,
- * where the browser will natively activate that button.
+ * True when a keystroke is a Space press on a focused button-like element or
+ * native disclosure summary, where the browser will activate the control.
*
* App-global single-key handlers bound to Space (the voice widget's
* push-to-talk hotkey, page-level shortcut maps) must stand down for these:
@@ -98,7 +98,7 @@ export function isButtonActivation(event) {
if (!isSpace) return false;
const target = event.target;
if (typeof target?.closest !== 'function') return false;
- return target.closest('button, [role="button"]') != null;
+ return target.closest('button, [role="button"], details > summary:first-of-type') != null;
}
/**