From cefd3e31e1550a52fd03a78dfeea2780478d55a8 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 09:07:49 +0000 Subject: [PATCH] fix(grid): in a list cell a single click only selects; no copy buttons (#36015) On a select-first grid a plain click on a link, a referenced record's chip, a file or an image thumbnail a cell draws selects the cell and opens nothing. Ctrl/Cmd-click, the selected cell's open button and Ctrl/Cmd+Enter open it. The name link keeps its click. The email and phone copy buttons are not drawn inside such a grid; Ctrl/Cmd+C copies the selected cell. Claude-Session: https://claude.ai/code/session_01L6bhgTQn1haiL13TBfwmxm Co-authored-by: Claude --- .../36015-list-cell-click-only-selects.md | 18 ++++ content/docs/frontend/plugins/plugin-grid.mdx | 15 ++- .../data-table-select-first-35684.test.tsx | 101 +++++++++++++++--- .../src/renderers/complex/data-table.tsx | 88 ++++++++++++++- .../complex/dataTableCellSelection.ts | 43 +++++++- ui/packages/fields/src/index.tsx | 12 ++- .../ObjectGrid.cellSelection-35684.test.tsx | 85 +++++++++++++++ .../plugin-grid/src/objectGridLinkCell.tsx | 3 + 8 files changed, 344 insertions(+), 21 deletions(-) create mode 100644 .changeset/36015-list-cell-click-only-selects.md diff --git a/.changeset/36015-list-cell-click-only-selects.md b/.changeset/36015-list-cell-click-only-selects.md new file mode 100644 index 00000000000..c89c464719e --- /dev/null +++ b/.changeset/36015-list-cell-click-only-selects.md @@ -0,0 +1,18 @@ +--- +'@object-ui/components': patch +'@object-ui/fields': patch +'@object-ui/plugin-grid': patch +--- + +fix(grid): in a list cell a single click only selects, and the email and phone cells draw no copy button + +Clause-②: no +Metadata-protocol: none + +On a grid with the select-first cell model (the console's list page), a plain click on a link a cell draws used to follow it: an email opened the mail program, a phone number the dialler, a URL a new tab, a lookup or user chip that record's page, and an image thumbnail its lightbox. The cell was not selected, so a reader who meant to select or edit the cell left the list instead. The email and phone cells also drew a copy button beside the value, easy to hit while selecting. + +A plain click on any of these now selects the cell and opens nothing. To open one: Ctrl/Cmd-click it (as before), press the open button the selected cell shows on hover (only on the selected cell, never on the row hover), or press Ctrl/Cmd+Enter on the selected cell. A cell of several chips opens the first one that way. A double-click on the link edits the cell, as on any other cell. The name link is the one exception and opens the record on a single click, as before. The copy buttons are not drawn inside such a grid; Ctrl/Cmd+C copies the selected cell. + +Outside the select-first model nothing changes: the record page, related lists, phone cards, kanban cards and every grid whose host does not turn on `cellSelection` keep their links and copy buttons. + +For renderer authors: a link (`a[href]`) inside a select-first cell is now treated as part of the cell's value. Mark the one link a single click must still follow with `data-opens-on-click`, a non-link control that opens what the value points at with `data-cell-opener`, and a copy control the grid should not draw with `data-cell-copy`. diff --git a/content/docs/frontend/plugins/plugin-grid.mdx b/content/docs/frontend/plugins/plugin-grid.mdx index f681192d058..74b724d26c2 100644 --- a/content/docs/frontend/plugins/plugin-grid.mdx +++ b/content/docs/frontend/plugins/plugin-grid.mdx @@ -397,8 +397,14 @@ object and the view does not declare `userActions.editInline: false`, and `singleClickEdit` is not read there. - **A click selects** a cell (a ring around it); it neither edits nor opens the - record. A link a cell draws (the name, a lookup, a phone or an email) keeps - its own click. On a touch screen a tap opens the record. + record. Only the name link keeps its own click (it opens the record). Every + other link a cell draws (an email, a phone number, a URL, a file, a lookup or + user chip, an image thumbnail) is selected by a click too (objectstack#36015); + to open it, Ctrl/Cmd-click it, press the **Open** button the selected cell + shows on hover, or press Ctrl/Cmd+Enter. A cell of several chips opens the + first one that way. The email and phone cells draw no copy button here: + Ctrl/Cmd+C copies the selected cell. On a touch screen a tap opens the + record. - **A cut-off value shows in full** when its cell is selected: a long text, a multi-line text or a list of tags that the column truncates opens on a layer over the cell, wrapped, scrolling inside past a few lines. Escape, an @@ -415,8 +421,9 @@ object and the view does not declare `userActions.editInline: false`, and - **Selected cell keys:** the arrows and Tab move the selection; Space is typed like any other key and opens the editor (a checkbox cell flips instead, as do Enter and a second click on it); Ctrl/Cmd+C copies; Ctrl/Cmd+V converts the text - to the field's type and commits it; Escape clears the selection. The record - opens from the name link, or a tap on a touch screen. + to the field's type and commits it; Ctrl/Cmd+Enter opens the link the cell + draws; Escape clears the selection. The record opens from the name link, or + a tap on a touch screen. - **A cell that opens no editor says why** on the cell: the field is read-only, calculated or not editable in a list, the reader may not edit the field, the object or the record, the view turned editing off, or the record is locked diff --git a/ui/packages/components/src/__tests__/data-table-select-first-35684.test.tsx b/ui/packages/components/src/__tests__/data-table-select-first-35684.test.tsx index b0de1635bd9..772f38b16b7 100644 --- a/ui/packages/components/src/__tests__/data-table-select-first-35684.test.tsx +++ b/ui/packages/components/src/__tests__/data-table-select-first-35684.test.tsx @@ -18,8 +18,11 @@ * 3. Space is typed like any key and opens the editor, never the record * (the maintainer's correction on #35683); a two-state cell flips on * Space or on a second click instead, and commits. - * 4. A link the cell draws keeps its own click; a double-click on the cell - * around it edits. + * 4. A plain click on a link the cell draws selects the cell and follows + * nothing; a Ctrl/Cmd-click follows it, and a double-click on it edits + * (objectstack#36015). The title link (`data-opens-on-click`) keeps its + * click. The selected cell's open button and Ctrl/Cmd+Enter open the + * link; a copy button a value draws is not drawn. * 5. A cell that opens no editor says why on the cell: the host's sentence, * else the table's own. * 6. A touch tap opens the record and edits nothing. @@ -48,11 +51,23 @@ const ROWS = [ function renderTable({ selection = {}, extra = {}, -}: { selection?: GridCellSelection | null; extra?: Record } = {}) { + withTitle = false, +}: { selection?: GridCellSelection | null; extra?: Record; withTitle?: boolean } = {}) { const DataTable = ComponentRegistry.get('data-table')!; const onRowClick = vi.fn(); const onCellChange = vi.fn(); const onSiteClick = vi.fn(); + const onTitleClick = vi.fn(); + // The title link a host marks as the one a click follows (objectstack#36015). + const titleColumn = { + header: 'Title', + accessorKey: 'title', + cell: (_value: unknown, row: { id: string }) => ( + { e.preventDefault(); onTitleClick(row.id); }}> + Record {row.id} + + ), + }; const schema = { type: 'data-table', columns: [ @@ -63,9 +78,13 @@ function renderTable({ header: 'Site', accessorKey: 'site', cell: (value: string) => ( - { e.preventDefault(); onSiteClick(value); }}>{value} + + { e.preventDefault(); onSiteClick(value); }}>{value} + + ), }, + ...(withTitle ? [titleColumn] : []), ], data: ROWS, editable: true, @@ -85,7 +104,7 @@ function renderTable({ utils.container.querySelectorAll('tbody tr')[row].querySelectorAll('td[data-grid-cell]')[col] as HTMLElement; const editor = () => utils.container.querySelector('td[data-editing-cell] input'); const catcher = () => utils.container.querySelector('[data-slot="cell-type-catcher"]'); - return { ...utils, cell, editor, catcher, onRowClick, onCellChange, onSiteClick }; + return { ...utils, cell, editor, catcher, onRowClick, onCellChange, onSiteClick, onTitleClick }; } describe('data-table select-first — a click selects (objectstack#35684)', () => { @@ -186,20 +205,78 @@ describe('data-table select-first — Space types; a two-state cell flips', () = }); }); -describe('data-table select-first — a link in a cell keeps its click', () => { - it('a click on the link follows it and selects nothing; a double-click beside it edits', () => { +describe('data-table select-first — a click on a link the cell draws only selects (objectstack#36015)', () => { + it('a plain click selects the cell and follows nothing; a Ctrl or Cmd click follows the link', () => { + const t = renderTable(); + const link = screen.getByText('a.example'); + const plain = fireEvent.click(link); + expect(t.onSiteClick).not.toHaveBeenCalled(); + // The browser's own navigation was cancelled too. + expect(plain).toBe(false); + expect(t.cell(0, 3)).toHaveAttribute('data-selected-cell'); + expect(t.onRowClick).not.toHaveBeenCalled(); + expect(document.activeElement).toBe(t.catcher()); + fireEvent.click(link, { ctrlKey: true }); + expect(t.onSiteClick).toHaveBeenCalledTimes(1); + fireEvent.click(link, { metaKey: true }); + expect(t.onSiteClick).toHaveBeenCalledTimes(2); + }); + + it('a double-click on the link edits, as on any cell', () => { const t = renderTable(); fireEvent.click(screen.getByText('a.example')); - expect(t.onSiteClick).toHaveBeenCalledWith('a.example'); - expect(t.cell(0, 3)).not.toHaveAttribute('data-selected-cell'); fireEvent.doubleClick(screen.getByText('a.example')); - expect(t.editor()).toBeNull(); - // The cell around the link. + expect(t.editor()).toHaveValue('a.example'); + expect(t.onSiteClick).not.toHaveBeenCalled(); + }); + + it('control: the title link (data-opens-on-click) keeps its click and selects nothing', () => { + const t = renderTable({ withTitle: true }); + fireEvent.click(screen.getByText('Record 1')); + expect(t.onTitleClick).toHaveBeenCalledWith('1'); + expect(t.cell(0, 4)).not.toHaveAttribute('data-selected-cell'); + }); + + it('the selected cell draws an open button that follows the link; an unselected cell draws none', () => { + const t = renderTable(); + expect(t.cell(0, 3).querySelector('[data-testid="cell-open-button"]')).toBeNull(); fireEvent.click(t.cell(0, 3)); + const open = t.cell(0, 3).querySelector('[data-testid="cell-open-button"]')!; + expect(open).toHaveAccessibleName('Open'); + expect(open.className).toContain('flex'); + fireEvent.click(open); + expect(t.onSiteClick).toHaveBeenCalledWith('a.example'); + // The cell stays selected. expect(t.cell(0, 3)).toHaveAttribute('data-selected-cell'); - fireEvent.doubleClick(t.cell(0, 3)); + }); + + it('a selected cell with nothing to open hides its open button', () => { + const t = renderTable(); + fireEvent.click(t.cell(0, 0)); + const open = t.cell(0, 0).querySelector('[data-testid="cell-open-button"]')!; + expect(open.className).toContain('hidden'); + expect(open.className).not.toMatch(/(^|\s)flex(\s|$)/); + }); + + it('Ctrl or Cmd+Enter on the selected cell follows the link; plain Enter edits', () => { + const t = renderTable(); + fireEvent.click(t.cell(0, 3)); + fireEvent.keyDown(t.catcher()!, { key: 'Enter', ctrlKey: true }); + expect(t.onSiteClick).toHaveBeenCalledTimes(1); + fireEvent.keyDown(t.catcher()!, { key: 'Enter', metaKey: true }); + expect(t.onSiteClick).toHaveBeenCalledTimes(2); + expect(t.editor()).toBeNull(); + fireEvent.keyDown(t.catcher()!, { key: 'Enter' }); expect(t.editor()).toHaveValue('a.example'); }); + + it('a copy button a value draws is hidden in the select-first table, and only there', () => { + const t = renderTable(); + expect(t.cell(0, 3).className).toContain('[&_[data-cell-copy]]:hidden'); + cleanup(); + const control = renderTable({ selection: null, extra: { keyboardNavigation: true } }); + expect(control.cell(0, 3).className).not.toContain('[data-cell-copy]'); + }); }); describe('data-table select-first — a cell that opens no editor says why', () => { diff --git a/ui/packages/components/src/renderers/complex/data-table.tsx b/ui/packages/components/src/renderers/complex/data-table.tsx index a2c7ee9de2f..dbeacb85441 100644 --- a/ui/packages/components/src/renderers/complex/data-table.tsx +++ b/ui/packages/components/src/renderers/complex/data-table.tsx @@ -15,7 +15,7 @@ import { DisabledReasonMenuLabel, menuItemReasonAria, useDisabledReason } from ' import { useGridFieldAuthoring } from '../../context/gridFieldAuthoring'; import { useGridCellSelection } from '../../context/gridCellSelection'; import { useGridHeaderMenu } from '../../context/gridHeaderMenu'; -import { caretToEnd, defaultTyping, defaultValueFromText, firstEditorControl, isCellWidgetTarget, isCommandLetter, isImeKey, isPrintableKey } from './dataTableCellSelection'; +import { caretToEnd, cellOpenerAt, defaultTyping, defaultValueFromText, firstCellOpener, firstEditorControl, isCellWidgetTarget, isCommandLetter, isImeKey, isPrintableKey } from './dataTableCellSelection'; import { useHorizontalOverflow, HOVER_SCROLLBAR_CLASSES } from '../../custom/use-horizontal-overflow'; import { ActiveListRow, listRecordIdOf } from '../../custom/record-list-face'; import { describeIgnoredBind, describeNonArrayData } from './dataTableBindDiagnostic'; @@ -69,6 +69,7 @@ import { AlertCircle, Check, Loader2, + SquareArrowOutUpRight, } from 'lucide-react'; import { DropdownMenu, @@ -1404,6 +1405,53 @@ function CellNotice({ text, onDismiss }: { text: string; onDismiss: () => void } ); } +/** + * objectstack#36015 — the selected cell's "open" button: drawn only while the + * cell draws something that opens (a link, a referenced record's chip, an + * image), shown when the pointer is over the cell. A plain click on that + * thing only selected the cell; this opens it. It takes no focus, so typing + * carries on in the cell, and the keyboard's way is Ctrl/Cmd+Enter. + */ +function CellOpenButton({ label, onOpen }: { label: string; onOpen: (cell: HTMLElement) => void }) { + const ref = useRef(null); + const [cell, setCell] = useState(null); + const [opens, setOpens] = useState(false); + useLayoutEffect(() => { + const host = ref.current?.closest('td') ?? null; + setCell(host); + if (!host) return undefined; + // A referenced record's name is read after the cell first draws, and its + // chip becomes a link only then. + const measure = () => setOpens(firstCellOpener(host) !== null); + measure(); + if (typeof MutationObserver === 'undefined') return undefined; + const observer = new MutationObserver(measure); + observer.observe(host, { childList: true, subtree: true, attributes: true, attributeFilter: ['href'] }); + return () => observer.disconnect(); + }, []); + return ( + + ); +} + /** * objectstack#35685 — why a list cell's save was refused, said on that cell: * the server's reasons, one line each, and, when the refusal names a field the @@ -3598,6 +3646,22 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => { const factsOf = (row: any, col: TableColumn) => cellSelection?.describeCell?.(row, col.accessorKey) ?? null; + // objectstack#36015 — while set, a click on a cell's opener follows it: the + // open button or Ctrl/Cmd+Enter is clicking it on the reader's behalf. + const followingOpenerRef = useRef(false); + /** Opens what the cell draws (its first opener); `false` when it draws none. */ + const openCellOpener = (cell: Element): boolean => { + const opener = firstCellOpener(cell); + if (!opener) return false; + followingOpenerRef.current = true; + try { + opener.click(); + } finally { + followingOpenerRef.current = false; + } + return true; + }; + /** Why this cell opens no editor, or `null` when it opens one. */ const readOnlyReasonOf = (row: any, col: TableColumn): string | null => { const reason = factsOf(row, col)?.readOnlyReason; @@ -3719,6 +3783,11 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => { return; } setCellNotice(null); + if (onCatcher && e.key === 'Enter' && (e.ctrlKey || e.metaKey) && !e.altKey && !e.shiftKey) { + // objectstack#36015 — Ctrl/Cmd+Enter opens what the selected cell draws. + if (openCellOpener(e.currentTarget)) e.preventDefault(); + return; + } const next = navigationTarget(e, rowIndex, colIndex); if (next) { e.preventDefault(); @@ -4919,6 +4988,9 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => { // A ring that moves no layout (outline, not border). isSelectedCell && "outline-2 -outline-offset-2 outline-primary", selectFirst && !isFrozen && "relative", + // objectstack#36015 — a single click selects, and Ctrl/Cmd+C copies + // the selected cell, so the copy buttons a value draws are not drawn. + selectFirst && "group/cell [&_[data-cell-copy]]:hidden", !autosaves && hasPendingChange && "font-semibold text-amber-700 dark:text-amber-400", cellError !== undefined && "ring-2 ring-inset ring-destructive", isFrozen && ['sticky z-10 bg-background', STICKY_ROW_TINT], @@ -4941,6 +5013,17 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => { // where its column does. ...(pinnedRightOffset ? { right: pinnedRightOffset } : {}), }} + onClickCapture={selectFirst ? (e) => { + // objectstack#36015 — a plain click on a link, a referenced + // record's chip or an image the cell draws selects the cell and + // opens nothing. A modifier click opens it as it always did. + if (isEditing || followingOpenerRef.current || isTouchPress(e)) return; + if (cellOpenerAt(e.target, e.currentTarget) === null) return; + if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button !== 0) return; + e.preventDefault(); + e.stopPropagation(); + selectCell(rowIndex, colIndex); + } : undefined} onMouseDown={selectFirst ? (e) => { // The double-click is the edit gesture here, so its second // press does not select the word under the pointer. @@ -5055,6 +5138,9 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => { }} /> )} + {isSelectedCell && !isEditing && ( + + )} {cellNotice?.rowIndex === rowIndex && cellNotice.colIndex === colIndex && ( setCellNotice(null)} /> )} diff --git a/ui/packages/components/src/renderers/complex/dataTableCellSelection.ts b/ui/packages/components/src/renderers/complex/dataTableCellSelection.ts index 8f6ca7a5e22..411fc59201c 100644 --- a/ui/packages/components/src/renderers/complex/dataTableCellSelection.ts +++ b/ui/packages/components/src/renderers/complex/dataTableCellSelection.ts @@ -25,12 +25,49 @@ export function isImeKey(e: { nativeEvent: KeyboardEvent; keyCode?: number }): b } /** - * A press on a control a cell draws (a record link, a phone or mail link, a - * button, a checkbox) keeps its own click: it is not a press on the cell. A - * disabled control (a read face's checkbox) has no click of its own. + * The attribute a link wears when a single click on it still follows it in a + * select-first grid: the row's title link (the name column). Every other link + * a cell draws is one of the cell's {@link cellOpenerAt openers}. + */ +export const OPENS_ON_CLICK_ATTRIBUTE = 'data-opens-on-click'; + +/** + * The attribute a cell renderer puts on a non-link control that opens what the + * value points at (an image thumbnail's lightbox), so the select-first grid + * treats it as it treats a link. + */ +export const CELL_OPENER_ATTRIBUTE = 'data-cell-opener'; + +const CELL_OPENER_SELECTOR = `a[href]:not([${OPENS_ON_CLICK_ATTRIBUTE}]), [${CELL_OPENER_ATTRIBUTE}]`; + +/** + * What a cell draws that opens something — a mail, phone or web link, a + * referenced record's chip, a file, an image — at or around `target`, or + * `null`. In a select-first grid a plain click on one only selects the cell; + * it is opened by a Ctrl/Cmd-click, the selected cell's open button or + * Ctrl/Cmd+Enter. + */ +export function cellOpenerAt(target: EventTarget | null, cell: Element): HTMLElement | null { + if (!(target instanceof Element) || !cell.contains(target)) return null; + const opener = target.closest(CELL_OPENER_SELECTOR); + return opener !== null && opener !== cell && cell.contains(opener) ? opener : null; +} + +/** The first opener a cell draws (a cell of several chips opens the first), or `null`. */ +export function firstCellOpener(cell: Element): HTMLElement | null { + return cell.querySelector(CELL_OPENER_SELECTOR); +} + +/** + * A press on a control a cell draws (the title link, a button, a checkbox) + * keeps its own click: it is not a press on the cell. A disabled control (a + * read face's checkbox) has no click of its own, and an opener + * ({@link cellOpenerAt}) is part of the value: a press on it is a press on + * the cell. */ export function isCellWidgetTarget(target: EventTarget | null, cell: Element): boolean { if (!(target instanceof Element) || !cell.contains(target)) return false; + if (cellOpenerAt(target, cell) !== null) return false; const widget = target.closest( 'a[href], button, input, select, textarea, label, [role="link"], [role="button"], [role="checkbox"], [role="switch"], [contenteditable]:not([contenteditable="false"])', ); diff --git a/ui/packages/fields/src/index.tsx b/ui/packages/fields/src/index.tsx index 65c8cd2eefc..31e5154bc11 100644 --- a/ui/packages/fields/src/index.tsx +++ b/ui/packages/fields/src/index.tsx @@ -2031,8 +2031,11 @@ export function EmailCellRenderer({ value }: CellRendererProps): React.ReactElem {safe} + {/* A select-first grid does not draw this (`data-cell-copy`): there a + click selects the cell and Ctrl/Cmd+C copies it (objectstack#36015). */}