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: manage Shell photo composer focus (#9843)

Adam Eivyea455f757841
diff --git a/client/src/components/shell/ShellImageDrop.jsx b/client/src/components/shell/ShellImageDrop.jsx
index c5c3b94691..a57a252642 100644
--- a/client/src/components/shell/ShellImageDrop.jsx
+++ b/client/src/components/shell/ShellImageDrop.jsx
@@ -6,6 +6,7 @@ import FormField from '../ui/FormField';
import usePopoverPosition, { VIEWPORT_PADDING } from '../../hooks/usePopoverPosition.js';
import useEscapeKey from '../../hooks/useEscapeKey';
import useClickOutside from '../../hooks/useClickOutside.js';
+import useFocusTrap from '../../hooks/useFocusTrap.js';
import { IMAGE_ACCEPT, validateImageFile } from '../../utils/fileUpload';
import { formatBytes } from '../../utils/formatters';
import toast from '../ui/Toast';
@@ -122,7 +123,10 @@ export default function ShellImageDrop({ onSend, placement = 'below' }) {
if (ok && draftGenRef.current === gen) close();
}, [picked, message, onSend, sending, close]);
- useEscapeKey(open, close);
+ useEscapeKey(open, () => { close(); triggerRef.current?.focus(); });
+ // The panel is portaled to <body>, so Tab from the trigger would otherwise
+ // skip its controls. Wait for measurement so the hidden panel can take focus.
+ useFocusTrap(open && !!style, popoverRef);
// This panel is portaled to <body>, so it isn't a descendant of the trigger
// container — a single-ref containment check would read every click on the
@@ -142,6 +146,7 @@ export default function ShellImageDrop({ onSend, placement = 'below' }) {
}`}
title="Send a photo to this session"
aria-label="Send a photo to this session"
+ aria-haspopup="dialog"
aria-expanded={open}
>
<ImageUp size={14} />
@@ -151,6 +156,9 @@ export default function ShellImageDrop({ onSend, placement = 'below' }) {
{open && createPortal(
<div
ref={popoverRef}
+ role="dialog"
+ aria-modal="true"
+ aria-label="Send photo to session"
onPaste={handlePaste}
onDrop={handleDrop}
onDragOver={(e) => e.preventDefault()}
diff --git a/client/src/components/shell/ShellImageDrop.test.jsx b/client/src/components/shell/ShellImageDrop.test.jsx
index a7d0cd16e9..be9ad6971e 100644
--- a/client/src/components/shell/ShellImageDrop.test.jsx
+++ b/client/src/components/shell/ShellImageDrop.test.jsx
@@ -1,5 +1,6 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
import ShellImageDrop from './ShellImageDrop';
import { findEnabledByRole } from '../../test/enabledBarrier.js';
@@ -35,6 +36,28 @@ describe('ShellImageDrop', () => {
expect(screen.getByLabelText(/choose a photo/i)).toBeTruthy();
});
+ it('announces a dialog, moves keyboard focus into it, and restores focus on Escape', async () => {
+ const user = userEvent.setup();
+ render(<ShellImageDrop onSend={vi.fn()} />);
+ const trigger = screen.getByRole('button', { name: /send a photo/i });
+
+ expect(trigger).toHaveAttribute('aria-haspopup', 'dialog');
+ expect(trigger).toHaveAttribute('aria-expanded', 'false');
+ trigger.focus();
+ await user.keyboard('{Enter}');
+
+ const dialog = screen.getByRole('dialog', { name: 'Send photo to session' });
+ const picker = screen.getByLabelText('Choose a photo to send to this session');
+ await waitFor(() => expect(document.activeElement).toBe(picker));
+ expect(dialog).toHaveAttribute('aria-modal', 'true');
+ expect(trigger).toHaveAttribute('aria-expanded', 'true');
+
+ await user.keyboard('{Escape}');
+ await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
+ expect(trigger).toHaveAttribute('aria-expanded', 'false');
+ expect(document.activeElement).toBe(trigger);
+ });
+
it('sends the picked file with the typed message', async () => {
const onSend = vi.fn().mockResolvedValue(true);
render(<ShellImageDrop onSend={onSend} />);