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: drive Tab out of the overflow menu explicitly so focus can't land on body (#3286)

[._.]/ Adam Eivy779b25a84875
diff --git a/client/src/components/ui/OverflowMenu.jsx b/client/src/components/ui/OverflowMenu.jsx
index 39d375ab72..76f877e1ef 100644
--- a/client/src/components/ui/OverflowMenu.jsx
+++ b/client/src/components/ui/OverflowMenu.jsx
@@ -17,6 +17,7 @@ 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"])';
export default function OverflowMenu({ label, items = [], className = '', triggerRef: externalTriggerRef }) {
const [open, setOpen] = useState(false);
@@ -51,6 +52,18 @@ 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 => !menuRef.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();
@@ -59,6 +72,12 @@ 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);
}
};
diff --git a/client/src/components/ui/OverflowMenu.test.jsx b/client/src/components/ui/OverflowMenu.test.jsx
index 67ec3f9ccf..62147750e5 100644
--- a/client/src/components/ui/OverflowMenu.test.jsx
+++ b/client/src/components/ui/OverflowMenu.test.jsx
@@ -94,6 +94,39 @@ describe('OverflowMenu', () => {
expect(document.activeElement).toBe(screen.getByRole('button', { name: 'More actions' }));
});
+ it('closes on Tab and advances from the trigger rather than dropping focus on the body', async () => {
+ const user = userEvent.setup();
+ render(
+ <div>
+ <OverflowMenu label="More actions" items={items()} />
+ <button type="button">after</button>
+ </div>
+ );
+
+ await user.click(screen.getByRole('button', { name: 'More actions' }));
+ expect(document.activeElement).toBe(screen.getByRole('menuitem', { name: 'Archive' }));
+
+ await user.tab();
+ expect(screen.queryByRole('menu')).toBeNull();
+ expect(document.activeElement).toBe(screen.getByRole('button', { name: 'after' }));
+ });
+
+ it('closes on Shift+Tab and steps back to the control before the trigger', async () => {
+ const user = userEvent.setup();
+ render(
+ <div>
+ <button type="button">before</button>
+ <OverflowMenu label="More actions" items={items()} />
+ </div>
+ );
+
+ await user.click(screen.getByRole('button', { name: 'More actions' }));
+ await user.tab({ shift: true });
+
+ expect(screen.queryByRole('menu')).toBeNull();
+ expect(document.activeElement).toBe(screen.getByRole('button', { name: 'before' }));
+ });
+
it('closes on an outside click', async () => {
const user = userEvent.setup();
render(