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(sheets): focus the grid when a spreadsheet loads (#7680)
teo79fdb0740147
diff --git a/apps/web/src/features/block-spreadsheet/SpreadsheetBlock.tsx b/apps/web/src/features/block-spreadsheet/SpreadsheetBlock.tsxindex 2ea9664eb6..287a05fa7f 100644--- a/apps/web/src/features/block-spreadsheet/SpreadsheetBlock.tsx+++ b/apps/web/src/features/block-spreadsheet/SpreadsheetBlock.tsx@@ -9,6 +9,8 @@ import {SplitHeaderRight,} from '@components/app/split-layout/components/SplitHeader';import { BlockItemSplitLabel } from '@components/app/split-layout/components/SplitLabel';+import { useCanAutofocusSplitContent } from '@components/app/split-layout/layoutUtils';+import { useNavigatedFromJK } from '@components/app/useNavigatedFromJK';import { useBlockId } from '@core/block';import { DocumentBlockContainer } from '@core/component/DocumentBlockContainer';import { BlockLiveIndicators } from '@core/component/LiveIndicators';@@ -71,6 +73,8 @@ function SpreadsheetBlockContent(props: { share?: string }) {const canEdit = useCanEdit();const userId = useUserId();const permissions = useGetPermissions();+ const canAutofocus = useCanAutofocusSplitContent();+ const { navigatedFromJK } = useNavigatedFromJK();const openShare = useShareModal(() => ({id: documentId,blockAlias: 'spreadsheet',@@ -173,6 +177,7 @@ function SpreadsheetBlockContent(props: { share?: string }) {<SpreadsheetComments documentId={documentId} store={store}>{(commentLocation, comments) => (<SpreadsheetEditor+ autoFocus={canAutofocus && !navigatedFromJK()}commentLocation={commentLocation()}comments={comments}mentions={spreadsheetMentions}diff --git a/apps/web/src/features/block-spreadsheet/SpreadsheetDemo.tsx b/apps/web/src/features/block-spreadsheet/SpreadsheetDemo.tsxindex fdf746ce8f..8905a301af 100644--- a/apps/web/src/features/block-spreadsheet/SpreadsheetDemo.tsx+++ b/apps/web/src/features/block-spreadsheet/SpreadsheetDemo.tsx@@ -218,6 +218,7 @@ export default function SpreadsheetDemo() {</Dialog><div class="min-h-0 min-w-0 flex-1"><SpreadsheetEditor+ autoFocus={!panel.isInlinePreview}mentions={spreadsheetMentions}store={store}name={name()}diff --git a/apps/web/src/features/block-spreadsheet/browser-test/README.md b/apps/web/src/features/block-spreadsheet/browser-test/README.mdindex d3c6fe9c1c..0f8dcfabe7 100644--- a/apps/web/src/features/block-spreadsheet/browser-test/README.md+++ b/apps/web/src/features/block-spreadsheet/browser-test/README.md@@ -31,7 +31,8 @@ sheet creation and rename, cross-sheet calculation, permission changes, andXLSX import/export through native browser file APIs. They also verify atomicimport undo/redo, restoring a distant selection across tabs, and formattingwithout a calculation-status flash or grid remount. Further regressions cover-immediate typing after adding or duplicating sheets, returning focus from toolbar+immediate typing after the workbook loads (without taking focus from a control+reached while loading) and after adding or duplicating sheets, returning focus from toolbarfields, range formatting/sorting, and footer controls down to a 360-pixel panel.Imported conditional formatting, validation lists and notes, imported chartsand images (drawn over their cells, following edits, deleted and restored withdiff --git a/apps/web/src/features/block-spreadsheet/browser-test/initial-focus.browser.e2e.ts b/apps/web/src/features/block-spreadsheet/browser-test/initial-focus.browser.e2e.tsnew file mode 100644index 0000000000..0115862dc7--- /dev/null+++ b/apps/web/src/features/block-spreadsheet/browser-test/initial-focus.browser.e2e.ts@@ -0,0 +1,24 @@+import { expect, test } from '@playwright/test';++test('typing right after the sheet loads edits the highlighted cell', async ({+ page,+}) => {+ await page.goto('/?load=500');+ await expect(page.getByRole('grid', { name: 'Spreadsheet' })).toBeFocused();+ await page.keyboard.type('month');+ await page.keyboard.press('Enter');+ await expect(page.locator('[data-address="A1"]')).toHaveText('month');+ await expect(page.getByRole('textbox', { name: 'Go to cell' })).toHaveValue(+ 'A2'+ );+});++test('loading does not take focus from a control the user already reached', async ({+ page,+}) => {+ await page.goto('/?load=1500');+ const address = page.getByRole('textbox', { name: 'Go to cell' });+ await address.focus();+ await expect(page.locator('[data-address="B4"]')).toHaveText('30');+ await expect(address).toBeFocused();+});diff --git a/apps/web/src/features/block-spreadsheet/views/SpreadsheetEditor.tsx b/apps/web/src/features/block-spreadsheet/views/SpreadsheetEditor.tsxindex ba01c68692..dde08d0ffe 100644--- a/apps/web/src/features/block-spreadsheet/views/SpreadsheetEditor.tsx+++ b/apps/web/src/features/block-spreadsheet/views/SpreadsheetEditor.tsx@@ -919,7 +919,14 @@ export function SpreadsheetEditor(props: {onClear={grid.clear}onGridReady={(element) => {gridElement = element;- if (props.autoFocus) focusGrid();+ // The sheet loads asynchronously; never take focus from a dialog+ // or control the user reached in the meantime.+ const active = document.activeElement;+ if (+ props.autoFocus &&+ (!active || active === document.body || active.contains(element))+ )+ focusGrid();}}/></Show>diff --git a/docs/AGENT_GUIDE/documents.md b/docs/AGENT_GUIDE/documents.mdindex 52ef64afd8..3b2fbff535 100644--- a/docs/AGENT_GUIDE/documents.md+++ b/docs/AGENT_GUIDE/documents.md@@ -99,7 +99,10 @@ use a green grid icon in file lists and search. The grid fillsthe panel beneath the formatting and formula bars. While a workbook opens, ashimmering placeholder grid (status "Opening spreadsheet…") stands in for it, andformula cells show a short shimmer bar until their first results arrive; wait for-real cell text before reading values. They have the `.spreadsheet` file type; uploading an+real cell text before reading values. Once it loads, the grid takes keyboard focus+with A1 selected, so typing immediately edits A1 and arrow keys move the selection;+it does not take focus from a dialog or control reached while loading, nor in an+inline preview or when the sheet was opened by J/K list navigation. They have the `.spreadsheet` file type; uploading anExcel (`.xlsx`, `.xlsm`) or CSV file in Files or a channel opens a read-only spreadsheet preview, including existing `/app/unknown/<uuid>` links and CSV code routes. Review **Import notes**, then choose **Edit in Macro** to create a collaborative native copy. The original file and its link remain intact. Conversion waits for a durable save before opening the copy; a failed save can be retried without creating another copy. The normal document download action retrieves the original; the spreadsheet footer exports the imported representation.You can also open a native spreadsheet and use the bottom-right **Import and export → Import…** menu to import its sheets. A large workbook shows a progress bar on **Import workbook** while it is written; the page stays responsive, and one undo removes the whole import.