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): keep dropdown lists beside their cell and switch in one click (#8138)
teoc7c65ee8b8ad
diff --git a/apps/web/src/features/block-spreadsheet/README.md b/apps/web/src/features/block-spreadsheet/README.mdindex 51139e5791..7693bbcbd0 100644--- a/apps/web/src/features/block-spreadsheet/README.md+++ b/apps/web/src/features/block-spreadsheet/README.md@@ -378,6 +378,9 @@ Import keeps what Excel calculates and shows:rejects the entry, warnings and information accept it, and each shows therule's message in the footer. List rules offer their values in a dropdown on theactive cell (Alt+Down), and every cell they cover shows an arrow that opens it.+ `components/CellListMenu.tsx` anchors the non-modal list to the cell: below it,+ or above or beside it when there is no room, never over it. While a list is+ open, pressing another dropdown cell opens that cell's list instead.`components/DropdownDialog.tsx` (Format and data → Dropdown…, or the cell menu)adds, edits and removes list rules on the selection through`packages/spreadsheet/src/data-validation.ts`, which the AI `set_dropdown` anddiff --git a/apps/web/src/features/block-spreadsheet/browser-test/README.md b/apps/web/src/features/block-spreadsheet/browser-test/README.mdindex d4ed50f575..6cc4dca9ca 100644--- a/apps/web/src/features/block-spreadsheet/browser-test/README.md+++ b/apps/web/src/features/block-spreadsheet/browser-test/README.md@@ -34,7 +34,9 @@ without a calculation-status flash or grid remount. Further regressions coverimmediate typing after the workbook loads (without taking focus from a controlreached while loading) and after adding or duplicating sheets, returning focus from toolbarfields, range formatting/sorting, and footer controls down to a 360-pixel panel.-Dropdowns added, used and removed from the toolbar and cell menus,+Dropdowns added, used and removed from the toolbar and cell menus, open lists+kept clear of their cell (above it near the bottom edge) and moved to another+dropdown cell with one click,imported conditional formatting, validation lists and notes, imported chartsand images (drawn over their cells, following edits, deleted and restored withundo, and kept in the download), radar, bubble, stock and contour charts@@ -70,8 +72,8 @@ bunx playwright test --config src/features/block-spreadsheet/browser-test/playwrThe `android-chrome` (Pixel 7) and `iphone-webkit` (iPhone 13) projects exercisetouch taps, edit/apply/cancel, formula suggestions, selection/reference handles,-formatting menus, sheet creation/rename, find, viewer permissions, and the narrow-footer. Landscape and reduced viewport checks cover layout with less vertical+formatting menus, sheet creation/rename, find, viewer permissions, the narrow+footer, and tapping between dropdown cells while a list is open. Landscape and reduced viewport checks cover layout with less verticalspace. Chromium swipes and handle drags use CDP's trusted touch input, includingnative scrolling and pointer cancellation; ribbon swipes must not format cells.WebKit exposes touch taps but no trusted touch-drag API, so its handle tests use adiff --git a/apps/web/src/features/block-spreadsheet/browser-test/dropdowns.browser.e2e.ts b/apps/web/src/features/block-spreadsheet/browser-test/dropdowns.browser.e2e.tsindex 7ad27c2351..8284b8c96c 100644--- a/apps/web/src/features/block-spreadsheet/browser-test/dropdowns.browser.e2e.ts+++ b/apps/web/src/features/block-spreadsheet/browser-test/dropdowns.browser.e2e.ts@@ -75,6 +75,60 @@ test('a dropdown added from the menu shows arrows, offers its choices and rejectawait expect(cell(page, 'C4')).toHaveText('High');});+test('an open list stays beside its cell and moves to another dropdown cell in one click', async ({+ page,+}) => {+ const grid = page.getByRole('grid', { name: 'Spreadsheet' });+ await cell(page, 'C2').click();+ await cell(page, 'E12').click({ modifiers: ['Shift'] });+ await page.getByRole('button', { name: 'Format and data' }).click();+ await page.getByRole('menuitem', { name: 'Dropdown…' }).click();+ const dialog = page.getByRole('dialog', { name: 'Dropdown' });+ await dialog+ .getByRole('textbox', { name: 'Choices, one per line' })+ .fill('Low\nMedium\nHigh');+ await dialog.getByRole('button', { name: 'Save' }).click();+ await expect(dialog).toBeHidden();++ const list = page.getByRole('menu');+ await page.getByRole('button', { name: 'Choose a value for C2' }).click();+ await expect(list.getByRole('menuitem')).toHaveText([+ 'Low',+ 'Medium',+ 'High',+ ]);+ const c2 = await cell(page, 'C2').boundingBox();+ const below = await list.boundingBox();+ expect(below!.y).toBeGreaterThanOrEqual(c2!.y + c2!.height);++ await cell(page, 'E2').click();+ await expect(cell(page, 'E2')).toHaveAttribute('aria-selected', 'true');+ await expect(+ page.getByRole('button', { name: 'Choose a value for E2' })+ ).toHaveAttribute('aria-expanded', 'true');+ await expect(list.getByRole('menuitem', { name: 'Low' })).toBeFocused();+ await page.keyboard.press('ArrowDown');+ await expect(list.getByRole('menuitem', { name: 'Medium' })).toBeFocused();+ await page.keyboard.press('Enter');+ await expect(list).toBeHidden();+ await expect(cell(page, 'E2')).toHaveText('Medium');+ await expect(cell(page, 'C2')).toHaveText('');+ await expect(grid).toBeFocused();++ // Without room below, the list opens above the cell instead of over it.+ await page.setViewportSize({ width: 1440, height: 420 });+ await cell(page, 'D12').click();+ await page.keyboard.press('Alt+ArrowDown');+ await expect(list).toBeVisible();+ const d12 = await cell(page, 'D12').boundingBox();+ const above = await list.boundingBox();+ expect(above!.y + above!.height).toBeLessThanOrEqual(d12!.y);+ await page.keyboard.press('Escape');+ await expect(list).toBeHidden();+ await expect(grid).toBeFocused();+ await expect(cell(page, 'D12')).toHaveText('');+});+test('a dropdown can list the values of a range and accept other entries', async ({page,}) => {diff --git a/apps/web/src/features/block-spreadsheet/browser-test/spreadsheet.mobile.e2e.ts b/apps/web/src/features/block-spreadsheet/browser-test/spreadsheet.mobile.e2e.tsindex 1d39310cdd..0e56b175d5 100644--- a/apps/web/src/features/block-spreadsheet/browser-test/spreadsheet.mobile.e2e.ts+++ b/apps/web/src/features/block-spreadsheet/browser-test/spreadsheet.mobile.e2e.ts@@ -280,6 +280,43 @@ test('touch formatting and sheet navigation preserve workbook state', async ({await expect(addressBar(page)).toHaveValue('A2');});+test('tapping another dropdown cell moves the open list there, and other cells close it', async ({+ page,+}) => {+ for (const address of ['C4', 'C2']) {+ await cell(page, address).tap();+ await tapMenu(page, 'Format and data', 'Dropdown…');+ const dialog = page.getByRole('dialog', { name: 'Dropdown' });+ await dialog+ .getByRole('textbox', { name: 'Choices, one per line' })+ .fill('Low\nMedium\nHigh');+ await button(page, 'Save').tap();+ await expect(dialog).toBeHidden();+ }+ const list = page.getByRole('menu');+ const marker = (address: string) =>+ cell(page, address).locator('[data-dropdown-marker]');++ await marker('C4').tap();+ await expect(list).toBeVisible();+ await cell(page, 'C2').tap();+ await expect(button(page, 'Choose a value for C2')).toHaveAttribute(+ 'aria-expanded',+ 'true'+ );+ await list.getByRole('menuitem', { name: 'High' }).tap();+ await expect(list).toBeHidden();+ await expect(cell(page, 'C2')).toHaveText('High');++ await marker('C4').tap();+ await expect(list).toBeVisible();+ await cell(page, 'E8').tap();+ await expect(list).toBeHidden();+ await cell(page, 'C4').tap();+ await expect(cell(page, 'C4')).toHaveAttribute('aria-selected', 'true');+ await expect(list).toBeHidden();+});+test('viewer touch controls keep editing disabled while allowing selection and downloads', async ({page,}) => {diff --git a/apps/web/src/features/block-spreadsheet/components/CellListMenu.tsx b/apps/web/src/features/block-spreadsheet/components/CellListMenu.tsxindex 44272eddae..8d31870d53 100644--- a/apps/web/src/features/block-spreadsheet/components/CellListMenu.tsx+++ b/apps/web/src/features/block-spreadsheet/components/CellListMenu.tsx@@ -1,59 +1,86 @@import CaretDown from '@phosphor/caret-down.svg';-import { Dropdown } from '@ui/components/Dropdown';+import { Dropdown, type DropdownContentProps } from '@ui/components/Dropdown';import { For, type JSX } from 'solid-js';/*** A list-validated cell's choices, opened from a button beside the active- * cell as in Excel, or with Alt+Down.+ * cell as in Excel, or with Alt+Down. The list is a non-modal popover: it opens+ * below the cell, or above or beside it when there is no room, never over it,+ * and the sheet stays visible and usable around it.*/export function CellListMenu(props: {address: string;items: string[];open: boolean;onOpenChange: (open: boolean) => void;+ /** The active cell and its button, at the bottom right of this box. */style: JSX.CSSProperties;+ buttonSize: number;onPick: (item: string) => void;onRestoreFocus: () => void;+ /** Prevent the default to keep the list open through a press outside it. */+ onPointerDownOutside: DropdownContentProps['onPointerDownOutside'];}) {+ let anchor!: HTMLDivElement;return (<div- class="absolute z-[3]"+ ref={anchor}+ class="pointer-events-none absolute z-[3]"style={props.style}- onPointerDown={(event) => event.stopPropagation()}- onDblClick={(event) => event.stopPropagation()}>- <Dropdown- open={props.open}- onOpenChange={props.onOpenChange}- placement="bottom-end"- modal={false}+ <div+ class="pointer-events-auto absolute right-0 bottom-0"+ style={{+ width: `${props.buttonSize}px`,+ height: `${props.buttonSize}px`,+ }}+ onPointerDown={(event) => event.stopPropagation()}+ onDblClick={(event) => event.stopPropagation()}>- <Dropdown.Trigger- variant="outline"- size="icon-xs"- label={`Choose a value for ${props.address}`}- tabIndex={-1}- class="size-full min-h-0 min-w-0 rounded-none p-0 touch:min-h-0 touch:min-w-0"+ <Dropdown+ open={props.open}+ onOpenChange={props.onOpenChange}+ getAnchorRect={() => anchor.getBoundingClientRect()}+ placement="bottom-start"+ flip="top-start right-start left-start"+ hideWhenDetached+ modal={false}>- <CaretDown class="size-3" />- </Dropdown.Trigger>- <Dropdown.Content- class="max-h-[min(18rem,60dvh)] min-w-32 max-w-80 overflow-y-auto overscroll-contain text-xs touch:text-[max(14px,0.875rem)] touch:[&_[role=menuitem]]:min-h-[44px]"- onCloseAutoFocus={(event) => {- event.preventDefault();- // Kobalte returns focus to its trigger after this handler.- queueMicrotask(props.onRestoreFocus);- }}- >- <For each={props.items}>- {(item) => (- <Dropdown.Item closeOnSelect onSelect={() => props.onPick(item)}>- <span class="truncate">{item}</span>- </Dropdown.Item>- )}- </For>- </Dropdown.Content>- </Dropdown>+ <Dropdown.Trigger+ variant="outline"+ size="icon-xs"+ label={`Choose a value for ${props.address}`}+ tabIndex={-1}+ class="size-full min-h-0 min-w-0 rounded-none p-0 touch:min-h-0 touch:min-w-0"+ >+ <CaretDown class="size-3" />+ </Dropdown.Trigger>+ <Dropdown.Content+ class="max-h-[min(18rem,var(--kb-popper-content-available-height))] min-w-[max(8rem,var(--kb-popper-anchor-width))] max-w-80 overflow-y-auto overscroll-contain text-xs backdrop-filter-none! touch:text-[max(14px,0.875rem)] touch:[&_[role=menuitem]]:min-h-[44px]"+ onPointerDownOutside={props.onPointerDownOutside}+ onCloseAutoFocus={(event) => {+ event.preventDefault();+ // Kobalte returns focus to its trigger after this handler. It runs+ // a task after closing, when the list may already be open again+ // for another cell; focus then stays with that list.+ queueMicrotask(() => {+ if (!props.open) props.onRestoreFocus();+ });+ }}+ >+ <For each={props.items}>+ {(item) => (+ <Dropdown.Item+ closeOnSelect+ onSelect={() => props.onPick(item)}+ >+ <span class="truncate">{item}</span>+ </Dropdown.Item>+ )}+ </For>+ </Dropdown.Content>+ </Dropdown>+ </div></div>);}diff --git a/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.tsx b/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.tsxindex b0a8192efe..a2ad3e910b 100644--- a/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.tsx+++ b/apps/web/src/features/block-spreadsheet/components/SpreadsheetGrid.tsx@@ -281,6 +281,16 @@ export function SpreadsheetGrid(props: {column >= bounds.left &&column <= bounds.right);+ const opensListOnPress = (position: CellPosition) =>+ listOpenAt() !== undefined &&+ listOpenAt() !== cellAddress(position) &&+ hasDropdown(position.row, position.column);+ /** Pressing a cell closes an open list, or opens that dropdown cell's list. */+ function closeOrMoveList(position: CellPosition, extend = false) {+ const opens = !extend && opensListOnPress(position);+ setListOpenAt(undefined);+ if (opens) queueMicrotask(() => setListOpenAt(cellAddress(position)));+ }const [selectedDrawing, setSelectedDrawing] = createSignal<string>();const [resizing, setResizing] = createSignal<{column: number;@@ -644,6 +654,7 @@ export function SpreadsheetGrid(props: {time - lastTap.time <= 500 &&cellAddress(props.selection.anchor) === address &&cellAddress(props.selection.focus) === address;+ closeOrMoveList(position);props.onSelect(position);if (repeat && !props.readonly) {props.onEdit();@@ -1775,6 +1786,7 @@ export function SpreadsheetGrid(props: {false;if (keepReferenceFocus) return;dragging = true;+ closeOrMoveList({ row, column }, event.shiftKey);props.onSelect({ row, column }, event.shiftKey);focusGrid();}}@@ -2099,10 +2111,28 @@ export function SpreadsheetGrid(props: {setListOpenAt(open ? address() : undefined)}style={{- left: `${columnOffsets()[props.selection.anchor.column + 1] + 1}px`,- top: `${rowOffsets()[props.selection.anchor.row + 1] - size()}px`,- width: `${size()}px`,- height: `${size()}px`,+ left: `${columnOffsets()[props.selection.anchor.column]}px`,+ top: `${rowOffsets()[props.selection.anchor.row]}px`,+ width: `${columnOffsets()[props.selection.anchor.column + 1] - columnOffsets()[props.selection.anchor.column] + 1 + size()}px`,+ height: `${rowHeights()[props.selection.anchor.row]}px`,+ }}+ buttonSize={size()}+ onPointerDownOutside={(event) => {+ const cell =+ event.target instanceof Element+ ? event.target.closest<HTMLElement>('[data-address]')+ : null;+ const position =+ cell && grid.contains(cell)+ ? parseCellAddress(cell.dataset.address ?? '')+ : undefined;+ // That cell's press handler opens its list instead.+ if (+ position &&+ !event.detail.isContextMenu &&+ opensListOnPress(position)+ )+ event.preventDefault();}}onPick={(item) => props.onPickListItem?.(item)}onRestoreFocus={focusGrid}diff --git a/docs/agent-guide/documents.md b/docs/agent-guide/documents.mdindex ce24d272cf..191566b273 100644--- a/docs/agent-guide/documents.md+++ b/docs/agent-guide/documents.md@@ -185,7 +185,11 @@ current choices. Agents add the same dropdowns with `EditSpreadsheet`'sEvery cell with a dropdown (from the dialog, an agent, or an Excel list rule) showsa small arrow at its right edge; clicking it selects the cell and opens itschoices. The selected cell's arrow sits just outside its right edge (**Choose a-value for B2**); click it or press Alt+Down. Typing a value the rule does not allow+value for B2**); click it or press Alt+Down. The list opens below the cell, or+above or beside it when there is no room, without covering the cell or dimming the+sheet. Up/Down and Enter pick a choice and Escape closes it. While a list is open,+one click or tap on another dropdown cell opens that cell's list; any other cell+closes it. Typing a value the rule does not allowshows the rule's message in the footer, and a "stop" rule keeps the previous value.A red corner marks a cell with a note; selecting the cell shows the note, and anyinput message, beside it.