Skip to content

Commit cefd3e3

Browse files
committed
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 <noreply@anthropic.com>
1 parent c00be39 commit cefd3e3

8 files changed

Lines changed: 344 additions & 21 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@object-ui/components': patch
3+
'@object-ui/fields': patch
4+
'@object-ui/plugin-grid': patch
5+
---
6+
7+
fix(grid): in a list cell a single click only selects, and the email and phone cells draw no copy button
8+
9+
Clause-②: no
10+
Metadata-protocol: none
11+
12+
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.
13+
14+
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.
15+
16+
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.
17+
18+
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`.

‎content/docs/frontend/plugins/plugin-grid.mdx‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,14 @@ object and the view does not declare `userActions.editInline: false`, and
397397
`singleClickEdit` is not read there.
398398

399399
- **A click selects** a cell (a ring around it); it neither edits nor opens the
400-
record. A link a cell draws (the name, a lookup, a phone or an email) keeps
401-
its own click. On a touch screen a tap opens the record.
400+
record. Only the name link keeps its own click (it opens the record). Every
401+
other link a cell draws (an email, a phone number, a URL, a file, a lookup or
402+
user chip, an image thumbnail) is selected by a click too (objectstack#36015);
403+
to open it, Ctrl/Cmd-click it, press the **Open** button the selected cell
404+
shows on hover, or press Ctrl/Cmd+Enter. A cell of several chips opens the
405+
first one that way. The email and phone cells draw no copy button here:
406+
Ctrl/Cmd+C copies the selected cell. On a touch screen a tap opens the
407+
record.
402408
- **A cut-off value shows in full** when its cell is selected: a long text, a
403409
multi-line text or a list of tags that the column truncates opens on a
404410
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
415421
- **Selected cell keys:** the arrows and Tab move the selection; Space is typed
416422
like any other key and opens the editor (a checkbox cell flips instead, as
417423
do Enter and a second click on it); Ctrl/Cmd+C copies; Ctrl/Cmd+V converts the text
418-
to the field's type and commits it; Escape clears the selection. The record
419-
opens from the name link, or a tap on a touch screen.
424+
to the field's type and commits it; Ctrl/Cmd+Enter opens the link the cell
425+
draws; Escape clears the selection. The record opens from the name link, or
426+
a tap on a touch screen.
420427
- **A cell that opens no editor says why** on the cell: the field is read-only,
421428
calculated or not editable in a list, the reader may not edit the field, the
422429
object or the record, the view turned editing off, or the record is locked

‎ui/packages/components/src/__tests__/data-table-select-first-35684.test.tsx‎

Lines changed: 89 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
* 3. Space is typed like any key and opens the editor, never the record
1919
* (the maintainer's correction on #35683); a two-state cell flips on
2020
* Space or on a second click instead, and commits.
21-
* 4. A link the cell draws keeps its own click; a double-click on the cell
22-
* around it edits.
21+
* 4. A plain click on a link the cell draws selects the cell and follows
22+
* nothing; a Ctrl/Cmd-click follows it, and a double-click on it edits
23+
* (objectstack#36015). The title link (`data-opens-on-click`) keeps its
24+
* click. The selected cell's open button and Ctrl/Cmd+Enter open the
25+
* link; a copy button a value draws is not drawn.
2326
* 5. A cell that opens no editor says why on the cell: the host's sentence,
2427
* else the table's own.
2528
* 6. A touch tap opens the record and edits nothing.
@@ -48,11 +51,23 @@ const ROWS = [
4851
function renderTable({
4952
selection = {},
5053
extra = {},
51-
}: { selection?: GridCellSelection | null; extra?: Record<string, unknown> } = {}) {
54+
withTitle = false,
55+
}: { selection?: GridCellSelection | null; extra?: Record<string, unknown>; withTitle?: boolean } = {}) {
5256
const DataTable = ComponentRegistry.get('data-table')!;
5357
const onRowClick = vi.fn();
5458
const onCellChange = vi.fn();
5559
const onSiteClick = vi.fn();
60+
const onTitleClick = vi.fn();
61+
// The title link a host marks as the one a click follows (objectstack#36015).
62+
const titleColumn = {
63+
header: 'Title',
64+
accessorKey: 'title',
65+
cell: (_value: unknown, row: { id: string }) => (
66+
<a href={`/record/${row.id}`} data-opens-on-click="" onClick={(e) => { e.preventDefault(); onTitleClick(row.id); }}>
67+
Record {row.id}
68+
</a>
69+
),
70+
};
5671
const schema = {
5772
type: 'data-table',
5873
columns: [
@@ -63,9 +78,13 @@ function renderTable({
6378
header: 'Site',
6479
accessorKey: 'site',
6580
cell: (value: string) => (
66-
<a href={`https://${value}`} onClick={(e) => { e.preventDefault(); onSiteClick(value); }}>{value}</a>
81+
<span>
82+
<a href={`https://${value}`} onClick={(e) => { e.preventDefault(); onSiteClick(value); }}>{value}</a>
83+
<button type="button" data-cell-copy="">Copy site</button>
84+
</span>
6785
),
6886
},
87+
...(withTitle ? [titleColumn] : []),
6988
],
7089
data: ROWS,
7190
editable: true,
@@ -85,7 +104,7 @@ function renderTable({
85104
utils.container.querySelectorAll('tbody tr')[row].querySelectorAll('td[data-grid-cell]')[col] as HTMLElement;
86105
const editor = () => utils.container.querySelector<HTMLInputElement>('td[data-editing-cell] input');
87106
const catcher = () => utils.container.querySelector<HTMLInputElement>('[data-slot="cell-type-catcher"]');
88-
return { ...utils, cell, editor, catcher, onRowClick, onCellChange, onSiteClick };
107+
return { ...utils, cell, editor, catcher, onRowClick, onCellChange, onSiteClick, onTitleClick };
89108
}
90109

91110
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', () =
186205
});
187206
});
188207

189-
describe('data-table select-first — a link in a cell keeps its click', () => {
190-
it('a click on the link follows it and selects nothing; a double-click beside it edits', () => {
208+
describe('data-table select-first — a click on a link the cell draws only selects (objectstack#36015)', () => {
209+
it('a plain click selects the cell and follows nothing; a Ctrl or Cmd click follows the link', () => {
210+
const t = renderTable();
211+
const link = screen.getByText('a.example');
212+
const plain = fireEvent.click(link);
213+
expect(t.onSiteClick).not.toHaveBeenCalled();
214+
// The browser's own navigation was cancelled too.
215+
expect(plain).toBe(false);
216+
expect(t.cell(0, 3)).toHaveAttribute('data-selected-cell');
217+
expect(t.onRowClick).not.toHaveBeenCalled();
218+
expect(document.activeElement).toBe(t.catcher());
219+
fireEvent.click(link, { ctrlKey: true });
220+
expect(t.onSiteClick).toHaveBeenCalledTimes(1);
221+
fireEvent.click(link, { metaKey: true });
222+
expect(t.onSiteClick).toHaveBeenCalledTimes(2);
223+
});
224+
225+
it('a double-click on the link edits, as on any cell', () => {
191226
const t = renderTable();
192227
fireEvent.click(screen.getByText('a.example'));
193-
expect(t.onSiteClick).toHaveBeenCalledWith('a.example');
194-
expect(t.cell(0, 3)).not.toHaveAttribute('data-selected-cell');
195228
fireEvent.doubleClick(screen.getByText('a.example'));
196-
expect(t.editor()).toBeNull();
197-
// The cell around the link.
229+
expect(t.editor()).toHaveValue('a.example');
230+
expect(t.onSiteClick).not.toHaveBeenCalled();
231+
});
232+
233+
it('control: the title link (data-opens-on-click) keeps its click and selects nothing', () => {
234+
const t = renderTable({ withTitle: true });
235+
fireEvent.click(screen.getByText('Record 1'));
236+
expect(t.onTitleClick).toHaveBeenCalledWith('1');
237+
expect(t.cell(0, 4)).not.toHaveAttribute('data-selected-cell');
238+
});
239+
240+
it('the selected cell draws an open button that follows the link; an unselected cell draws none', () => {
241+
const t = renderTable();
242+
expect(t.cell(0, 3).querySelector('[data-testid="cell-open-button"]')).toBeNull();
198243
fireEvent.click(t.cell(0, 3));
244+
const open = t.cell(0, 3).querySelector<HTMLButtonElement>('[data-testid="cell-open-button"]')!;
245+
expect(open).toHaveAccessibleName('Open');
246+
expect(open.className).toContain('flex');
247+
fireEvent.click(open);
248+
expect(t.onSiteClick).toHaveBeenCalledWith('a.example');
249+
// The cell stays selected.
199250
expect(t.cell(0, 3)).toHaveAttribute('data-selected-cell');
200-
fireEvent.doubleClick(t.cell(0, 3));
251+
});
252+
253+
it('a selected cell with nothing to open hides its open button', () => {
254+
const t = renderTable();
255+
fireEvent.click(t.cell(0, 0));
256+
const open = t.cell(0, 0).querySelector<HTMLButtonElement>('[data-testid="cell-open-button"]')!;
257+
expect(open.className).toContain('hidden');
258+
expect(open.className).not.toMatch(/(^|\s)flex(\s|$)/);
259+
});
260+
261+
it('Ctrl or Cmd+Enter on the selected cell follows the link; plain Enter edits', () => {
262+
const t = renderTable();
263+
fireEvent.click(t.cell(0, 3));
264+
fireEvent.keyDown(t.catcher()!, { key: 'Enter', ctrlKey: true });
265+
expect(t.onSiteClick).toHaveBeenCalledTimes(1);
266+
fireEvent.keyDown(t.catcher()!, { key: 'Enter', metaKey: true });
267+
expect(t.onSiteClick).toHaveBeenCalledTimes(2);
268+
expect(t.editor()).toBeNull();
269+
fireEvent.keyDown(t.catcher()!, { key: 'Enter' });
201270
expect(t.editor()).toHaveValue('a.example');
202271
});
272+
273+
it('a copy button a value draws is hidden in the select-first table, and only there', () => {
274+
const t = renderTable();
275+
expect(t.cell(0, 3).className).toContain('[&_[data-cell-copy]]:hidden');
276+
cleanup();
277+
const control = renderTable({ selection: null, extra: { keyboardNavigation: true } });
278+
expect(control.cell(0, 3).className).not.toContain('[data-cell-copy]');
279+
});
203280
});
204281

205282
describe('data-table select-first — a cell that opens no editor says why', () => {

‎ui/packages/components/src/renderers/complex/data-table.tsx‎

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { DisabledReasonMenuLabel, menuItemReasonAria, useDisabledReason } from '
1515
import { useGridFieldAuthoring } from '../../context/gridFieldAuthoring';
1616
import { useGridCellSelection } from '../../context/gridCellSelection';
1717
import { useGridHeaderMenu } from '../../context/gridHeaderMenu';
18-
import { caretToEnd, defaultTyping, defaultValueFromText, firstEditorControl, isCellWidgetTarget, isCommandLetter, isImeKey, isPrintableKey } from './dataTableCellSelection';
18+
import { caretToEnd, cellOpenerAt, defaultTyping, defaultValueFromText, firstCellOpener, firstEditorControl, isCellWidgetTarget, isCommandLetter, isImeKey, isPrintableKey } from './dataTableCellSelection';
1919
import { useHorizontalOverflow, HOVER_SCROLLBAR_CLASSES } from '../../custom/use-horizontal-overflow';
2020
import { ActiveListRow, listRecordIdOf } from '../../custom/record-list-face';
2121
import { describeIgnoredBind, describeNonArrayData } from './dataTableBindDiagnostic';
@@ -69,6 +69,7 @@ import {
6969
AlertCircle,
7070
Check,
7171
Loader2,
72+
SquareArrowOutUpRight,
7273
} from 'lucide-react';
7374
import {
7475
DropdownMenu,
@@ -1404,6 +1405,53 @@ function CellNotice({ text, onDismiss }: { text: string; onDismiss: () => void }
14041405
);
14051406
}
14061407

1408+
/**
1409+
* objectstack#36015 — the selected cell's "open" button: drawn only while the
1410+
* cell draws something that opens (a link, a referenced record's chip, an
1411+
* image), shown when the pointer is over the cell. A plain click on that
1412+
* thing only selected the cell; this opens it. It takes no focus, so typing
1413+
* carries on in the cell, and the keyboard's way is Ctrl/Cmd+Enter.
1414+
*/
1415+
function CellOpenButton({ label, onOpen }: { label: string; onOpen: (cell: HTMLElement) => void }) {
1416+
const ref = useRef<HTMLButtonElement>(null);
1417+
const [cell, setCell] = useState<HTMLElement | null>(null);
1418+
const [opens, setOpens] = useState(false);
1419+
useLayoutEffect(() => {
1420+
const host = ref.current?.closest<HTMLElement>('td') ?? null;
1421+
setCell(host);
1422+
if (!host) return undefined;
1423+
// A referenced record's name is read after the cell first draws, and its
1424+
// chip becomes a link only then.
1425+
const measure = () => setOpens(firstCellOpener(host) !== null);
1426+
measure();
1427+
if (typeof MutationObserver === 'undefined') return undefined;
1428+
const observer = new MutationObserver(measure);
1429+
observer.observe(host, { childList: true, subtree: true, attributes: true, attributeFilter: ['href'] });
1430+
return () => observer.disconnect();
1431+
}, []);
1432+
return (
1433+
<button
1434+
ref={ref}
1435+
type="button"
1436+
tabIndex={-1}
1437+
aria-label={label}
1438+
title={label}
1439+
data-testid="cell-open-button"
1440+
className={cn(
1441+
'absolute right-1 top-1/2 z-20 size-5 -translate-y-1/2 items-center justify-center rounded border bg-background text-muted-foreground opacity-0 shadow-sm transition-opacity hover:text-foreground group-hover/cell:opacity-100',
1442+
opens ? 'flex' : 'hidden',
1443+
)}
1444+
onMouseDown={(e) => e.preventDefault()}
1445+
onClick={(e) => {
1446+
e.stopPropagation();
1447+
if (cell) onOpen(cell);
1448+
}}
1449+
>
1450+
<SquareArrowOutUpRight className="size-3" aria-hidden="true" />
1451+
</button>
1452+
);
1453+
}
1454+
14071455
/**
14081456
* objectstack#35685 — why a list cell's save was refused, said on that cell:
14091457
* the server's reasons, one line each, and, when the refusal names a field the
@@ -3598,6 +3646,22 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
35983646

35993647
const factsOf = (row: any, col: TableColumn) => cellSelection?.describeCell?.(row, col.accessorKey) ?? null;
36003648

3649+
// objectstack#36015 — while set, a click on a cell's opener follows it: the
3650+
// open button or Ctrl/Cmd+Enter is clicking it on the reader's behalf.
3651+
const followingOpenerRef = useRef(false);
3652+
/** Opens what the cell draws (its first opener); `false` when it draws none. */
3653+
const openCellOpener = (cell: Element): boolean => {
3654+
const opener = firstCellOpener(cell);
3655+
if (!opener) return false;
3656+
followingOpenerRef.current = true;
3657+
try {
3658+
opener.click();
3659+
} finally {
3660+
followingOpenerRef.current = false;
3661+
}
3662+
return true;
3663+
};
3664+
36013665
/** Why this cell opens no editor, or `null` when it opens one. */
36023666
const readOnlyReasonOf = (row: any, col: TableColumn): string | null => {
36033667
const reason = factsOf(row, col)?.readOnlyReason;
@@ -3719,6 +3783,11 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
37193783
return;
37203784
}
37213785
setCellNotice(null);
3786+
if (onCatcher && e.key === 'Enter' && (e.ctrlKey || e.metaKey) && !e.altKey && !e.shiftKey) {
3787+
// objectstack#36015 — Ctrl/Cmd+Enter opens what the selected cell draws.
3788+
if (openCellOpener(e.currentTarget)) e.preventDefault();
3789+
return;
3790+
}
37223791
const next = navigationTarget(e, rowIndex, colIndex);
37233792
if (next) {
37243793
e.preventDefault();
@@ -4919,6 +4988,9 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
49194988
// A ring that moves no layout (outline, not border).
49204989
isSelectedCell && "outline-2 -outline-offset-2 outline-primary",
49214990
selectFirst && !isFrozen && "relative",
4991+
// objectstack#36015 — a single click selects, and Ctrl/Cmd+C copies
4992+
// the selected cell, so the copy buttons a value draws are not drawn.
4993+
selectFirst && "group/cell [&_[data-cell-copy]]:hidden",
49224994
!autosaves && hasPendingChange && "font-semibold text-amber-700 dark:text-amber-400",
49234995
cellError !== undefined && "ring-2 ring-inset ring-destructive",
49244996
isFrozen && ['sticky z-10 bg-background', STICKY_ROW_TINT],
@@ -4941,6 +5013,17 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
49415013
// where its column does.
49425014
...(pinnedRightOffset ? { right: pinnedRightOffset } : {}),
49435015
}}
5016+
onClickCapture={selectFirst ? (e) => {
5017+
// objectstack#36015 — a plain click on a link, a referenced
5018+
// record's chip or an image the cell draws selects the cell and
5019+
// opens nothing. A modifier click opens it as it always did.
5020+
if (isEditing || followingOpenerRef.current || isTouchPress(e)) return;
5021+
if (cellOpenerAt(e.target, e.currentTarget) === null) return;
5022+
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button !== 0) return;
5023+
e.preventDefault();
5024+
e.stopPropagation();
5025+
selectCell(rowIndex, colIndex);
5026+
} : undefined}
49445027
onMouseDown={selectFirst ? (e) => {
49455028
// The double-click is the edit gesture here, so its second
49465029
// press does not select the word under the pointer.
@@ -5055,6 +5138,9 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
50555138
}}
50565139
/>
50575140
)}
5141+
{isSelectedCell && !isEditing && (
5142+
<CellOpenButton label={t('table.open')} onOpen={openCellOpener} />
5143+
)}
50585144
{cellNotice?.rowIndex === rowIndex && cellNotice.colIndex === colIndex && (
50595145
<CellNotice text={cellNotice.text} onDismiss={() => setCellNotice(null)} />
50605146
)}

0 commit comments

Comments
 (0)