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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix(a11y): add aria-expanded, aria-haspopup, and Escape handler to ShareToButton and SyncToPeerButton (#7959)
[._.]/ Adam Eivy0894cb56a1bb
diff --git a/client/src/components/sharing/ShareToButton.jsx b/client/src/components/sharing/ShareToButton.jsxindex 7ad4217670..bc27c8c539 100644--- a/client/src/components/sharing/ShareToButton.jsx+++ b/client/src/components/sharing/ShareToButton.jsx@@ -100,6 +100,20 @@ export default function ShareToButton({ kind, ids, items, label = 'Share', compaif (open) refresh();}, [open]);+ // Close on Escape and return focus to the trigger so keyboard users don't+ // have to Tab back through the popover content.+ useEffect(() => {+ if (!open) return undefined;+ const onKey = (e) => {+ if (e.key === 'Escape') {+ setOpen(false);+ triggerRef.current?.focus();+ }+ };+ window.addEventListener('keydown', onKey);+ return () => window.removeEventListener('keydown', onKey);+ }, [open]);+// Both refs: the menu lives outside the trigger's subtree once portaled, so a// trigger-only containment check would read clicks on the menu as outside.useClickOutside([wrapperRef, popoverRef], open, () => setOpen(false));@@ -166,6 +180,8 @@ export default function ShareToButton({ kind, ids, items, label = 'Share', compatype="button"onClick={() => setOpen((v) => !v)}disabled={nothingToShare}+ aria-expanded={open}+ aria-haspopup="true"className={`inline-flex items-center gap-1.5 px-2.5 py-1.5 rounded text-xs border border-port-border hover:border-port-accent/40 text-gray-300 hover:text-white disabled:opacity-40 disabled:cursor-not-allowed transition-colors ${compact ? 'p-1.5' : ''}`}title={nothingToShare ? 'Nothing selected to share' : 'Share to a bucket'}>diff --git a/client/src/components/sharing/ShareToButton.test.jsx b/client/src/components/sharing/ShareToButton.test.jsxnew file mode 100644index 0000000000..6d20344cb5--- /dev/null+++ b/client/src/components/sharing/ShareToButton.test.jsx@@ -0,0 +1,98 @@+import { describe, it, expect, vi, beforeEach } from 'vitest';+import { render, screen, waitFor } from '@testing-library/react';+import userEvent from '@testing-library/user-event';++vi.mock('../../services/api', () => ({+ listShareBuckets: vi.fn(),+ exportToShareBucket: vi.fn(),+ listShareSubscriptions: vi.fn(),+ subscribeToShareBucket: vi.fn(),+ unsubscribeFromShareBucket: vi.fn(),+}));+vi.mock('../ui/Toast', () => ({+ default: { success: vi.fn(), error: vi.fn() },+}));++import * as api from '../../services/api';+import ShareToButton from './ShareToButton';++const BUCKET_A = { id: 'bkt-a', name: 'Bucket A', mode: 'auto-merge', path: '/exports/a' };+const BUCKET_B = { id: 'bkt-b', name: 'Bucket B', mode: 'inbox', path: '/exports/b' };++beforeEach(() => {+ vi.clearAllMocks();+ api.listShareBuckets.mockResolvedValue({ buckets: [BUCKET_A, BUCKET_B] });+ api.listShareSubscriptions.mockResolvedValue({ subscriptions: [] });+});++describe('ShareToButton', () => {+ it('is disabled when nothing is selected to share (no ids)', () => {+ render(<ShareToButton kind="series" />);+ expect(screen.getByRole('button', { name: /Share/i })).toBeDisabled();+ });++ it('opens the bucket list when clicked', async () => {+ const user = userEvent.setup();+ render(<ShareToButton kind="series" ids={['s1']} />);+ await user.click(screen.getByRole('button', { name: /Share/i }));+ await waitFor(() => expect(api.listShareBuckets).toHaveBeenCalled());+ expect(await screen.findByText('Bucket A')).toBeTruthy();+ expect(screen.getByText('Bucket B')).toBeTruthy();+ });++ it('exposes aria-expanded=false when closed and aria-expanded=true when open', async () => {+ const user = userEvent.setup();+ render(<ShareToButton kind="series" ids={['s1']} />);+ const trigger = screen.getByRole('button', { name: /Share/i });+ expect(trigger).toHaveAttribute('aria-expanded', 'false');+ expect(trigger).toHaveAttribute('aria-haspopup', 'true');+ await user.click(trigger);+ expect(trigger).toHaveAttribute('aria-expanded', 'true');+ await user.click(trigger);+ expect(trigger).toHaveAttribute('aria-expanded', 'false');+ });++ it('closes the popover and returns focus to the trigger when Escape is pressed', async () => {+ const user = userEvent.setup();+ render(<ShareToButton kind="series" ids={['s1']} />);+ const trigger = screen.getByRole('button', { name: /Share/i });+ await user.click(trigger);+ expect(trigger).toHaveAttribute('aria-expanded', 'true');+ await user.keyboard('{Escape}');+ expect(trigger).toHaveAttribute('aria-expanded', 'false');+ // Focus returns to the trigger after Escape.+ expect(document.activeElement).toBe(trigger);+ });++ it('subscribes a series record to a bucket on click', async () => {+ api.subscribeToShareBucket.mockResolvedValue({+ subscription: { id: 'sub-s1-bkt-a', bucketId: 'bkt-a' },+ });+ const user = userEvent.setup();+ render(<ShareToButton kind="series" ids={['s1']} />);+ await user.click(screen.getByRole('button', { name: /Share/i }));+ await screen.findByText('Bucket A');+ await user.click(screen.getByText('Bucket A'));+ await waitFor(() => expect(api.subscribeToShareBucket).toHaveBeenCalledWith(+ { bucketId: 'bkt-a', recordKind: 'series', recordId: 's1' },+ { silent: true },+ ));+ });++ it('shares a media item one-shot on click', async () => {+ api.exportToShareBucket.mockResolvedValue({+ exports: [{ recordCount: 3, assetCount: 1 }],+ });+ const user = userEvent.setup();+ const items = [{ kind: 'media', ref: 'm1' }];+ render(<ShareToButton kind="media" items={items} />);+ await user.click(screen.getByRole('button', { name: /Share/i }));+ await screen.findByText('Bucket A');+ await user.click(screen.getByText('Bucket A'));+ await waitFor(() => expect(api.exportToShareBucket).toHaveBeenCalledWith(+ 'bkt-a',+ { kind: 'media', items },+ { silent: true },+ ));+ });+});diff --git a/client/src/components/sharing/SyncToPeerButton.jsx b/client/src/components/sharing/SyncToPeerButton.jsxindex dce7c6c62c..70fb020ce7 100644--- a/client/src/components/sharing/SyncToPeerButton.jsx+++ b/client/src/components/sharing/SyncToPeerButton.jsx@@ -111,6 +111,20 @@ export default function SyncToPeerButton({if (open) refresh();}, [open]);+ // Close on Escape and return focus to the trigger so keyboard users don't+ // have to Tab back through the popover content.+ useEffect(() => {+ if (!open) return undefined;+ const onKey = (e) => {+ if (e.key === 'Escape') {+ setOpen(false);+ triggerRef.current?.focus();+ }+ };+ window.addEventListener('keydown', onKey);+ return () => window.removeEventListener('keydown', onKey);+ }, [open]);+// Both refs: the menu lives in a portal outside wrapperRef, so a trigger-only// containment check would read clicks on the menu as outside.useClickOutside([wrapperRef, popoverRef], open, () => setOpen(false));@@ -160,6 +174,8 @@ export default function SyncToPeerButton({type="button"onClick={() => setOpen((v) => !v)}disabled={nothingToSync}+ aria-expanded={open}+ aria-haspopup="true"className={`inline-flex items-center gap-1.5 px-2.5 py-1.5 rounded text-xs border border-port-border hover:border-port-accent/40 text-gray-300 hover:text-white disabled:opacity-40 disabled:cursor-not-allowed transition-colors ${compact ? 'p-1.5' : ''}`}title={nothingToSync ? 'Nothing to sync' : 'Sync to a peer instance'}>diff --git a/client/src/components/sharing/SyncToPeerButton.test.jsx b/client/src/components/sharing/SyncToPeerButton.test.jsxindex 32371c1d21..36ad8959ec 100644--- a/client/src/components/sharing/SyncToPeerButton.test.jsx+++ b/client/src/components/sharing/SyncToPeerButton.test.jsx@@ -174,4 +174,28 @@ describe('SyncToPeerButton', () => {expect(top).toBeGreaterThanOrEqual(8);vi.restoreAllMocks();});++ it('exposes aria-expanded=false when closed and aria-expanded=true when open', async () => {+ const user = userEvent.setup();+ render(<SyncToPeerButton recordKind="universe" recordId="u1" />);+ const trigger = screen.getByRole('button', { name: /Sync/i });+ expect(trigger).toHaveAttribute('aria-expanded', 'false');+ expect(trigger).toHaveAttribute('aria-haspopup', 'true');+ await user.click(trigger);+ expect(trigger).toHaveAttribute('aria-expanded', 'true');+ await user.click(trigger);+ expect(trigger).toHaveAttribute('aria-expanded', 'false');+ });++ it('closes the popover and returns focus to the trigger when Escape is pressed', async () => {+ const user = userEvent.setup();+ render(<SyncToPeerButton recordKind="universe" recordId="u1" />);+ const trigger = screen.getByRole('button', { name: /Sync/i });+ await user.click(trigger);+ expect(trigger).toHaveAttribute('aria-expanded', 'true');+ await user.keyboard('{Escape}');+ expect(trigger).toHaveAttribute('aria-expanded', 'false');+ // Focus returns to the trigger after Escape.+ expect(document.activeElement).toBe(trigger);+ });});