Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(mobile): open sheets without a focus ring on their first row (#9251)
Peter Chinman4aa4f78dfd10
diff --git a/.agents/rules/web/mobile.md b/.agents/rules/web/mobile.mdindex d00e186a99..612e140fe7 100644--- a/.agents/rules/web/mobile.md+++ b/.agents/rules/web/mobile.md@@ -56,6 +56,10 @@ read their code, and follow that pattern rather than inventing a new one.- Phone drawers have a handle and no X; drag, backdrop, or Escape dismiss,and focus returns to the opener. No submenus at phone width: drill inplace with a back row.+- A sheet takes focus itself when it opens, so no row opens wearing a focus+ ring; only a first tab stop that is a text field keeps it. Name another+ target with `initialFocusEl` or `onInitialFocus`, never an autofocus of your+ own.- Actions that must stay in reach while a sheet scrolls sit in its pinnedchrome between the handle and `MobileDrawer.ScrollBody`, never in a stickyband inside the scroll. A touch popover split exposes that slot asdiff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.mdindex 9633229194..a52bed5f2e 100644--- a/apps/web/AGENTS.md+++ b/apps/web/AGENTS.md@@ -73,6 +73,10 @@ stacked sheet), which must bring it back on screen. It also keeps a persistentprompt under an open sheet and its picker, above a transient notice, and thatnotice on top of the sheet:`bunx playwright test --config src/components/app/mobile/browser-test/playwright.config.ts`.+The same suite covers where a sheet puts focus as it opens: on itself, leaving+its first row unringed, unless the first tab stop is a text field, the sheet+focused something itself, or it names its own target; Tab then moves into the+rows, which do show the ring.CRM creation has backend-free desktop/phone coverage for name-only companies,personal-email contacts and explicit company selection:diff --git a/apps/web/src/components/app/mobile/MobileDrawer.tsx b/apps/web/src/components/app/mobile/MobileDrawer.tsxindex 60b209a741..f2220cdbff 100644--- a/apps/web/src/components/app/mobile/MobileDrawer.tsx+++ b/apps/web/src/components/app/mobile/MobileDrawer.tsx@@ -40,6 +40,10 @@ export function scrollToFocusedInput(e: FocusEvent, offset = 40) {}, 300);}+/** Corvu's focus trap's own selector, to read the stop it would focus. */+const FOCUSABLE_SELECTOR =+ 'a[href]:not([tabindex="-1"]), button:not([tabindex="-1"]), input:not([tabindex="-1"]), textarea:not([tabindex="-1"]), select:not([tabindex="-1"]), details:not([tabindex="-1"]), [tabindex]:not([tabindex="-1"])';+/*** Drop-in replacement for `Drawer.Content` that handles mobile keyboard* behaviour automatically:@@ -286,6 +290,34 @@ function swallowRestOfTap() {});}+/**+ * A sheet opens with focus on itself unless its first tab stop is something to+ * type into. Corvu's focus trap otherwise focuses that stop, and a browser+ * paints the focus ring for a scripted focus arriving while nothing on the+ * page is focused — which is every tap, since a tapped button is not focused+ * on iOS. That ringed the first row of every sheet of rows.+ *+ * A text field keeps the focus: a sheet that opens for a search or a name is+ * opened to type in. So does whatever the sheet focused itself while opening,+ * such as the heading Settings announces when it drills in. The content+ * element carries `tabindex="-1"`, so the trap, Escape and the sheet's own+ * announcement all still work when the sheet holds focus itself. Sheets that+ * want another control focused name it with `initialFocusEl` or their own+ * `onInitialFocus`, as the comment composer and the model picker do.+ */+function focusSheetOverItsFirstRow(event: Event) {+ const sheet = event.target as HTMLElement | null;+ if (!sheet) return;+ if (sheet.contains(document.activeElement)) {+ // Corvu would move this to the first tab stop; the sheet chose it.+ event.preventDefault();+ return;+ }+ if (isEditableInput(sheet.querySelector(FOCUSABLE_SELECTOR))) return;+ event.preventDefault();+ sheet.focus();+}+/*** Wrapper around Corvu's Drawer for mobile. Handles styling and input/virtual keyboard behaviour.*/@@ -299,6 +331,7 @@ export const MobileDrawer = Object.assign(const [local, rest] = splitProps(props, ['onOutsidePointer','onOpenChange',+ 'onInitialFocus',]);let uncontrolledOpen = props.initialOpen ?? false;let disposed = false;@@ -326,6 +359,11 @@ export const MobileDrawer = Object.assign(local.onOpenChange?.(open);if (!open && !closed()) setActiveSnapPoint(1);}}+ onInitialFocus={(event) => {+ local.onInitialFocus?.(event);+ if (event.defaultPrevented || props.initialFocusEl) return;+ focusSheetOverItsFirstRow(event);+ }}onOutsidePointer={(event) => {if (!dismissesDrawer(event)) event.preventDefault();local.onOutsidePointer?.(event);diff --git a/apps/web/src/components/app/mobile/browser-test/drawer-focus.browser.e2e.ts b/apps/web/src/components/app/mobile/browser-test/drawer-focus.browser.e2e.tsnew file mode 100644index 0000000000..45dca22dbe--- /dev/null+++ b/apps/web/src/components/app/mobile/browser-test/drawer-focus.browser.e2e.ts@@ -0,0 +1,69 @@+import { expect, type Locator, type Page, test } from '@playwright/test';++/** Corvu starts the opening slide a frame after mount, so wait for it to end. */+async function settled(sheet: Locator) {+ await expect(sheet).toBeInViewport({ ratio: 1 });+ await expect(sheet).not.toHaveAttribute('data-transitioning');+}++const ringed = (target: Locator) =>+ target.evaluate((element) => element.matches(':focus-visible'));++const focusedLabel = (page: Page) =>+ page.evaluate(+ () =>+ document.activeElement?.getAttribute('aria-label') ??+ document.activeElement?.textContent ??+ null+ );++test('a sheet of rows opens with focus on itself, with no ring on its first row', async ({+ page,+}) => {+ await page.goto('/?scenario=menu');+ const sheet = page.getByRole('dialog', { name: 'Add to message' });+ await settled(sheet);++ await expect(sheet).toBeFocused();+ expect(await focusedLabel(page)).toBe('Add to message');+ const first = sheet.getByRole('button', { name: 'Mention' });+ await expect(first).not.toBeFocused();+ expect(await ringed(first)).toBe(false);+ // The sheet holds focus, and a focused sheet shows nothing of its own.+ await expect(sheet).toHaveCSS('outline-style', 'none');+});++test('Tab moves from the sheet into its rows, which do show the ring', async ({+ page,+}) => {+ await page.goto('/?scenario=menu');+ const sheet = page.getByRole('dialog', { name: 'Add to message' });+ await settled(sheet);++ await page.keyboard.press('Tab');+ const first = sheet.getByRole('button', { name: 'Mention' });+ await expect(first).toBeFocused();+ expect(await ringed(first)).toBe(true);+});++test('a sheet opened to type in focuses the field, with no ring to show', async ({+ page,+}) => {+ await page.goto('/?scenario=typing');+ const sheet = page.getByRole('dialog', { name: 'Choose a repository' });+ await settled(sheet);++ const search = sheet.getByRole('textbox', { name: 'Search repositories' });+ await expect(search).toBeFocused();+ await expect(search).toHaveCSS('outline-style', 'none');+});++test('a sheet that names its initial focus still gets it', async ({ page }) => {+ await page.goto('/?scenario=search');+ const sheet = page.getByRole('dialog', { name: 'Choose a model' });+ await settled(sheet);++ await expect(+ sheet.getByRole('textbox', { name: 'Search models' })+ ).toBeFocused();+});diff --git a/apps/web/src/components/app/mobile/browser-test/fixture.tsx b/apps/web/src/components/app/mobile/browser-test/fixture.tsxindex 4b848a280a..5493c487dd 100644--- a/apps/web/src/components/app/mobile/browser-test/fixture.tsx+++ b/apps/web/src/components/app/mobile/browser-test/fixture.tsx@@ -1,5 +1,6 @@import '@fontsource-variable/inter';import '../../../../index.css';+import { ComposerAddDrawer } from '@app/features/channel/Input/ComposerAddMenu';import { MobileSettingsSheet } from '@app/features/settings/MobileSettingsSheet';import { SettingsPage, SettingsRow } from '@app/features/settings/primitives';import { toast } from '@core/component/Toast/Toast';@@ -315,6 +316,38 @@ function DiscardScenario() {);}+/** The composer's +, the sheet the focus ring was reported on. */+function MenuScenario() {+ const [open, setOpen] = createSignal(true);+ let editor: HTMLDivElement | undefined;+ const item = (id: string, label: string) => ({+ id,+ label,+ icon: <span aria-hidden="true">+</span>,+ onSelect: () => press(label),+ });+ return (+ <>+ <div ref={editor} contenteditable class="fixed bottom-2 left-4 text-xs" />+ <ComposerAddDrawer+ open={open()}+ onOpenChange={setOpen}+ getEditor={() => editor}+ groups={[+ {+ items: [+ { ...item('mention', 'Mention'), focusesEditor: true },+ item('files', 'Attach files'),+ item('gif', 'GIF'),+ ],+ },+ { items: [item('task', 'New task'), item('poll', 'New poll')] },+ ]}+ />+ </>+ );+}+/*** Shaped like a task's Properties sheet: rows down to its bottom edge, where* the phone prompt sits, and a picker stacked on it, searching from the same@@ -381,6 +414,71 @@ function PersistentPromptScenario() {);}+/** Shaped like the repository picker: a sheet opened to type a search into. */+function TypingScenario() {+ const [open, setOpen] = createSignal(true);+ return (+ <MobileDrawer side="bottom" open={open()} onOpenChange={setOpen}>+ <MobileDrawer.Portal>+ <MobileDrawer.Overlay />+ <MobileDrawer.Content aria-label="Choose a repository">+ <MobileDrawer.Handle />+ <input+ aria-label="Search repositories"+ class="mx-4 mb-2 h-9 bg-transparent outline-none"+ />+ <MobileDrawer.ScrollBody>+ <MobileDrawer.Section class="flex flex-col">+ <MobileDrawer.Item onClick={() => press('macro')}>+ macro+ </MobileDrawer.Item>+ </MobileDrawer.Section>+ </MobileDrawer.ScrollBody>+ </MobileDrawer.Content>+ </MobileDrawer.Portal>+ </MobileDrawer>+ );+}++/** Shaped like the model picker: the field it opens for is named explicitly. */+function SearchScenario() {+ const [open, setOpen] = createSignal(true);+ const [search, setSearch] = createSignal<HTMLInputElement>();+ return (+ <MobileDrawer+ side="bottom"+ open={open()}+ onOpenChange={setOpen}+ initialFocusEl={search()}+ >+ <MobileDrawer.Portal>+ <MobileDrawer.Overlay />+ <MobileDrawer.Content aria-label="Choose a model">+ <MobileDrawer.Handle />+ {/* Behind the Back row, so only the named target can focus it. */}+ <div class="flex items-center gap-2 px-4 pb-2">+ <Button variant="ghost" onClick={() => press('Back')}>+ Back+ </Button>+ <input+ ref={setSearch}+ aria-label="Search models"+ class="h-9 min-w-0 flex-1 bg-transparent outline-none"+ />+ </div>+ <MobileDrawer.ScrollBody>+ <MobileDrawer.Section class="flex flex-col">+ <MobileDrawer.Item onClick={() => press('Sonnet')}>+ Sonnet+ </MobileDrawer.Item>+ </MobileDrawer.Section>+ </MobileDrawer.ScrollBody>+ </MobileDrawer.Content>+ </MobileDrawer.Portal>+ </MobileDrawer>+ );+}+function Fixture() {const scenario = new URLSearchParams(location.search).get('scenario');return (@@ -410,6 +508,15 @@ function Fixture() {<Match when={scenario === 'uncontrolled'}><UncontrolledScenario /></Match>+ <Match when={scenario === 'menu'}>+ <MenuScenario />+ </Match>+ <Match when={scenario === 'typing'}>+ <TypingScenario />+ </Match>+ <Match when={scenario === 'search'}>+ <SearchScenario />+ </Match></Switch><ImperativeDialogHost /></>diff --git a/apps/web/src/features/block-agent/component/EffortSelector.test.tsx b/apps/web/src/features/block-agent/component/EffortSelector.test.tsxindex 13f7c710fe..13a13de244 100644--- a/apps/web/src/features/block-agent/component/EffortSelector.test.tsx+++ b/apps/web/src/features/block-agent/component/EffortSelector.test.tsx@@ -112,7 +112,9 @@ it('returns focus to the composer when the mobile chooser closes', async () => {));fireEvent.click(screen.getByRole('button', { name: 'Effort: Low' }));const low = await screen.findByRole('button', { name: 'Low' });- await waitFor(() => expect(document.activeElement).toBe(low));+ // The sheet takes focus, not its first row, so no row opens ringed.+ const sheet = low.closest('[data-corvu-drawer-content]');+ await waitFor(() => expect(document.activeElement).toBe(sheet));fireEvent.keyDown(low, { key: 'Escape' });await waitFor(() => expect(document.activeElement).toBe(input));});diff --git a/apps/web/src/features/email-thread/views/mobile-email-compose.test.tsx b/apps/web/src/features/email-thread/views/mobile-email-compose.test.tsxindex 4f5b0dac13..0ecdf41a17 100644--- a/apps/web/src/features/email-thread/views/mobile-email-compose.test.tsx+++ b/apps/web/src/features/email-thread/views/mobile-email-compose.test.tsx@@ -162,11 +162,9 @@ it('routes Escape to draft choices and dismisses those before the composer', asyfireEvent.click(screen.getByRole('button', { name: 'Reply' }));fireEvent.keyDown(document, { key: 'Escape' });const save = await screen.findByRole('button', { name: 'Save Draft' });- await waitFor(() =>- expect(document.activeElement).toBe(- screen.getByRole('button', { name: 'Delete Draft' })- )- );+ // The choices sheet takes focus, not its first row, so no row opens ringed.+ const choices = save.closest('[data-corvu-drawer-content]');+ await waitFor(() => expect(document.activeElement).toBe(choices));fireEvent.keyDown(save, { key: 'Escape' });await waitFor(() =>expect(screen.queryByRole('button', { name: 'Save Draft' })).toBeNull()